Skip to content

Commit

Permalink
test: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 21, 2022
1 parent 1aac4df commit 56af3d6
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 47 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@koishijs/utils": "^5.4.4",
"cordis": "^1.0.0",
"cordis": "^1.1.1",
"fastest-levenshtein": "^1.0.12",
"minato": "^1.1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@koishijs/segment": "^1.1.1",
"cosmokit": "^1.1.2",
"reggol": "^1.0.3",
"schemastery": "^3.4.1",
"schemastery": "^3.4.2",
"supports-color": "^8.1.1"
}
}
2 changes: 1 addition & 1 deletion plugins/a11y/schedule/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Schedule Plugin', () => {
await new Promise(process.nextTick)
await client1.shouldReply('', 'foo')

await client1.shouldReply('schedule -l', '2. 2000-01-01 00:30:00 起每隔 1 小时:echo foo')
await client1.shouldReply('schedule -l', '2. 每隔 1 小时 (剩余 59 分钟):echo foo')
await client1.shouldReply('schedule -d 2', '日程 2 已删除。')
clock.tick(Time.hour) // 02:31
await new Promise(process.nextTick)
Expand Down
2 changes: 1 addition & 1 deletion plugins/common/echo/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('@koishijs/plugin-echo', () => {
it('basic support', async () => {
await client.shouldReply('echo', '请输入要发送的文本。')
await client.shouldReply('echo foo', 'foo')
await client.shouldReply('echo -e []', '[]')
await client.shouldReply('echo -E []', '[]')
await client.shouldReply('echo -A foo', '[CQ:anonymous]foo')
await client.shouldReply('echo -a foo', '[CQ:anonymous,ignore=true]foo')

Expand Down
6 changes: 3 additions & 3 deletions plugins/common/forward/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface Rule {
guildId?: string
}

export const Rule = Schema.object({
export const Rule: Schema<Rule> = Schema.object({
source: Schema.string().required().description('来源频道'),
target: Schema.string().required().description('目标频道'),
selfId: Schema.string().required().description('负责推送的机器人账号'),
Expand All @@ -28,12 +28,12 @@ export interface Config {
interval?: number
}

export const schema = Schema.union([
export const Config = Schema.union([
Schema.object({
rules: Schema.array(Rule).description('转发规则'),
interval: Schema.natural().role('ms').default(Time.hour).description('推送消息不再响应回复的时间。'),
}),
Schema.transform(Schema.array(Rule), (rules) => ({ rules })),
Schema.transform(Schema.array(Rule), (rules) => ({ rules, interval: Time.hour })),
])

export function apply(ctx: Context, { rules, interval }: Config) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/common/forward/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('@koishijs/plugin-forward', () => {

it('command usage', async () => {
app.plugin('database-memory')
await app._tasks.flush()
await app.lifecycle.flush()
await app.mock.initUser('123', 3)

await session2.shouldReply('forward', //)
Expand Down
79 changes: 41 additions & 38 deletions plugins/common/repeater/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,60 @@ import { App } from 'koishi'
import mock from '@koishijs/plugin-mock'
import * as repeater from '@koishijs/plugin-repeater'

const app = new App().plugin(mock)
const session1 = app.mock.client('123', '123')
const session2 = app.mock.client('456', '123')
const session3 = app.mock.client('789', '123')
async function setup(config: repeater.Config) {
const app = new App().plugin(mock)
const client1 = app.mock.client('123', '123')
const client2 = app.mock.client('456', '123')
const client3 = app.mock.client('789', '123')

const options: repeater.Config = {}
app.plugin(repeater, options)

before(() => app.start())
app.plugin(repeater, config)
await app.start()
return [client1, client2, client3]
}

describe('Repeater', () => {
beforeEach(async () => {
options.onRepeat = null
options.onInterrupt = null
await session1.shouldNotReply('clear')
})

it('repeat (basic config)', async () => {
options.onRepeat = { minTimes: 2 }

await session1.shouldNotReply('foo')
await session1.shouldReply('foo', 'foo')
await session1.shouldNotReply('foo')
await session1.shouldNotReply('foo')
const [client1] = await setup({
onRepeat: { minTimes: 2 },
})

await client1.shouldNotReply('foo')
await client1.shouldReply('foo', 'foo')
await client1.shouldNotReply('foo')
await client1.shouldNotReply('foo')
})

it('repeat check', async () => {
options.onRepeat = ({ users }, { userId }) => users[userId] > 2 ? '在?为什么重复复读?' : ''

await session1.shouldNotReply('foo')
await session2.shouldNotReply('foo')
await session3.shouldNotReply('foo')
await session1.shouldNotReply('foo')
await session1.shouldReply('foo', '在?为什么重复复读?')
const [client1, client2, client3] = await setup({
onRepeat: ({ users }, { userId }) => users[userId] > 2 ? '在?为什么重复复读?' : '',
})

await client1.shouldNotReply('foo')
await client2.shouldNotReply('foo')
await client3.shouldNotReply('foo')
await client1.shouldNotReply('foo')
await client1.shouldReply('foo', '在?为什么重复复读?')
})

it('interrupt', async () => {
options.onRepeat = ({ times }) => times >= 3 ? '打断复读!' : ''
const [client1, client2, client3] = await setup({
onRepeat: ({ times }) => times >= 3 ? '打断复读!' : '',
})

await session1.shouldNotReply('foo')
await session2.shouldNotReply('foo')
await session3.shouldReply('foo', '打断复读!')
await client1.shouldNotReply('foo')
await client2.shouldNotReply('foo')
await client3.shouldReply('foo', '打断复读!')
})

it('interrupt check', async () => {
options.onInterrupt = ({ times }) => times >= 2 ? '在?为什么打断复读?' : ''

await session1.shouldNotReply('foo')
await session2.shouldNotReply('bar')
await session1.shouldNotReply('foo')
await session2.shouldNotReply('foo')
await session3.shouldReply('bar', '在?为什么打断复读?')
const [client1, client2, client3] = await setup({
onInterrupt: ({ times }) => times >= 2 ? '在?为什么打断复读?' : '',
})

await client1.shouldNotReply('foo')
await client2.shouldNotReply('bar')
await client1.shouldNotReply('foo')
await client2.shouldNotReply('foo')
await client3.shouldReply('bar', '在?为什么打断复读?')
})
})
2 changes: 1 addition & 1 deletion plugins/frontend/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"element-plus": "^2.1.11",
"marked": "^4.0.15",
"sass": "^1.51.0",
"schemastery": "^3.4.1",
"schemastery": "^3.4.2",
"vite": "^2.9.8",
"vue": "^3.2.33",
"vue-router": "^4.0.14"
Expand Down

0 comments on commit 56af3d6

Please sign in to comment.