Skip to content

Commit

Permalink
0.25.1
Browse files Browse the repository at this point in the history
* rename event `watchdog` to `heartbeat` (wechaty#88)

* 0.23.1

* clear log message

* 0.23.2

* reset for start

* 0.23.3

* add name() method for getting the provider npm name (wechaty#89)

* 0.23.4

* refactor PuppetTest to seprate module directory (wechaty#89)

* 0.23.5

* Upgrade state-switch to support Observable

* 0.23.6

* Upgrade StateSwitch to support RxJS fromEvent

* fix options

* 0.23.7

* --skipLibCheck

* 0.23.8

* public state for rxjs helper function visit

* 0.23.9

* 0.24.0 (wechaty#92)

* increase the cache size for RoomMemberPayload from 10K to 30K

* 0.23.10

* 0.25.1

Co-authored-by: Huan LI <zixia@zixia.net>
  • Loading branch information
su-chang and huan authored Apr 23, 2020
1 parent c3319bf commit 80d7083
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 258 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty-puppet",
"version": "0.21.12",
"version": "0.25.1",
"description": "Abstract Puppet for Wechaty",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -64,7 +64,7 @@
"rx-queue": "^0.8.1",
"rxjs": "^6.2.1",
"semver": "^6.0.0",
"state-switch": "^0.6.2",
"state-switch": "^0.9.7",
"watchdog": "^0.8.12"
},
"git": {
Expand Down
1 change: 1 addition & 0 deletions scripts/npm-pack-testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ npm install *-*.*.*.tgz \
./node_modules/.bin/tsc \
--esModuleInterop \
--lib esnext \
--skipLibCheck \
--noEmitOnError \
--noImplicitAny \
--target es6 \
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export {
EventErrorPayload,
EventReadyPayload,
EventResetPayload,
EventWatchdogPayload,
EventHeartbeatPayload,
} from './schemas/event'
export {
FriendshipPayload,
Expand Down
195 changes: 23 additions & 172 deletions src/puppet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,196 +6,29 @@ import test from 'blue-tape'
import sinon from 'sinon'

import {
FileBox,
MemoryCard,
} from './config'

import {
ContactGender,
ContactPayload,
ContactPayloadFilterFunction,
ContactQueryFilter,
ContactType,
} from './schemas/contact'
import {
FriendshipPayload,
} from './schemas/friendship'
import {
ImageType,
} from './schemas/image'
import {
MessagePayload,
MessagePayloadFilterFunction,
MessageQueryFilter,
MessageType,
} from './schemas/message'
import {
RoomMemberPayload,
RoomPayload,
RoomPayloadFilterFunction,
RoomQueryFilter,
} from './schemas/room'
import {
RoomInvitationPayload,
} from './schemas/room-invitation'
import {
UrlLinkPayload,
} from './schemas/url-link'
import {
MiniProgramPayload,
} from './schemas/mini-program'

/**
* The Fixture
*/
import {
Puppet,
} from './puppet'

class PuppetTest extends Puppet {

public async start () : Promise<void> { return {} as any }
public async stop () : Promise<void> { return {} as any }

public async ding (data?: string) : Promise<void> { return data as void }
public async logout () : Promise<void> { return {} as any }

/**
*
* ContactSelf
*
*
*/
public async contactSelfQRCode () : Promise<string> { return '' }
public async contactSelfName (name: string) : Promise<void> { return void name }
public async contactSelfSignature (signature: string) : Promise<void> { return void signature }

/**
*
* Tag
*
*/
public async tagContactAdd (tagId: string, contactId: string) : Promise<void> { return void { contactId, tagId } }
public async tagContactRemove (tagId: string, contactId: string) : Promise<void> { return void { contactId, tagId } }
public async tagContactDelete (tagId: string) : Promise<void> { return void { tagId } }
public async tagContactList (contactId?: string) : Promise<string[]> { return [contactId || ''] }

/**
*
* Contact
*
*/
public async contactAlias (contactId: string) : Promise<string>
public async contactAlias (contactId: string, alias: string | null) : Promise<void>
public async contactAlias (contactId: string, alias?: string | null) : Promise<string | void> { return { alias, contactId } as any }

public async contactAvatar (contactId: string) : Promise<FileBox>
public async contactAvatar (contactId: string, file: FileBox) : Promise<void>
public async contactAvatar (contactId: string, file?: FileBox) : Promise<void | FileBox> { return { contactId, file } as any }

public async contactList () : Promise<string[]> { return {} as any }

public async contactRawPayload (id: string) : Promise<any> { return { id } as any }
public async contactRawPayloadParser (rawPayload: any) : Promise<ContactPayload> { return { rawPayload } as any }

/**
*
* Friendship
*
*/
public async friendshipRawPayload (id: string) : Promise<any> { return { id } as any }
public async friendshipRawPayloadParser (rawPayload: any) : Promise<FriendshipPayload> { return rawPayload }

public async friendshipSearchPhone (phone: string) : Promise<null | string> { return phone }
public async friendshipSearchWeixin (weixin: string) : Promise<null | string> { return weixin }
public async friendshipAdd (contactId: string, hello?: string) : Promise<void> { return { contactId, hello } as any }
public async friendshipAccept (friendshipId: string) : Promise<void> { return { friendshipId } as any }

/**
*
* Message
*
*/
public async messageContact (messageId: string) : Promise<string> { return { messageId } as any }
public async messageFile (messageId: string) : Promise<FileBox> { return { messageId } as any }
public async messageImage (messageId: string, imageType: ImageType) : Promise<FileBox> { return { imageType, messageId } as any }
public async messageMiniProgram (messageId: string) : Promise<MiniProgramPayload> { return { messageId } as any }
public async messageUrl (messageId: string) : Promise<UrlLinkPayload> { return { messageId } as any }

public async messageForward (conversationId: string, messageId: string) : Promise<void | string> { return { conversationId, messageId } as any }
public async messageSendContact (conversationId: string, contactId: string) : Promise<void | string> { return { contactId, conversationId } as any }
public async messageSendFile (conversationId: string, file: FileBox) : Promise<void | string> { return { conversationId, file } as any }
public async messageSendText (conversationId: string, text: string) : Promise<void | string> { return { conversationId, text } as any }
public async messageSendUrl (conversationId: string, urlLinkPayload: UrlLinkPayload) : Promise<void | string> { return { conversationId, urlLinkPayload } as any }
public async messageSendMiniProgram (conversationId: string, miniProgramPayload: MiniProgramPayload) : Promise<void | string> { return { conversationId, miniProgramPayload } as any }

public async messageRawPayload (id: string) : Promise<any> { return { id } as any }
public async messageRawPayloadParser (rawPayload: any) : Promise<MessagePayload> { return { rawPayload } as any }

public async messageRecall (messageId: string) : Promise<boolean> { return { messageId } as any }

public messageQueryFilterFactory (
query: MessageQueryFilter,
): MessagePayloadFilterFunction {
return super.messageQueryFilterFactory(query)
}

/**
*
* Room Invitation
*
*/
public async roomInvitationAccept (_: string): Promise<void> { }

public async roomInvitationRawPayload (roomInvitationId: string) : Promise<any> { return { roomInvitationId } as any }
public async roomInvitationRawPayloadParser (rawPayload: any) : Promise<RoomInvitationPayload> { return rawPayload }

/**
*
* Room
*
*/
public async roomAnnounce (roomId: string) : Promise<string>
public async roomAnnounce (roomId: string, text: string) : Promise<void>
public async roomAnnounce (roomId: string, text?: string) : Promise<void | string> { return { roomId, text } as any }

public async roomAdd (roomId: string, contactId: string) : Promise<void> { return { contactId, roomId } as any }
public async roomAvatar (roomId: string) : Promise<FileBox> { return { roomId } as any }
public async roomCreate (contactIdList: string[], topic?: string) : Promise<string> { return { contactIdList, topic } as any }
public async roomDel (roomId: string, contactId: string) : Promise<void> { return { contactId, roomId } as any }
public async roomQuit (roomId: string) : Promise<void> { return { roomId } as any }
public async roomQRCode (roomId: string) : Promise<string> { return { roomId } as any }

public async roomTopic (roomId: string) : Promise<string>
public async roomTopic (roomId: string, topic: string) : Promise<void>
public async roomTopic (roomId: string, topic?: string) : Promise<string | void> { return { roomId, topic } as any }

public async roomList () : Promise<string[]> { return {} as any }
public async roomMemberList (roomId: string) : Promise<string[]> { return { roomId } as any }

public async roomRawPayload (id: string) : Promise<any> { return { id } as any }
public async roomRawPayloadParser (rawPayload: any) : Promise<RoomPayload> { return { rawPayload } as any }

public async roomMemberRawPayload (roomId: string, contactId: string) : Promise<any> { return { contactId, roomId } as any }
public async roomMemberRawPayloadParser (rawPayload: any) : Promise<RoomMemberPayload> { return rawPayload }

/**
* expose to public for internal methods:
*/
public roomQueryFilterFactory (
query: RoomQueryFilter,
): RoomPayloadFilterFunction {
return super.roomQueryFilterFactory(query)
}

public contactQueryFilterFactory (
query: ContactQueryFilter,
): ContactPayloadFilterFunction {
return super.contactQueryFilterFactory(query)
}

public reset (reason: string): void {
return super.reset(reason)
}

}
PuppetTest,
} from '../tests/fixtures/puppet-test/puppet-test'

test('contactQueryFilterFunction()', async t => {

Expand Down Expand Up @@ -604,3 +437,21 @@ test('messageQueryFilterFactory() two condition', async t => {
t.equal(resultPayload[0].text, EXPECTED_TEXT_DATA, 'should get text data')
t.equal(resultPayload[0].type, EXPECTED_TYPE_URL, 'should get type url')
})

test('name()', async t => {
const puppet = new PuppetTest()

const name = puppet.name()
const EXPECTED_NAME = 'puppet-test'

t.equal(name, EXPECTED_NAME, 'should get the child class package name')
})

test('version()', async t => {
const puppet = new PuppetTest()

const version = puppet.version()
const EXPECTED_VERSION = '1.0.0'

t.equal(version, EXPECTED_VERSION, 'should get the child class package version')
})
Loading

0 comments on commit 80d7083

Please sign in to comment.