Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
b3075a11
W
wechaty
项目概览
.Veneno.
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b3075a11
编写于
10月 24, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#40 fix unit test
上级
12deab2f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
16 deletion
+18
-16
src/puppet-web/firer.spec.ts
src/puppet-web/firer.spec.ts
+9
-10
src/puppet-web/firer.ts
src/puppet-web/firer.ts
+9
-6
未找到文件。
src/puppet-web/firer.spec.ts
浏览文件 @
b3075a11
...
...
@@ -29,21 +29,20 @@ test('Firer.checkFriendConfirm', t => {
'
你已添加了李卓桓,现在可以开始聊天了。
'
,
'
李卓桓
'
]
]
let
result
:
boolean
contentList
.
forEach
((
content
,
friend
)
=>
{
contentList
.
forEach
((
[
content
]
)
=>
{
result
=
Firer
.
checkFriendConfirm
(
content
)
t
.
tru
thy
(
result
,
'
should be truthy for confirm msg:
'
+
content
)
t
.
tru
e
(
result
,
'
should be truthy for confirm msg:
'
+
content
)
})
result
=
Firer
.
checkFriendConfirm
(
'
fsdfsdfasdfasdfadsa
'
)
t
.
fals
y
(
result
,
'
should be falsy for other msg
'
)
t
.
fals
e
(
result
,
'
should be falsy for other msg
'
)
})
test
(
'
Firer.checkRoomJoin
'
,
t
=>
{
const
contentList
=
[
const
contentList
:
[
string
,
string
,
string
[]][]
=
[
[
`You've invited "李卓桓" to the group chat`
,
`You've`
...
...
@@ -73,7 +72,7 @@ test('Firer.checkRoomJoin', t => {
let
result
contentList
.
forEach
(([
content
,
inviter
,
inviteeList
])
=>
{
result
=
Firer
.
checkRoomJoin
(
content
as
string
)
result
=
Firer
.
checkRoomJoin
(
content
)
t
.
truthy
(
result
,
'
should check room join message right for
'
+
content
)
t
.
deepEqual
(
result
[
0
],
inviteeList
,
'
should get inviteeList right
'
)
t
.
is
(
result
[
1
],
inviter
,
'
should get inviter right
'
)
...
...
@@ -81,7 +80,7 @@ test('Firer.checkRoomJoin', t => {
t
.
throws
(()
=>
{
Firer
.
checkRoomJoin
(
'
fsadfsadfsdfsdfs
'
)
},
'
should throws if message is not expected
'
)
},
Error
,
'
should throws if message is not expected
'
)
})
test
(
'
Firer.checkRoomLeave
'
,
t
=>
{
...
...
@@ -105,7 +104,7 @@ test('Firer.checkRoomLeave', t => {
t
.
throws
(()
=>
{
Firer
.
checkRoomLeave
(
'
fafdsfsdfafa
'
)
},
'
should throw if message is not expected
'
)
},
Error
,
'
should throw if message is not expected
'
)
})
test
(
'
Firer.checkRoomTopic
'
,
t
=>
{
...
...
@@ -126,12 +125,12 @@ test('Firer.checkRoomTopic', t => {
contentList
.
forEach
(([
content
,
changer
,
topic
])
=>
{
result
=
Firer
.
checkRoomTopic
(
content
)
t
.
truthy
(
result
,
'
should check topic right for content:
'
+
content
)
t
.
is
(
topic
,
result
[
2
],
'
should get right topic
'
)
t
.
is
(
topic
,
result
[
0
],
'
should get right topic
'
)
t
.
is
(
changer
,
result
[
1
],
'
should get right changer
'
)
})
t
.
throws
(()
=>
{
Firer
.
checkRoomTopic
(
'
fafdsfsdfafa
'
)
},
'
should throw if message is not expected
'
)
},
Error
,
'
should throw if message is not expected
'
)
})
src/puppet-web/firer.ts
浏览文件 @
b3075a11
...
...
@@ -93,9 +93,10 @@ async function fireFriendRequest(m: Message) {
/**
* try to find FriendRequest Confirmation Message
*/
function
checkFriendConfirm
(
content
)
{
function
checkFriendConfirm
(
content
:
string
):
boolean
{
const
reList
=
regexConfig
.
friendConfirm
let
found
=
false
reList
.
some
(
re
=>
!!
(
found
=
re
.
test
(
content
)))
if
(
found
)
{
return
true
...
...
@@ -140,7 +141,7 @@ function checkRoomJoin(content: string): [string[], string] {
let
found
:
string
[]
|
null
=
[]
reList
.
some
(
re
=>
!!
(
found
=
content
.
match
(
re
)))
if
(
!
found
||
!
found
.
length
)
{
throw
new
Error
(
'
checkRoomJoin() not found
'
)
throw
new
Error
(
'
checkRoomJoin() not found
matched re of
'
+
content
)
}
const
[
inviter
,
inviteeStr
]
=
[
found
[
1
],
found
[
2
]
]
...
...
@@ -280,7 +281,7 @@ function checkRoomLeave(content: string): string|null {
let
found
:
string
[]
|
null
=
[]
reList
.
some
(
re
=>
!!
(
found
=
content
.
match
(
re
)))
if
(
!
found
||
!
found
.
length
)
{
return
null
throw
new
Error
(
'
checkRoomLeave() no matched re for
'
+
content
)
}
return
found
[
1
]
// leaver
}
...
...
@@ -288,11 +289,13 @@ function checkRoomLeave(content: string): string|null {
/**
* You removed "Bruce LEE" from the group chat
*/
async
function
fireRoomLeave
(
m
:
Message
)
{
async
function
fireRoomLeave
(
m
:
Message
)
:
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWebFirer
'
,
'
fireRoomLeave(%s)
'
,
m
.
content
())
const
leaver
=
checkRoomLeave
(
m
.
content
())
if
(
!
leaver
)
{
let
leaver
try
{
leaver
=
checkRoomLeave
(
m
.
content
())
}
catch
(
e
)
{
return
}
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() got leaver: %s
'
,
leaver
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录