Skip to content

Commit 56ce088

Browse files
committed
add mixin protected properties tests (#155)
1 parent cfb24ce commit 56ce088

26 files changed

+356
-114
lines changed

src/agents/cache-agent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import type {
2323
import type {
2424
RoomInvitationPayload,
2525
} from '../schemas/room-invitation.js'
26-
import type { PuppetOptions } from '../schemas/puppet.js'
26+
import type {
27+
PuppetOptions,
28+
} from '../schemas/puppet.js'
2729

2830
type PayloadCacheOptions = Required<PuppetOptions>['cache']
2931

@@ -33,8 +35,8 @@ class CacheAgent {
3335
readonly friendship : QuickLru<string, FriendshipPayload>
3436
readonly message : QuickLru<string, MessagePayload>
3537
readonly room : QuickLru<string, RoomPayload>
36-
readonly roomMember : QuickLru<string, RoomMemberPayload>
3738
readonly roomInvitation : QuickLru<string, RoomInvitationPayload>
39+
readonly roomMember : QuickLru<string, RoomMemberPayload>
3840

3941
constructor (
4042
protected options: PayloadCacheOptions = {},

src/mixins/cache-mixin.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm
2+
3+
import {
4+
test,
5+
} from 'tstest'
6+
7+
import type {
8+
CacheMixin,
9+
ProtectedPropertyCacheMixin,
10+
} from './cache-mixin.js'
11+
12+
test('ProtectedPropertyCacheMixin', async t => {
13+
type NotExistInMixin = Exclude<ProtectedPropertyCacheMixin, keyof InstanceType<CacheMixin>>
14+
type NotExistTest = NotExistInMixin extends never ? true : false
15+
16+
const noOneLeft: NotExistTest = true
17+
t.ok(noOneLeft, 'should match Mixin properties for every protected property')
18+
})

src/mixins/cache-mixin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ const cacheMixin = <MixinBase extends typeof PuppetSkelton>(mixinBase: MixinBase
4141

4242
type CacheMixin = ReturnType<typeof cacheMixin>
4343

44+
type ProtectedPropertyCacheMixin = never
45+
| 'cache'
46+
4447
export type {
4548
CacheMixin,
49+
ProtectedPropertyCacheMixin,
4650
}
4751
export { cacheMixin }

src/mixins/contact-mixin.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm
2+
3+
import {
4+
test,
5+
} from 'tstest'
6+
7+
import type {
8+
ContactMixin,
9+
ProtectedPropertyContactMixin,
10+
} from './contact-mixin.js'
11+
12+
test('ProtectedPropertyContactMixin', async t => {
13+
type NotExistInMixin = Exclude<ProtectedPropertyContactMixin, keyof InstanceType<ContactMixin>>
14+
type NotExistTest = NotExistInMixin extends never ? true : false
15+
16+
const noOneLeft: NotExistTest = true
17+
t.ok(noOneLeft, 'should match Mixin properties for every protected property')
18+
})

src/mixins/contact-mixin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,16 @@ const contactMixin = <MixinBase extends CacheMixin & typeof PuppetSkelton>(mixin
294294
return ContactMixin
295295
}
296296

297+
type ProtectedPropertyContactMixin = never
298+
| 'contactRawPayload'
299+
| 'contactRawPayloadParser'
300+
| 'contactQueryFilterFactory'
301+
| 'contactPayloadCache'
302+
297303
type ContactMixin = ReturnType<typeof contactMixin>
298304

299305
export type {
300306
ContactMixin,
307+
ProtectedPropertyContactMixin,
301308
}
302309
export { contactMixin }

src/mixins/friendship-mixin.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm
2+
3+
import {
4+
test,
5+
} from 'tstest'
6+
7+
import type {
8+
FriendshipMixin,
9+
ProtectedPropertyFriendshipMixin,
10+
} from './friendship-mixin.js'
11+
12+
test('ProtectedPropertyFriendshipMixin', async t => {
13+
type NotExistInMixin = Exclude<ProtectedPropertyFriendshipMixin, keyof InstanceType<FriendshipMixin>>
14+
type NotExistTest = NotExistInMixin extends never ? true : false
15+
16+
const noOneLeft: NotExistTest = true
17+
t.ok(noOneLeft, 'should match Mixin properties for every protected property')
18+
})

src/mixins/friendship-mixin.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,15 @@ const friendshipMixin = <MixinBase extends typeof PuppetSkelton & CacheMixin>(mi
130130
return FriendshipMixin
131131
}
132132

133+
type FriendshipMixin = ReturnType<typeof friendshipMixin>
134+
135+
type ProtectedPropertyFriendshipMixin = never
136+
| 'friendshipRawPayload'
137+
| 'friendshipRawPayloadParser'
138+
| 'friendshipPayloadCache'
139+
140+
export type {
141+
FriendshipMixin,
142+
ProtectedPropertyFriendshipMixin,
143+
}
133144
export { friendshipMixin }

src/mixins/login-mixin.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm
2+
3+
import {
4+
test,
5+
} from 'tstest'
6+
7+
import type {
8+
LoginMixin,
9+
ProtectedPropertyLoginMixin,
10+
} from './login-mixin.js'
11+
12+
test('ProtectedPropertyLoginMixin', async t => {
13+
type NotExistInMixin = Exclude<ProtectedPropertyLoginMixin, keyof InstanceType<LoginMixin>>
14+
type NotExistTest = NotExistInMixin extends never ? true : false
15+
16+
const noOneLeft: NotExistTest = true
17+
t.ok(noOneLeft, 'should match Mixin properties for every protected property')
18+
})

src/mixins/login-mixin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ const loginMixin = <MixinBase extends typeof PuppetSkelton>(mixinBase: MixinBase
126126

127127
type LoginMixin = ReturnType<typeof loginMixin>
128128

129+
type ProtectedPropertyLoginMixin = never
130+
| 'login'
131+
129132
export type {
130133
LoginMixin,
134+
ProtectedPropertyLoginMixin,
131135
}
132136
export { loginMixin }

src/mixins/memory-mixin.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm
2+
3+
import {
4+
test,
5+
} from 'tstest'
6+
7+
import type {
8+
MemoryMixin,
9+
ProtectedPropertyMemoryMixin,
10+
} from './memory-mixin.js'
11+
12+
test('ProtectedPropertyMemoryMixin', async t => {
13+
type NotExistInMixin = Exclude<ProtectedPropertyMemoryMixin, keyof InstanceType<MemoryMixin>>
14+
type NotExistTest = NotExistInMixin extends never ? true : false
15+
16+
const noOneLeft: NotExistTest = true
17+
t.ok(noOneLeft, 'should match Mixin properties for every protected property')
18+
})

src/mixins/memory-mixin.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ const memoryMixin = <MixinBase extends typeof PuppetSkelton>(mixinBase: MixinBas
5151
return MemoryMixin
5252
}
5353

54+
type MemoryMixin = ReturnType<typeof memoryMixin>
55+
56+
type ProtectedPropertyMemoryMixin = never
57+
| 'memory'
58+
59+
export type {
60+
MemoryMixin,
61+
ProtectedPropertyMemoryMixin,
62+
}
5463
export { memoryMixin }

src/mixins/message-mixin.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm
2+
3+
import {
4+
test,
5+
} from 'tstest'
6+
7+
import type {
8+
MessageMixin,
9+
ProtectedPropertyMessageMixin,
10+
} from './message-mixin.js'
11+
12+
test('ProtectedPropertyMessageMixin', async t => {
13+
type NotExistInMixin = Exclude<ProtectedPropertyMessageMixin, keyof InstanceType<MessageMixin>>
14+
type NotExistTest = NotExistInMixin extends never ? true : false
15+
16+
const noOneLeft: NotExistTest = true
17+
t.ok(noOneLeft, 'should match Mixin properties for every protected property')
18+
})

src/mixins/message-mixin.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,16 @@ const messageMixin = <MinxinBase extends typeof PuppetSkelton & CacheMixin>(base
208208
return MessageMixin
209209
}
210210

211+
type MessageMixin = ReturnType<typeof messageMixin>
212+
213+
type ProtectedPropertyMessageMixin = never
214+
| 'messagePayloadCache'
215+
| 'messageQueryFilterFactory'
216+
| 'messageRawPayload'
217+
| 'messageRawPayloadParser'
218+
219+
export type {
220+
MessageMixin,
221+
ProtectedPropertyMessageMixin,
222+
}
211223
export { messageMixin }

src/mixins/mod.ts

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,71 @@
1-
import { cacheMixin } from '../mixins/cache-mixin.js'
2-
import { contactMixin } from '../mixins/contact-mixin.js'
3-
import { friendshipMixin } from '../mixins/friendship-mixin.js'
4-
import { loginMixin } from '../mixins/login-mixin.js'
5-
import { memoryMixin } from '../mixins/memory-mixin.js'
6-
import { messageMixin } from '../mixins/message-mixin.js'
7-
import { miscMixin } from './misc-mixin.js'
8-
import { roomInvitationMixin } from '../mixins/room-invitation-mixin.js'
9-
import { roomMemberMixin } from '../mixins/room-member-mixin.js'
10-
import { roomMixin } from '../mixins/room-mixin.js'
11-
import { stateMixin } from '../mixins/state-mixin.js'
12-
import { tagMixin } from '../mixins/tag-mixin.js'
13-
import { watchdogMixin } from '../mixins/watchdog-mixin.js'
1+
import {
2+
cacheMixin,
3+
ProtectedPropertyCacheMixin,
4+
} from '../mixins/cache-mixin.js'
5+
import {
6+
contactMixin,
7+
ProtectedPropertyContactMixin,
8+
} from '../mixins/contact-mixin.js'
9+
import {
10+
friendshipMixin,
11+
ProtectedPropertyFriendshipMixin,
12+
} from '../mixins/friendship-mixin.js'
13+
import {
14+
loginMixin,
15+
ProtectedPropertyLoginMixin,
16+
} from '../mixins/login-mixin.js'
17+
import {
18+
memoryMixin,
19+
ProtectedPropertyMemoryMixin,
20+
} from '../mixins/memory-mixin.js'
21+
import {
22+
messageMixin,
23+
ProtectedPropertyMessageMixin,
24+
} from '../mixins/message-mixin.js'
25+
import { miscMixin } from './misc-mixin.js'
26+
import {
27+
roomInvitationMixin,
28+
ProtectedPropertyRoomInvitationMixin,
29+
} from '../mixins/room-invitation-mixin.js'
30+
import {
31+
roomMemberMixin,
32+
ProtectedPropertyRoomMemberMixin,
33+
} from '../mixins/room-member-mixin.js'
34+
import {
35+
roomMixin,
36+
ProtectedPropertyRoomMixin,
37+
} from '../mixins/room-mixin.js'
38+
import {
39+
stateMixin,
40+
ProtectedPropertyStateMixin,
41+
} from '../mixins/state-mixin.js'
42+
import { tagMixin } from '../mixins/tag-mixin.js'
43+
44+
/**
45+
* Issue #155 - Mixin: Property 'messageRawPayload' of exported class expression
46+
* may not be private or protected.ts(4094)
47+
* @see https://github.com/wechaty/puppet/issues/155
48+
*
49+
* We can not use `private` or `protected` to declare Mixins
50+
* So we define a `ProtectedMethods` list to mark the protected methods
51+
* And Omit them from the Puppet typing defination
52+
* to build a new PuppetInterface
53+
*/
54+
type PuppetProtectedProperty = never
55+
| ProtectedPropertyCacheMixin
56+
| ProtectedPropertyContactMixin
57+
| ProtectedPropertyFriendshipMixin
58+
| ProtectedPropertyLoginMixin
59+
| ProtectedPropertyMemoryMixin
60+
| ProtectedPropertyMessageMixin
61+
| ProtectedPropertyRoomInvitationMixin
62+
| ProtectedPropertyRoomMemberMixin
63+
| ProtectedPropertyRoomMixin
64+
| ProtectedPropertyStateMixin
1465

66+
export type {
67+
PuppetProtectedProperty,
68+
}
1569
export {
1670
cacheMixin,
1771
contactMixin,
@@ -25,5 +79,4 @@ export {
2579
roomMixin,
2680
stateMixin,
2781
tagMixin,
28-
watchdogMixin,
2982
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm
2+
3+
import {
4+
test,
5+
} from 'tstest'
6+
7+
import type {
8+
RoomInvitationMixin,
9+
ProtectedPropertyRoomInvitationMixin,
10+
} from './room-invitation-mixin.js'
11+
12+
test('ProtectedPropertyRoomInvitationMixin', async t => {
13+
type NotExistInMixin = Exclude<ProtectedPropertyRoomInvitationMixin, keyof InstanceType<RoomInvitationMixin>>
14+
type NotExistTest = NotExistInMixin extends never ? true : false
15+
16+
const noOneLeft: NotExistTest = true
17+
t.ok(noOneLeft, 'should match Mixin properties for every protected property')
18+
})

src/mixins/room-invitation-mixin.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,15 @@ const roomInvitationMixin = <MixinBase extends typeof PuppetSkelton & CacheMixin
100100
return RoomInvitationMixin
101101
}
102102

103+
type RoomInvitationMixin = ReturnType<typeof roomInvitationMixin>
104+
105+
type ProtectedPropertyRoomInvitationMixin = never
106+
| 'roomInvitationPayloadCache'
107+
| 'roomInvitationRawPayload'
108+
| 'roomInvitationRawPayloadParser'
109+
110+
export type {
111+
RoomInvitationMixin,
112+
ProtectedPropertyRoomInvitationMixin,
113+
}
103114
export { roomInvitationMixin }

src/mixins/room-member-mixin.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm
2+
3+
import {
4+
test,
5+
} from 'tstest'
6+
7+
import type {
8+
RoomMemberMixin,
9+
ProtectedPropertyRoomMemberMixin,
10+
} from './room-member-mixin.js'
11+
12+
test('ProtectedPropertyRoomMemberMixin', async t => {
13+
type NotExistInMixin = Exclude<ProtectedPropertyRoomMemberMixin, keyof InstanceType<RoomMemberMixin>>
14+
type NotExistTest = NotExistInMixin extends never ? true : false
15+
16+
const noOneLeft: NotExistTest = true
17+
t.ok(noOneLeft, 'should match Mixin properties for every protected property')
18+
})

src/mixins/room-member-mixin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,12 @@ const roomMemberMixin = <MixinBase extends typeof PuppetSkelton & ContactMixin>(
169169

170170
type RoomMemberMixin = ReturnType<typeof roomMemberMixin>
171171

172+
type ProtectedPropertyRoomMemberMixin = never
173+
| 'roomMemberRawPayload'
174+
| 'roomMemberRawPayloadParser'
175+
172176
export type {
177+
ProtectedPropertyRoomMemberMixin,
173178
RoomMemberMixin,
174179
}
175180
export { roomMemberMixin }

src/mixins/room-mixin.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm
2+
3+
import {
4+
test,
5+
} from 'tstest'
6+
7+
import type {
8+
RoomMixin,
9+
ProtectedPropertyRoomMixin,
10+
} from './room-mixin.js'
11+
12+
test('ProtectedPropertyRoomMixin', async t => {
13+
type NotExistInMixin = Exclude<ProtectedPropertyRoomMixin, keyof InstanceType<RoomMixin>>
14+
type NotExistTest = NotExistInMixin extends never ? true : false
15+
16+
const noOneLeft: NotExistTest = true
17+
t.ok(noOneLeft, 'should match Mixin properties for every protected property')
18+
})

0 commit comments

Comments
 (0)