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

more unit tests for pure function helpers

上级 5e512659
#!/usr/bin/env ts-node
// tslint:disable:max-line-length
// tslint:disable:no-shadowed-variable
import test from 'blue-tape'
// test('xx)
import { PadchatMessagePayload } from '../padchat-schemas'
export function friendRequestEventMessageParser(rawPayload: PadchatMessagePayload) {
// // const reList = regexConfig.friendConfirm
// // let found = false
// // reList.some(re => !!(found = re.test(content)))
// // if (found) {
// // return true
// // } else {
// // return false
// // }
}
......@@ -6,6 +6,8 @@ import test from 'blue-tape'
import {
PuppetRoomJoinEvent,
YOU,
} from '../../puppet/'
import {
......@@ -16,74 +18,102 @@ import { roomJoinEventMessageParser } from './room-event-message-parser'
test('roomJoinEventMessageParser() EN-other-invite-other', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content: '李卓桓 invited Huan to the group chat',
continue: 1,
description: '',
from_user: '5967138682@chatroom',
msg_id: '11101130790981890',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528754090,
to_user: 'wxid_5zj4i5htp9ih22',
uin: 1928023446,
content : '李卓桓 invited Huan to the group chat',
continue : 1,
description : '',
from_user : '5967138682@chatroom',
msg_id : '11101130790981890',
msg_source : '',
msg_type : 5,
status : 1,
sub_type : 10000,
timestamp : 1528754090,
to_user : 'wxid_5zj4i5htp9ih22',
uin : 1928023446,
}
const EXPECTED_EVENT: PuppetRoomJoinEvent = {
inviteeNameList : ['Huan'],
inviterName : '李卓桓',
roomId : '5967138682@chatroom',
}
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() EN-other-invite-others', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content: '李卓桓 invited 李佳芮, Huan to the group chat',
continue: 1,
description: '',
from_user: '5178377660@chatroom',
msg_id: '3318447775079396781',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528752402,
to_user: 'wxid_5zj4i5htp9ih22',
uin: 1928023446,
content : '李卓桓 invited 李佳芮, Huan to the group chat',
continue : 1,
description : '',
from_user : '5178377660@chatroom',
msg_id : '3318447775079396781',
msg_source : '',
msg_type : 5,
status : 1,
sub_type : 10000,
timestamp : 1528752402,
to_user : 'wxid_5zj4i5htp9ih22',
uin : 1928023446,
}
const EXPECTED_EVENT: PuppetRoomJoinEvent = {
inviteeNameList : ['李佳芮', 'Huan'],
inviterName : '李卓桓',
roomId : '5178377660@chatroom',
}
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() EN-other-invite-bot', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content: '李卓桓 invited you to a group chat with ',
continue: 1,
description: '',
from_user: '3453262102@chatroom',
msg_id: '6633562959389269859',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528653783,
to_user: 'wxid_5zj4i5htp9ih22',
uin: 1928023446,
content : '李卓桓 invited you to a group chat with ',
continue : 1,
description : '',
from_user : '3453262102@chatroom',
msg_id : '6633562959389269859',
msg_source : '',
msg_type : 5,
status : 1,
sub_type : 10000,
timestamp : 1528653783,
to_user : 'wxid_5zj4i5htp9ih22',
uin : 1928023446,
}
const EXPECTED_EVENT: PuppetRoomJoinEvent = {
inviteeNameList : [YOU],
inviterName : '李卓桓',
roomId : '3453262102@chatroom',
}
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() EN-other-invite-bot-with-others', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content: '李卓桓 invited you and Huan to the group chat',
continue: 1,
description: '',
from_user: '5178377660@chatroom',
msg_id: '3875534618008681721',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528751621,
to_user: 'wxid_5zj4i5htp9ih22',
uin: 1928023446,
content : '李卓桓 invited you and Huan to the group chat',
continue : 1,
description : '',
from_user : '5178377660@chatroom',
msg_id : '3875534618008681721',
msg_source : '',
msg_type : 5,
status : 1,
sub_type : 10000,
timestamp : 1528751621,
to_user : 'wxid_5zj4i5htp9ih22',
uin : 1928023446,
}
const EXPECTED_EVENT: PuppetRoomJoinEvent = {
inviteeNameList : [YOU, 'Huan'],
inviterName : '李卓桓',
roomId : '5178377660@chatroom',
}
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() EN-bot-invite-other', async t => {
......@@ -101,6 +131,15 @@ test('roomJoinEventMessageParser() EN-bot-invite-other', async t => {
to_user : 'wxid_5zj4i5htp9ih22',
uin : 1928023446,
}
const EXPECTED_EVENT: PuppetRoomJoinEvent = {
inviteeNameList : ['. 李 卓 桓 .呵呵'],
inviterName : YOU,
roomId : '3453262102@chatroom',
}
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() EN-bot-invite-others', async t => {
......
......@@ -16,47 +16,55 @@ import {
import { roomJoinEventMessageParser } from './room-event-message-parser'
test('roomJoinEventMessageParser() ZH-other-invite-other', async t => {
const PADCHAT_MESSAGE_PAYLOAD_ROOM_JOIN: PadchatMessagePayload = {
content: '"李卓桓"邀请"Huan LI++"加入了群聊',
continue: 1,
description: '',
from_user: '5354656522@chatroom',
msg_id: '1303222499352704462',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528657265,
to_user: 'wxid_a8d806dzznm822',
uin: 1211516682,
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content : '"李卓桓"邀请"Huan LI++"加入了群聊',
continue : 1,
description : '',
from_user : '5354656522@chatroom',
msg_id : '1303222499352704462',
msg_source : '',
msg_type : 5,
status : 1,
sub_type : 10000,
timestamp : 1528657265,
to_user : 'wxid_a8d806dzznm822',
uin : 1211516682,
}
const EXPECTED_MESSAGE_PAYLOAD_ROOM_JOIN: PuppetRoomJoinEvent = {
const EXPECTED_EVENT: PuppetRoomJoinEvent = {
inviteeNameList: ['Huan LI++'],
inviterName: '李卓桓',
roomId: '5354656522@chatroom',
}
const payload = roomJoinEventMessageParser(PADCHAT_MESSAGE_PAYLOAD_ROOM_JOIN)
console.log('payload:', payload)
t.deepEqual(payload, EXPECTED_MESSAGE_PAYLOAD_ROOM_JOIN, 'should parse room join message payload')
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
console.log('payload:', event)
t.deepEqual(event, EXPECTED_EVENT, 'should parse room join message payload')
})
test('roomJoinEventMessageParser() ZH-other-invite-others', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content: '李卓桓 invited 李佳芮, 李卓桓 to the group chat',
continue: 1,
description: '',
from_user: '5178377660@chatroom',
msg_id: '3318447775079396781',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528752402,
to_user: 'wxid_5zj4i5htp9ih22',
uin: 1928023446,
content : '李卓桓 invited 李佳芮, 李卓桓2 to the group chat',
continue : 1,
description : '',
from_user : '5178377660@chatroom',
msg_id : '3318447775079396781',
msg_source : '',
msg_type : 5,
status : 1,
sub_type : 10000,
timestamp : 1528752402,
to_user : 'wxid_5zj4i5htp9ih22',
uin : 1928023446,
}
const EXPECTED_EVENT: PuppetRoomJoinEvent = {
inviteeNameList : ['李佳芮', '李卓桓2'],
inviterName : '李卓桓',
roomId : '5178377660@chatroom',
}
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() ZH-other-invite-bot', async t => {
......@@ -75,15 +83,14 @@ test('roomJoinEventMessageParser() ZH-other-invite-bot', async t => {
uin : 324216852,
}
const EXPECTED_MESSAGE_PAYLOAD_ROOM_JOIN: PuppetRoomJoinEvent = {
const EXPECTED_EVENT: PuppetRoomJoinEvent = {
inviteeNameList : [YOU],
inviterName : '李佳芮',
roomId : '8083065140@chatroom',
}
const payload = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
console.log('payload:', payload)
t.deepEqual(payload, EXPECTED_MESSAGE_PAYLOAD_ROOM_JOIN, 'should parse room join message payload')
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() ZH-other-invite-bot-with-others', async t => {
......@@ -101,6 +108,14 @@ test('roomJoinEventMessageParser() ZH-other-invite-bot-with-others', async t =>
to_user : 'wxid_a8d806dzznm822',
uin : 1211516682,
}
const EXPECTED_EVENT: PuppetRoomJoinEvent = {
inviteeNameList : [YOU, 'Huan LI++'],
inviterName : '李卓桓',
roomId : '5178377660@chatroom',
}
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() ZH-bot-invite-other', async t => {
......@@ -118,6 +133,14 @@ test('roomJoinEventMessageParser() ZH-bot-invite-other', async t => {
to_user : 'lizhuohuan',
uin : 4763975,
}
const EXPECTED_EVENT: PuppetRoomJoinEvent = {
inviteeNameList : ['Huan LI++'],
inviterName : YOU,
roomId : '5354656522@chatroom',
}
const event = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
t.deepEqual(event, EXPECTED_EVENT, 'should parse event')
})
test('roomJoinEventMessageParser() ZH-bot-invite-others', async t => {
......
......@@ -18,20 +18,20 @@ import { roomJoinEventMessageParser, roomLeaveEventMessageParser } from './room
test('roomLeaveEventMessageParser() EN-bot-delete-other', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content: 'You removed "李卓桓" from the group chat',
continue: 1,
description: '',
from_user: '6061139518@chatroom',
msg_id: '4444372134867544747',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528751382,
to_user: 'wxid_5zj4i5htp9ih22',
uin: 1928023446,
content : 'You removed "李卓桓" from the group chat',
continue : 1,
description : '',
from_user : '6061139518@chatroom',
msg_id : '4444372134867544747',
msg_source : '',
msg_type : 5,
status : 1,
sub_type : 10000,
timestamp : 1528751382,
to_user : 'wxid_5zj4i5htp9ih22',
uin : 1928023446,
}
const EXPECTED_MESSAGE_PAYLOAD_ROOM_LEAVE: PuppetRoomLeaveEvent = {
const EXPECTED_EVENT: PuppetRoomLeaveEvent = {
leaverNameList : ['李卓桓'],
removerName : YOU,
roomId : '6061139518@chatroom',
......@@ -39,7 +39,7 @@ test('roomLeaveEventMessageParser() EN-bot-delete-other', async t => {
const payload = roomJoinEventMessageParser(MESSAGE_PAYLOAD)
// console.log('payload:', payload)
t.deepEqual(payload, EXPECTED_MESSAGE_PAYLOAD_ROOM_LEAVE, 'should parse room leave message payload')
t.deepEqual(payload, EXPECTED_EVENT, 'should parse room leave message payload')
})
......
......@@ -17,7 +17,7 @@ import {
import { roomLeaveEventMessageParser } from './room-event-message-parser'
test('roomLeaveEventMessageParser() ZH-bot-delete-other', async t => {
const PADCHAT_MESSAGE_PAYLOAD_ROOM_LEAVE: PadchatMessagePayload = {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content : '你将"Huan LI++"移出了群聊',
continue : 1,
description : '',
......@@ -32,15 +32,15 @@ test('roomLeaveEventMessageParser() ZH-bot-delete-other', async t => {
uin : 4763975,
}
const EXPECTED_MESSAGE_PAYLOAD_ROOM_LEAVE: PuppetRoomLeaveEvent = {
leaverNameList: ['Huan LI++'],
removerName: YOU,
roomId: '5354656522@chatroom',
const EXPECTED_EVENT: PuppetRoomLeaveEvent = {
leaverNameList : ['Huan LI++'],
removerName : YOU,
roomId : '5354656522@chatroom',
}
const payload = roomLeaveEventMessageParser(PADCHAT_MESSAGE_PAYLOAD_ROOM_LEAVE)
const payload = roomLeaveEventMessageParser(MESSAGE_PAYLOAD)
// console.log('payload:', payload)
t.deepEqual(payload, EXPECTED_MESSAGE_PAYLOAD_ROOM_LEAVE, 'should parse room leave message payload')
t.deepEqual(payload, EXPECTED_EVENT, 'should parse room leave message payload')
})
test('roomLeaveEventMessageParser() ZH-bot-delete-others', async t => {
......@@ -49,20 +49,28 @@ test('roomLeaveEventMessageParser() ZH-bot-delete-others', async t => {
test('roomLeaveEventMessageParser() ZH-other-delete-bot', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content: '你被"李卓桓"移出群聊',
continue: 1,
description: '',
from_user: '5178377660@chatroom',
msg_id: '78437822999859076',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528752134,
to_user: 'wxid_a8d806dzznm822',
uin: 1211516682,
content : '你被"李卓桓"移出群聊',
continue : 1,
description : '',
from_user : '5178377660@chatroom',
msg_id : '78437822999859076',
msg_source : '',
msg_type : 5,
status : 1,
sub_type : 10000,
timestamp : 1528752134,
to_user : 'wxid_a8d806dzznm822',
uin : 1211516682,
}
const EXPECTED_EVENT: PuppetRoomLeaveEvent = {
leaverNameList : [YOU],
removerName : '李卓桓',
roomId : '5178377660@chatroom',
}
t.skip('tbw')
const payload = roomLeaveEventMessageParser(MESSAGE_PAYLOAD)
// console.log('payload:', payload)
t.deepEqual(payload, EXPECTED_EVENT, 'should parse room leave message payload')
})
test('roomLeaveEventMessageParser() ZH-other-delete-other', async t => {
......
#!/usr/bin/env ts-node
// tslint:disable:max-line-length
// tslint:disable:no-shadowed-variable
import test from 'blue-tape'
import {
PadchatMessagePayload,
} from '../padchat-schemas'
import {
roomJoinEventMessageParser,
roomLeaveEventMessageParser,
roomTopicEventMessageParser,
} from './room-event-message-parser'
test('roomJoinEventMessageParser() not detected', async t => {
t.equal(
roomJoinEventMessageParser(undefined as any),
null,
'should return null for undefined',
)
t.equal(
roomJoinEventMessageParser('null' as any),
null,
'should return null for null',
)
t.equal(
roomJoinEventMessageParser('test' as any),
null,
'should return null for string',
)
t.equal(
roomJoinEventMessageParser({} as any),
null,
'should return null for empty object',
)
t.equal(
roomJoinEventMessageParser({ content: 'fsdfsfsdfasfas' } as PadchatMessagePayload ),
null,
'should return null for PadchatMessagePayload with unknown content',
)
})
test('roomLeaveEventMessageParser() not detected', async t => {
t.equal(
roomLeaveEventMessageParser(undefined as any),
null,
'should return null for undefined',
)
t.equal(
roomLeaveEventMessageParser('null' as any),
null,
'should return null for null',
)
t.equal(
roomLeaveEventMessageParser('test' as any),
null,
'should return null for string',
)
t.equal(
roomLeaveEventMessageParser({} as any),
null,
'should return null for empty object',
)
t.equal(
roomLeaveEventMessageParser({ content: 'fsdfsfsdfasfas' } as PadchatMessagePayload ),
null,
'should return null for PadchatMessagePayload with unknown content',
)
})
test('roomTopicEventMessageParser() not detected', async t => {
t.equal(
roomTopicEventMessageParser(undefined as any),
null,
'should return null for undefined',
)
t.equal(
roomTopicEventMessageParser('null' as any),
null,
'should return null for null',
)
t.equal(
roomTopicEventMessageParser('test' as any),
null,
'should return null for string',
)
t.equal(
roomTopicEventMessageParser({} as any),
null,
'should return null for empty object',
)
t.equal(
roomTopicEventMessageParser({ content: 'fsdfsfsdfasfas' } as PadchatMessagePayload ),
null,
'should return null for PadchatMessagePayload with unknown content',
)
})
......@@ -12,24 +12,24 @@ import {
import {
PadchatMessagePayload,
} from '../padchat-schemas'
} from '../padchat-schemas'
import { roomTopicEventMessageParser } from './room-event-message-parser'
test('roomTopicEventMessageParser() EN-other-modify-topic', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content: '"李卓桓" changed the group name to "新群名"',
continue: 1,
description: '',
from_user: '5354656522@chatroom',
msg_id: '1699332376319377977',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528656400,
to_user: 'wxid_5zj4i5htp9ih22',
uin: 1928023446,
content : '"李卓桓" changed the group name to "新群名"',
continue : 1,
description : '',
from_user : '5354656522@chatroom',
msg_id : '1699332376319377977',
msg_source : '',
msg_type : 5,
status : 1,
sub_type : 10000,
timestamp : 1528656400,
to_user : 'wxid_5zj4i5htp9ih22',
uin : 1928023446,
}
const EXPECTED_EVENT: PuppetRoomTopicEvent = {
changerName : '李卓桓',
......
......@@ -12,13 +12,13 @@ import {
import {
PadchatMessagePayload,
} from '../padchat-schemas'
} from '../padchat-schemas'
import { roomTopicEventMessageParser } from './room-event-message-parser'
test('roomTopicEventMessageParser() ZH-bot-modify-topic', async t => {
const PADCHAT_MESSAGE_PAYLOAD_ROOM_TOPIC: PadchatMessagePayload = {
content : '你修改群名为“新群名',
content : '你修改群名为“新群名”',
continue : 1,
description : '',
from_user : '5354656522@chatroom',
......@@ -35,28 +35,28 @@ test('roomTopicEventMessageParser() ZH-bot-modify-topic', async t => {
const EXPECTED_MESSAGE_PAYLOAD_ROOM_TOPIC: PuppetRoomTopicEvent = {
changerName : YOU,
roomId : '5354656522@chatroom',
topic : '新群名',
topic : '新群名',
}
const payload = roomTopicEventMessageParser(PADCHAT_MESSAGE_PAYLOAD_ROOM_TOPIC)
console.log('payload:', payload)
// console.log('payload:', payload)
t.deepEqual(payload, EXPECTED_MESSAGE_PAYLOAD_ROOM_TOPIC, 'should parse room topic message payload')
})
test('roomTopicEventMessageParser() ZH-other-modify-topic', async t => {
const MESSAGE_PAYLOAD: PadchatMessagePayload = {
content: '"李卓桓"修改群名为“新群名”',
continue: 1,
description: '',
from_user: '5354656522@chatroom',
msg_id: '4311778109694299650',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528656552,
to_user: 'wxid_a8d806dzznm822',
uin: 1211516682,
content : '"李卓桓"修改群名为“新群名”',
continue : 1,
description : '',
from_user : '5354656522@chatroom',
msg_id : '4311778109694299650',
msg_source : '',
msg_type : 5,
status : 1,
sub_type : 10000,
timestamp : 1528656552,
to_user : 'wxid_a8d806dzznm822',
uin : 1211516682,
}
const EXPECTED_MESSAGE_PAYLOAD_ROOM_TOPIC: PuppetRoomTopicEvent = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册