Skip to content

Commit

Permalink
feat(test-utils): BREAKING no reply
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 26, 2020
1 parent dd2fbe3 commit cf175f7
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 54 deletions.
44 changes: 22 additions & 22 deletions packages/koishi-core/tests/runtime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,30 @@ describe('command prefix', () => {

await session1.shouldHaveReply('foo bar', 'foobar')
await session2.shouldHaveReply('foo bar', 'foobar')
await session1.shouldHaveNoResponse('!foo bar')
await session2.shouldHaveNoResponse('!foo bar')
await session1.shouldHaveNoResponse('.foo bar')
await session2.shouldHaveNoResponse('.foo bar')
await session1.shouldHaveNoReply('!foo bar')
await session2.shouldHaveNoReply('!foo bar')
await session1.shouldHaveNoReply('.foo bar')
await session2.shouldHaveNoReply('.foo bar')
})

test('single prefix', async () => {
app.options.commandPrefix = '!'
app.prepare()

await session1.shouldHaveReply('foo bar', 'foobar')
await session2.shouldHaveNoResponse('foo bar')
await session2.shouldHaveNoReply('foo bar')
await session1.shouldHaveReply('!foo bar', 'foobar')
await session2.shouldHaveReply('!foo bar', 'foobar')
await session1.shouldHaveNoResponse('.foo bar')
await session2.shouldHaveNoResponse('.foo bar')
await session1.shouldHaveNoReply('.foo bar')
await session2.shouldHaveNoReply('.foo bar')
})

test('multiple prefixes', async () => {
app.options.commandPrefix = ['!', '.']
app.prepare()

await session1.shouldHaveReply('foo bar', 'foobar')
await session2.shouldHaveNoResponse('foo bar')
await session2.shouldHaveNoReply('foo bar')
await session1.shouldHaveReply('!foo bar', 'foobar')
await session2.shouldHaveReply('!foo bar', 'foobar')
await session1.shouldHaveReply('.foo bar', 'foobar')
Expand All @@ -74,8 +74,8 @@ describe('command prefix', () => {

await session1.shouldHaveReply('foo bar', 'foobar')
await session2.shouldHaveReply('foo bar', 'foobar')
await session1.shouldHaveNoResponse('!foo bar')
await session2.shouldHaveNoResponse('!foo bar')
await session1.shouldHaveNoReply('!foo bar')
await session2.shouldHaveNoReply('!foo bar')
await session1.shouldHaveReply('.foo bar', 'foobar')
await session2.shouldHaveReply('.foo bar', 'foobar')
})
Expand All @@ -96,7 +96,7 @@ describe('nickname prefix', () => {

test('no nickname', async () => {
await session1.shouldHaveReply('foo bar', 'foobar')
await session2.shouldHaveNoResponse('foo bar')
await session2.shouldHaveNoReply('foo bar')
await session1.shouldHaveReply('-foo bar', 'foobar')
await session2.shouldHaveReply('-foo bar', 'foobar')
await session2.shouldHaveReply(`[CQ:at,qq=${app.selfId}] foo bar`, 'foobar')
Expand All @@ -112,16 +112,16 @@ describe('nickname prefix', () => {
await session2.shouldHaveReply('koishi\n foo bar', 'foobar')
await session1.shouldHaveReply('@koishi foo bar', 'foobar')
await session2.shouldHaveReply('@koishi foo bar', 'foobar')
await session1.shouldHaveNoResponse('komeiji, foo bar')
await session2.shouldHaveNoResponse('komeiji, foo bar')
await session1.shouldHaveNoReply('komeiji, foo bar')
await session2.shouldHaveNoReply('komeiji, foo bar')
})

test('multiple nicknames', async () => {
app.options.nickname = ['komeiji', 'koishi']
app.prepare()

await session1.shouldHaveReply('foo bar', 'foobar')
await session2.shouldHaveNoResponse('foo bar')
await session2.shouldHaveNoReply('foo bar')
await session1.shouldHaveReply('-foo bar', 'foobar')
await session2.shouldHaveReply('-foo bar', 'foobar')
await session1.shouldHaveReply('koishi, foo bar', 'foobar')
Expand Down Expand Up @@ -218,25 +218,25 @@ describe('shortcuts', () => {
test('single shortcut', async () => {
await session2.shouldHaveReply(' bar1 ', 'foobar')
await session2.shouldHaveReply(' bar2 ', 'fooobar')
await session2.shouldHaveNoResponse('bar1 bar')
await session2.shouldHaveNoResponse('bar2 -t bar')
await session2.shouldHaveNoReply('bar1 bar')
await session2.shouldHaveNoReply('bar2 -t bar')
})

test('no command prefix', async () => {
await session2.shouldHaveNoResponse('#bar1')
await session2.shouldHaveNoResponse('#bar2')
await session2.shouldHaveNoResponse('#bar3')
await session2.shouldHaveNoResponse('#baz')
await session2.shouldHaveNoReply('#bar1')
await session2.shouldHaveNoReply('#bar2')
await session2.shouldHaveNoReply('#bar3')
await session2.shouldHaveNoReply('#baz')
})

test('nickname prefix & fuzzy', async () => {
await session2.shouldHaveNoResponse('bar3 -t baz')
await session2.shouldHaveNoReply('bar3 -t baz')
await session2.shouldHaveReply(`[CQ:at,qq=${app.selfId}] bar3 -t baz`, 'fooobaz')
})

test('one argument & fuzzy', async () => {
await session2.shouldHaveReply('bar4 bar baz', 'foobar baz')
await session2.shouldHaveNoResponse('bar4bar baz')
await session2.shouldHaveNoReply('bar4bar baz')
await session2.shouldHaveReply(`[CQ:at,qq=${app.selfId}] bar4bar baz`, 'foobar baz')
})
})
20 changes: 10 additions & 10 deletions packages/koishi-core/tests/suggestion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,45 @@ describe('Command Suggestions', () => {

test('execute command', async () => {
await session1.shouldHaveReply('foo bar', 'foobar')
await session1.shouldHaveNoResponse(' ')
await session1.shouldHaveNoReply(' ')
})

test('no suggestions found', async () => {
await session1.shouldHaveNoResponse('bar foo')
await session1.shouldHaveNoReply('bar foo')
})

test('apply suggestions 1', async () => {
await session1.shouldHaveReply('fo bar', expectedSuggestionText)
await session2.shouldHaveReply('fooo -t bar')
await session1.shouldHaveReply(' ', 'foobar')
await session1.shouldHaveNoResponse(' ')
await session1.shouldHaveNoReply(' ')
})

test('apply suggestions 2', async () => {
await session2.shouldHaveReply('foooo -t bar', expectedSuggestionText2)
await session1.shouldHaveReply('foo bar')
await session2.shouldHaveReply(' ', 'fooobar')
await session2.shouldHaveNoResponse(' ')
await session2.shouldHaveNoReply(' ')
})

test('ignore suggestions 1', async () => {
await session1.shouldHaveReply('fo bar', expectedSuggestionText)
await session1.shouldHaveNoResponse('bar foo')
await session1.shouldHaveNoResponse(' ')
await session1.shouldHaveNoReply('bar foo')
await session1.shouldHaveNoReply(' ')
})

test('ignore suggestions 2', async () => {
await session2.shouldHaveReply('fo bar', expectedSuggestionText)
await session2.shouldHaveReply('foo bar')
await session2.shouldHaveNoResponse(' ')
await session2.shouldHaveNoReply(' ')
})

test('multiple suggestions', async () => {
await session1.shouldHaveReply('fool bar', [
messages.COMMAND_SUGGESTION_PREFIX,
format(messages.SUGGESTION_TEXT, '“foo”或“fooo”'),
].join(''))
await session1.shouldHaveNoResponse(' ')
await session1.shouldHaveNoReply(' ')
})
})

Expand All @@ -98,7 +98,7 @@ describe('Custom Suggestions with Arguments', () => {
})

test('show suggestions', async () => {
await session.shouldHaveNoResponse(' ')
await session.shouldHaveNoReply(' ')
await session.shouldHaveReply('for', `prefix${format(messages.SUGGESTION_TEXT, '“foo”')}suffix`)
await session.shouldHaveReply(' ', 'text:foo')
})
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('Custom Suggestions with Options', () => {
})

test('show suggestions', async () => {
await session.shouldHaveNoResponse(' ')
await session.shouldHaveNoReply(' ')
await session.shouldHaveReply('for', `prefix${format(messages.SUGGESTION_TEXT, '“foo”')}suffix`)
await session.shouldHaveReply(' ', 'text:foo')
})
Expand Down
18 changes: 9 additions & 9 deletions packages/koishi-core/tests/validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,28 @@ afterAll(() => app.stop())
describe('middleware validation', () => {
test('user.flag.ignore', async () => {
await session1.shouldHaveReply('cmd2', 'cmd2:123')
await session3.shouldHaveNoResponse('cmd2')
await session3.shouldHaveNoReply('cmd2')
})

test('group.assignee', async () => {
await session4.shouldHaveReply('cmd1 --baz', 'cmd1:123')
await session4.shouldHaveReply('mid', 'mid')
await session5.shouldHaveNoResponse('cmd1 --baz')
await session5.shouldHaveNoReply('cmd1 --baz')
await session5.shouldHaveReply(`[CQ:at,qq=${app.selfId}] cmd1 --baz`, 'cmd1:123')
})

test('group.flag.noCommand', async () => {
await app.database.setGroup(321, { flag: GroupFlag.noCommand })
await session4.shouldHaveReply('mid', 'mid')
await session4.shouldHaveNoResponse('cmd1 --baz')
await session4.shouldHaveNoResponse(`[CQ:at,qq=${app.selfId}] cmd1 --baz`)
await session4.shouldHaveNoReply('cmd1 --baz')
await session4.shouldHaveNoReply(`[CQ:at,qq=${app.selfId}] cmd1 --baz`)
await app.database.setGroup(321, { flag: 0 })
})

test('group.flag.noResponse', async () => {
await app.database.setGroup(321, { flag: GroupFlag.noResponse })
await session4.shouldHaveNoResponse('mid')
await session4.shouldHaveNoResponse('cmd1 --baz')
await session4.shouldHaveNoReply('mid')
await session4.shouldHaveNoReply('cmd1 --baz')
await session4.shouldHaveReply(`[CQ:at,qq=${app.selfId}] cmd1 --baz`, 'cmd1:123')
await app.database.setGroup(321, { flag: 0 })
})
Expand All @@ -74,7 +74,7 @@ describe('command validation', () => {
await session2.shouldHaveReply('cmd1', messages.LOW_AUTHORITY)
await session1.shouldHaveReply('cmd1 --bar', messages.LOW_AUTHORITY)
app.command('cmd1', { showWarning: false })
await session1.shouldHaveNoResponse('cmd1 --bar')
await session1.shouldHaveNoReply('cmd1 --bar')
})

test('check usage', async () => {
Expand All @@ -84,14 +84,14 @@ describe('command validation', () => {
await session1.shouldHaveReply('cmd1', messages.USAGE_EXHAUSTED)
await session1.shouldHaveReply('cmd1 --baz', 'cmd1:123')
app.command('cmd1', { showWarning: false })
await session1.shouldHaveNoResponse('cmd1')
await session1.shouldHaveNoReply('cmd1')
})

test('check frequency', async () => {
app.command('cmd2', { showWarning: true })
await session2.shouldHaveReply('cmd2', 'cmd2:456')
await session2.shouldHaveReply('cmd2', messages.TOO_FREQUENT)
app.command('cmd2', { showWarning: false })
await session2.shouldHaveNoResponse('cmd2')
await session2.shouldHaveNoReply('cmd2')
})
})
2 changes: 1 addition & 1 deletion packages/plugin-common/tests/exec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const session = app.createSession('user', 123)
app.plugin(exec)

test('no input', async () => {
await session.shouldHaveNoResponse('$')
await session.shouldHaveNoReply('$')
})

test('stdout', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-common/tests/exit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ beforeEach(() => mock.mockClear())
afterAll(() => process.exit = processExit)

test('terminate', async () => {
await session.shouldHaveNoResponse(`koishi, 关机`)
await session.shouldHaveNoReply(`koishi, 关机`)
expect(mock).toBeCalledTimes(1)
expect(mock).toBeCalledWith(0)
})

test('restart', async () => {
await session.shouldHaveNoResponse(`koishi, 重启`)
await session.shouldHaveNoReply(`koishi, 重启`)
expect(mock).toBeCalledTimes(1)
expect(mock).toBeCalledWith(-1)
})
2 changes: 1 addition & 1 deletion packages/plugin-common/tests/help.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('help command', () => {
await session1.shouldMatchSnapshot('bar -h')
await session1.shouldMatchSnapshot('foo -h')
await session1.shouldMatchSnapshot('help help -e')
await session2.shouldHaveNoResponse('help.foo -h')
await session2.shouldHaveNoReply('help.foo -h')
await session2.shouldMatchSnapshot('help help.foo')
})

Expand Down
14 changes: 7 additions & 7 deletions packages/plugin-common/tests/repeater.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ test('repeat', async () => {
interruptCheck: false,
})

await session1.shouldHaveNoResponse('foo')
await session1.shouldHaveNoReply('foo')
await session1.shouldHaveReply('foo', 'foo')
await session1.shouldHaveNoResponse('foo')
await session1.shouldHaveNoResponse('foo')
await session1.shouldHaveNoReply('foo')
await session1.shouldHaveNoReply('foo')
})

test('interrupt', async () => {
Expand All @@ -30,7 +30,7 @@ test('interrupt', async () => {
interruptCheck: false,
})

await session1.shouldHaveNoResponse('foo')
await session1.shouldHaveNoReply('foo')
await session1.shouldHaveReply('foo', 'foo')
await session1.shouldHaveReply('foo', '打断复读!')
})
Expand All @@ -47,7 +47,7 @@ test('repeat check', async () => {
interruptCheck: false,
})

await session1.shouldHaveNoResponse('foo')
await session1.shouldHaveNoReply('foo')
await session1.shouldHaveReply('foo', 'foo')
await session2.shouldHaveReply('foo', 'foo')
await session2.shouldHaveReply('foo', `[CQ:at,qq=${session2.userId}] 在?为什么重复复读?`)
Expand All @@ -64,8 +64,8 @@ test('interrupt check', async () => {
interruptCheck: (_, times) => times >= 2,
})

await session1.shouldHaveNoResponse('foo')
await session1.shouldHaveNoResponse('bar')
await session1.shouldHaveNoReply('foo')
await session1.shouldHaveNoReply('bar')
await session1.shouldHaveReply('bar', 'bar')
await session1.shouldHaveReply('foo', `[CQ:at,qq=${session1.userId}] 在?为什么打断复读?`)
})
2 changes: 1 addition & 1 deletion packages/plugin-common/tests/respondent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ app.plugin<Respondent[]>(respondent, [{
test('basic support', async () => {
await session.shouldHaveReply('挖坑一时爽', '填坑火葬场')
await session.shouldHaveReply('填坑一时爽', '一直填坑一直爽')
await session.shouldHaveNoResponse('填坑一直爽')
await session.shouldHaveNoReply('填坑一直爽')
})
2 changes: 1 addition & 1 deletion packages/test-utils/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Session {
}
}

shouldHaveNoReplies (message: string) {
shouldHaveNoReply (message: string) {
return expect(this.send(message)).resolves.toHaveLength(0)
}

Expand Down

0 comments on commit cf175f7

Please sign in to comment.