@juzi/wechaty 1.0.160 → 1.0.162
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/package-json.js +2 -2
- package/dist/cjs/src/user-modules/call.d.ts +24 -0
- package/dist/cjs/src/user-modules/call.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/call.js +65 -0
- package/dist/cjs/src/user-modules/call.js.map +1 -1
- package/dist/cjs/src/user-modules/call.spec.js +171 -0
- package/dist/cjs/src/user-modules/call.spec.js.map +1 -1
- package/dist/cjs/src/wechaty-mixins/misc-mixin.d.ts +0 -6
- package/dist/cjs/src/wechaty-mixins/misc-mixin.d.ts.map +1 -1
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.d.ts +4 -4
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.d.ts.map +1 -1
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.js +15 -41
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.js.map +1 -1
- package/dist/esm/src/package-json.js +2 -2
- package/dist/esm/src/user-modules/call.d.ts +24 -0
- package/dist/esm/src/user-modules/call.d.ts.map +1 -1
- package/dist/esm/src/user-modules/call.js +65 -0
- package/dist/esm/src/user-modules/call.js.map +1 -1
- package/dist/esm/src/user-modules/call.spec.js +171 -0
- package/dist/esm/src/user-modules/call.spec.js.map +1 -1
- package/dist/esm/src/wechaty-mixins/misc-mixin.d.ts +0 -6
- package/dist/esm/src/wechaty-mixins/misc-mixin.d.ts.map +1 -1
- package/dist/esm/src/wechaty-mixins/puppet-mixin.d.ts +4 -4
- package/dist/esm/src/wechaty-mixins/puppet-mixin.d.ts.map +1 -1
- package/dist/esm/src/wechaty-mixins/puppet-mixin.js +15 -41
- package/dist/esm/src/wechaty-mixins/puppet-mixin.js.map +1 -1
- package/package.json +1 -1
- package/src/package-json.ts +2 -2
- package/src/user-modules/call.spec.ts +203 -0
- package/src/user-modules/call.ts +71 -0
- package/src/wechaty-mixins/puppet-mixin.ts +19 -36
- package/dist/cjs/src/wechaty-mixins/puppet-mixin-dirty-pool.spec.d.ts +0 -3
- package/dist/cjs/src/wechaty-mixins/puppet-mixin-dirty-pool.spec.d.ts.map +0 -1
- package/dist/cjs/src/wechaty-mixins/puppet-mixin-dirty-pool.spec.js +0 -121
- package/dist/cjs/src/wechaty-mixins/puppet-mixin-dirty-pool.spec.js.map +0 -1
- package/dist/esm/src/wechaty-mixins/puppet-mixin-dirty-pool.spec.d.ts +0 -3
- package/dist/esm/src/wechaty-mixins/puppet-mixin-dirty-pool.spec.d.ts.map +0 -1
- package/dist/esm/src/wechaty-mixins/puppet-mixin-dirty-pool.spec.js +0 -96
- package/dist/esm/src/wechaty-mixins/puppet-mixin-dirty-pool.spec.js.map +0 -1
- package/src/wechaty-mixins/puppet-mixin-dirty-pool.spec.ts +0 -144
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
|
|
2
|
-
|
|
3
|
-
import { test } from 'tstest'
|
|
4
|
-
import * as PUPPET from '@juzi/wechaty-puppet'
|
|
5
|
-
import { PuppetMock } from '@juzi/wechaty-puppet-mock'
|
|
6
|
-
|
|
7
|
-
import { WechatyBuilder } from '../wechaty-builder.js'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Regression: the `dirty` event handler for pooled user-modules
|
|
11
|
-
* (Contact / Room / WxxdProduct / WxxdOrder) used to call
|
|
12
|
-
* `this.Xxx.find({ id }).ready(true)`. `find({ id })` on a pool miss
|
|
13
|
-
* constructs a fresh instance and calls `ready()` — a puppet-side gRPC
|
|
14
|
-
* round-trip — turning a passive "invalidate if cached" signal into an
|
|
15
|
-
* active fetch for ids no business code has touched.
|
|
16
|
-
*
|
|
17
|
-
* The fix looks the id up in the pool directly and only calls
|
|
18
|
-
* `.ready(true)` when the instance is already pooled.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
async function delay (ms: number): Promise<void> {
|
|
22
|
-
await new Promise<void>(resolve => setTimeout(resolve, ms))
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
test('dirty handler does not fetch payload for un-pooled ids, but still refreshes pooled ones', async t => {
|
|
26
|
-
const puppet = new PuppetMock() as any
|
|
27
|
-
const wechaty = WechatyBuilder.build({ puppet })
|
|
28
|
-
|
|
29
|
-
const botContact = puppet.mocker.createContact({ name: 'test-bot' })
|
|
30
|
-
|
|
31
|
-
await wechaty.start()
|
|
32
|
-
await puppet.mocker.login(botContact)
|
|
33
|
-
|
|
34
|
-
// --- Case 1: un-pooled Contact id must not trigger contactRawPayload ---
|
|
35
|
-
|
|
36
|
-
let contactRawPayloadCalls = 0
|
|
37
|
-
const originalContactRawPayload = puppet.contactRawPayload.bind(puppet)
|
|
38
|
-
puppet.contactRawPayload = async (id: string) => {
|
|
39
|
-
contactRawPayloadCalls++
|
|
40
|
-
return originalContactRawPayload(id)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
puppet.emit('dirty', {
|
|
44
|
-
payloadType: PUPPET.types.Payload.Contact,
|
|
45
|
-
payloadId: 'never-loaded-contact-id',
|
|
46
|
-
})
|
|
47
|
-
await delay(50)
|
|
48
|
-
|
|
49
|
-
t.equal(
|
|
50
|
-
contactRawPayloadCalls,
|
|
51
|
-
0,
|
|
52
|
-
`dirty(Contact) for un-pooled id must not trigger contactRawPayload; got ${contactRawPayloadCalls} call(s)`,
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
// --- Case 2: un-pooled Room id must not trigger roomRawPayload ---
|
|
56
|
-
|
|
57
|
-
let roomRawPayloadCalls = 0
|
|
58
|
-
const originalRoomRawPayload = puppet.roomRawPayload.bind(puppet)
|
|
59
|
-
puppet.roomRawPayload = async (id: string) => {
|
|
60
|
-
roomRawPayloadCalls++
|
|
61
|
-
return originalRoomRawPayload(id)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
puppet.emit('dirty', {
|
|
65
|
-
payloadType: PUPPET.types.Payload.Room,
|
|
66
|
-
payloadId: 'never-loaded-room-id',
|
|
67
|
-
})
|
|
68
|
-
await delay(50)
|
|
69
|
-
|
|
70
|
-
t.equal(
|
|
71
|
-
roomRawPayloadCalls,
|
|
72
|
-
0,
|
|
73
|
-
`dirty(Room) for un-pooled id must not trigger roomRawPayload; got ${roomRawPayloadCalls} call(s)`,
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
// --- Case 3: Message dirty must not trigger messageRawPayload (Message has no user-layer pool) ---
|
|
77
|
-
|
|
78
|
-
let messageRawPayloadCalls = 0
|
|
79
|
-
const originalMessageRawPayload = puppet.messageRawPayload.bind(puppet)
|
|
80
|
-
puppet.messageRawPayload = async (id: string) => {
|
|
81
|
-
messageRawPayloadCalls++
|
|
82
|
-
return originalMessageRawPayload(id)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
puppet.emit('dirty', {
|
|
86
|
-
payloadType: PUPPET.types.Payload.Message,
|
|
87
|
-
payloadId: 'some-message-id',
|
|
88
|
-
})
|
|
89
|
-
await delay(50)
|
|
90
|
-
|
|
91
|
-
t.equal(
|
|
92
|
-
messageRawPayloadCalls,
|
|
93
|
-
0,
|
|
94
|
-
`dirty(Message) must not trigger messageRawPayload at the user layer; got ${messageRawPayloadCalls} call(s)`,
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
// --- Case 4: un-pooled Contact still emits the user-facing dirty event ---
|
|
98
|
-
|
|
99
|
-
let wechatyDirtyEmits = 0
|
|
100
|
-
wechaty.on('dirty', () => {
|
|
101
|
-
wechatyDirtyEmits++
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
puppet.emit('dirty', {
|
|
105
|
-
payloadType: PUPPET.types.Payload.Contact,
|
|
106
|
-
payloadId: 'yet-another-un-pooled-id',
|
|
107
|
-
})
|
|
108
|
-
await delay(50)
|
|
109
|
-
|
|
110
|
-
t.equal(
|
|
111
|
-
wechatyDirtyEmits,
|
|
112
|
-
1,
|
|
113
|
-
`wechaty.emit('dirty', ...) must fire once even when the id is not pooled; got ${wechatyDirtyEmits}`,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
// --- Case 5: pooled Contact MUST re-fetch on dirty ---
|
|
117
|
-
|
|
118
|
-
const pooledContact = puppet.mocker.createContact({ name: 'pooled-contact' })
|
|
119
|
-
|
|
120
|
-
// Force the contact into the wechatified pool via find(). Payload gets
|
|
121
|
-
// loaded once as part of find()'s ready() call — subsequent counts we
|
|
122
|
-
// measure from AFTER this seed.
|
|
123
|
-
await wechaty.Contact.find({ id: pooledContact.id })
|
|
124
|
-
|
|
125
|
-
let contactPayloadCalls = 0
|
|
126
|
-
const originalContactPayload = puppet.contactPayload.bind(puppet)
|
|
127
|
-
puppet.contactPayload = async (id: string) => {
|
|
128
|
-
contactPayloadCalls++
|
|
129
|
-
return originalContactPayload(id)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
puppet.emit('dirty', {
|
|
133
|
-
payloadType: PUPPET.types.Payload.Contact,
|
|
134
|
-
payloadId: pooledContact.id,
|
|
135
|
-
})
|
|
136
|
-
await delay(50)
|
|
137
|
-
|
|
138
|
-
t.ok(
|
|
139
|
-
contactPayloadCalls >= 1,
|
|
140
|
-
`dirty(Contact) for pooled id must trigger contactPayload via ready(true); got ${contactPayloadCalls} call(s)`,
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
await wechaty.stop()
|
|
144
|
-
})
|