diff --git a/package.json b/package.json index ea297546..1284f620 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wechaty-puppet", - "version": "1.21.2", + "version": "1.21.3", "description": "Abstract Puppet for Wechaty", "type": "module", "exports": { diff --git a/src/mixins/login-mixin.ts b/src/mixins/login-mixin.ts index 9648e912..aeae1d48 100644 --- a/src/mixins/login-mixin.ts +++ b/src/mixins/login-mixin.ts @@ -89,6 +89,10 @@ const loginMixin = (mixinBase: MixinBas contactId: this.currentUserId, data: 'puppet stop()', }) + await new Promise(resolve => setImmediate(() => { + this.__currentUserId = undefined + resolve() + })) } await super.stop() diff --git a/src/schemas/message.ts b/src/schemas/message.ts index f911b9c0..9357a5a0 100644 --- a/src/schemas/message.ts +++ b/src/schemas/message.ts @@ -21,6 +21,7 @@ export enum MessageType { Video = 15, // Video(4), Video(43) Post = 16, // Moment, Channel, Tweet, etc Channel = 17, // Channel + System = 18, // System Message } /** diff --git a/src/schemas/sayable.ts b/src/schemas/sayable.ts index 5ad3e220..53503f29 100644 --- a/src/schemas/sayable.ts +++ b/src/schemas/sayable.ts @@ -105,6 +105,7 @@ type SayablePayloadUnsupportedType = | 'RedEnvelope' | 'Transfer' | 'Unknown' + | 'System' export { sayablePayloads, diff --git a/tests/login.spec.ts b/tests/login.spec.ts new file mode 100644 index 00000000..6ba2d867 --- /dev/null +++ b/tests/login.spec.ts @@ -0,0 +1,25 @@ +#!/usr/bin/env -S node --no-warnings --loader ts-node/esm +// @ts-check + +import { test } from 'tstest' + +import { PuppetTest } from './fixtures/puppet-test/puppet-test.js' + +test('login testing', async t => { + + const puppet = new PuppetTest() + + const USER_ID = 'test-user' + let userFromEvent = null + const future = new Promise(resolve => puppet.on('login', user => { + userFromEvent = user.contactId + resolve() + })) + await puppet.start() + puppet.login(USER_ID) + await future + + t.same(userFromEvent, USER_ID, `should get login event with ${USER_ID}`) + await puppet.stop() + t.notOk(puppet.isLoggedIn, 'puppet should not be logged in after stop') +})