提交 b440563f 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

fix all room event unit tests

上级 e69f1eb6
......@@ -324,7 +324,7 @@ export class PadchatRpc extends EventEmitter {
private async rpcCall(
apiName : string,
...params : (string | WXSearchContactTypeStatus)[]
...params : string[]
): Promise<any> {
log.silly('PadchatRpc', 'rpcCall(%s, %s)', apiName, JSON.stringify(params).substr(0, 500))
return await this.jsonRpc.request(apiName, params)
......@@ -851,7 +851,13 @@ export class PadchatRpc extends EventEmitter {
}
public async WXAddUser(strangerV1: string, strangerV2: string, type: WXSearchContactTypeStatus, verify: string): Promise<any> {
const result = await this.rpcCall('WXAddUser', strangerV1, strangerV2, type, verify)
const result = await this.rpcCall(
'WXAddUser',
strangerV1,
strangerV2,
String(type),
verify,
)
log.silly('PadchatRpc', 'WXAddUser result: %s', JSON.stringify(result))
return result
}
......
export function isRoomId(id?: string): boolean {
if (!id) {
throw new Error('no id')
// throw new Error('no id')
return false
}
return /@chatroom$/.test(id)
}
export function isContactId(id?: string): boolean {
if (!id) {
throw new Error('no id')
return false
// throw new Error('no id')
}
return !isRoomId(id)
}
export function isContactOfficialId(id?: string): boolean {
if (!id) {
throw new Error('no id')
return false
// throw new Error('no id')
}
return /^gh_/i.test(id)
}
export function isStrangerV1(strangerId?: string): boolean {
if (!strangerId) {
throw new Error('no id')
return false
// throw new Error('no id')
}
return /^v1_/i.test(strangerId)
}
export function isStrangerV2(strangerId?: string): boolean {
if (!strangerId) {
throw new Error('no id')
return false
// throw new Error('no id')
}
return /^v2_/i.test(strangerId)
}
......
......@@ -141,8 +141,8 @@ test('roomJoinEventMessageParser() EN-bot-invite-other', async t => {
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() EN-bot-invite-others', async t => {
t.skip('should be the same as the bot-invite-other')
test('roomJoinEventMessageParser() EN-bot-invite-many', async t => {
t.skip('should be the same as the bot-invite-many')
})
test('roomJoinEventMessageParser() EN-room-create', async t => {
......
......@@ -38,7 +38,7 @@ test('roomJoinEventMessageParser() ZH-other-invite-other', async t => {
}
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
console.log('payload:', event)
// console.log('payload:', event)
t.deepEqual(event, EXPECTED_EVENT, 'should parse room join message payload')
})
......@@ -72,7 +72,7 @@ test('roomJoinEventMessageParser() ZH-other-invite-bot', async t => {
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() ZH-other-invite-bot-with-others', async t => {
test('roomJoinEventMessageParser() ZH-other-invite-bot-with-other', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content : '"李卓桓"邀请你和"Huan LI++"加入了群聊',
continue : 1,
......@@ -97,7 +97,7 @@ test('roomJoinEventMessageParser() ZH-other-invite-bot-with-others', async t =>
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() ZH-bot-invite-other', async t => {
test('roomJoinEventMessageParser() ZH-bot-invite-one', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content : '5354656522@chatroom:\n<sysmsg type="delchatroommember">\n\t<delchatroommember>\n\t\t<plain><![CDATA[你邀请"Huan LI++"加入了群聊 ]]></plain>\n\t\t<text><![CDATA[你邀请"Huan LI++"加入了群聊 ]]></text>\n\t\t<link>\n\t\t\t<scene>invite</scene>\n\t\t\t<text><![CDATA[ 撤销]]></text>\n\t\t\t<memberlist>\n\t\t\t\t<username><![CDATA[wxid_5zj4i5htp9ih22]]></username>\n\t\t\t</memberlist>\n\t\t</link>\n\t</delchatroommember>\n</sysmsg>\n',
continue : 1,
......@@ -122,7 +122,7 @@ test('roomJoinEventMessageParser() ZH-bot-invite-other', async t => {
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() ZH-bot-invite-others', async t => {
test('roomJoinEventMessageParser() ZH-bot-invite-three', async t => {
t.skip('tbw')
})
......
......@@ -122,7 +122,7 @@ test('splitChineseNameList()', async t => {
const EXPECTED_LIST = ['李卓桓', '李佳芮', '桔小秘']
const list = splitChineseNameList(TEXT)
t.equal(list, EXPECTED_LIST, 'should split chinese name list')
t.deepEqual(list, EXPECTED_LIST, 'should split chinese name list')
})
test('splitEnglihshNameList()', async t => {
......@@ -130,5 +130,5 @@ test('splitEnglihshNameList()', async t => {
const EXPECTED_LIST = ['Zhuohuan', '李佳芮', '太阁_传话助手']
const list = splitEnglishNameList(TEXT)
t.equal(list, EXPECTED_LIST, 'should split english name list')
t.deepEqual(list, EXPECTED_LIST, 'should split english name list')
})
......@@ -85,11 +85,27 @@ export function roomJoinEventMessageParser(
* when the message is a Recalled type, bot can undo the invitation
*/
if (rawPayload.sub_type === PadchatMessageType.Recalled) {
/**
* content:
* ```
* 3453262102@chatroom:
* <sysmsg type="delchatroommember">
* ...
* </sysmsg>
* ```
*/
const tryXmlText = content.replace(/^[^\n]+\n/, '')
interface XmlSchema {
plain: string,
sysmsg: {
type: string,
delchatroommember: {
plain: string,
text: string,
},
}
}
const jsonPayload = toJson(content, { object: true }) as XmlSchema
content = jsonPayload.plain
const jsonPayload = toJson(tryXmlText, { object: true }) as XmlSchema
content = jsonPayload.sysmsg.delchatroommember.plain
}
let matchesForBotInviteOtherEn = null as null | string[]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册