104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import {
|
|
applyLiveBindingStateSnapshot,
|
|
compareCustomerRole,
|
|
isStaleLiveStateVersion,
|
|
statusForLive,
|
|
} from './douyu-fulfillment-service.js'
|
|
|
|
const task = {
|
|
customer_role_name: '狗鼻子弗尼亚bd',
|
|
customer_platform: 'wechat',
|
|
customer_system: 'android',
|
|
} as never
|
|
|
|
const live = {
|
|
roleName: '狗鼻子弗尼亚bd',
|
|
areaName: '微信',
|
|
platName: '安卓(android)',
|
|
} as never
|
|
|
|
test('斗鱼客户资料与平台角色一致', () => {
|
|
const result = compareCustomerRole(task, live)
|
|
assert.equal(result.matched, true)
|
|
assert.equal(result.roleMatched, true)
|
|
assert.equal(result.channelMatched, true)
|
|
})
|
|
|
|
test('斗鱼客户资料平台或系统不一致时禁止确认', () => {
|
|
const result = compareCustomerRole(task, {
|
|
...live,
|
|
areaName: 'QQ',
|
|
platName: '苹果(iOS)',
|
|
} as never)
|
|
assert.equal(result.matched, false)
|
|
assert.equal(result.channelMatched, false)
|
|
})
|
|
|
|
test('斗鱼客户资料角色名不一致时禁止确认', () => {
|
|
const result = compareCustomerRole(task, { ...live, roleName: '另一个角色' } as never)
|
|
assert.equal(result.matched, false)
|
|
assert.equal(result.roleMatched, false)
|
|
})
|
|
|
|
test('绑定失败优先于旧角色确认标记', () => {
|
|
const status = statusForLive({
|
|
executionStatus: 'manual_required',
|
|
bindingStatus: 'failed',
|
|
issueCode: 'customer_role_cooldown',
|
|
bindReadyForConfirm: true,
|
|
bindConfirmed: false,
|
|
qrUrl: 'https://example.com/old-qr',
|
|
accountReady: true,
|
|
} as never)
|
|
assert.equal(status, 'failed')
|
|
})
|
|
|
|
test('绑定失败代码优先于旧待确认状态', () => {
|
|
const status = statusForLive({
|
|
executionStatus: 'role_ready',
|
|
bindingStatus: 'role_ready',
|
|
issueCode: 'binding_failed',
|
|
bindReadyForConfirm: true,
|
|
bindConfirmed: false,
|
|
qrUrl: '',
|
|
accountReady: true,
|
|
} as never)
|
|
assert.equal(status, 'failed')
|
|
})
|
|
|
|
test('已分配账号保持 allocated,不折叠成准备账号', () => {
|
|
const status = statusForLive({
|
|
executionStatus: 'allocated',
|
|
bindingStatus: 'not_started',
|
|
issueCode: '',
|
|
bindReadyForConfirm: false,
|
|
bindConfirmed: false,
|
|
qrUrl: '',
|
|
accountReady: true,
|
|
} as never)
|
|
assert.equal(status, 'allocated')
|
|
})
|
|
|
|
test('直播账号状态版本只允许向前推进', () => {
|
|
assert.equal(isStaleLiveStateVersion(8, 7), true)
|
|
assert.equal(isStaleLiveStateVersion(8, 8), false)
|
|
assert.equal(isStaleLiveStateVersion(8, 9), false)
|
|
assert.equal(isStaleLiveStateVersion(8, 0), false)
|
|
})
|
|
|
|
test('直播账号状态推送忽略空数据和无效任务', async () => {
|
|
assert.deepEqual(await applyLiveBindingStateSnapshot({ items: [] }), {
|
|
received: 0,
|
|
updated: 0,
|
|
})
|
|
assert.deepEqual(
|
|
await applyLiveBindingStateSnapshot({
|
|
items: [{ sessionId: 0 }, null, { sessionId: 'bad' }],
|
|
}),
|
|
{ received: 3, updated: 0 },
|
|
)
|
|
})
|