76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import type { HuyaBindingDecision } from '../src/types/semi-auto-binding.ts'
|
|
import { formatHuyaBindingDecisionMessage } from '../src/utils/semi-auto-binding-decision.ts'
|
|
|
|
function decision(input: Partial<HuyaBindingDecision>): HuyaBindingDecision {
|
|
return {
|
|
accountRoleState: 'bound',
|
|
targetRoleMatch: 'mismatch',
|
|
flowState: 'rebind_blocked_account',
|
|
primaryAction: 'wait_account_rebind',
|
|
allowedActions: [],
|
|
rebindBlockScope: 'account',
|
|
accountRebindAvailableAt: '',
|
|
targetRoleRebindAvailableAt: '',
|
|
canGenerateBindingQr: false,
|
|
canConfirmBinding: false,
|
|
canCompleteTask: false,
|
|
requiresCustomerConfirmation: false,
|
|
requiresSupport: false,
|
|
comparison: {
|
|
verdict: 'mismatch',
|
|
customerRoleName: '',
|
|
customerRoleId: '',
|
|
customerZone: '',
|
|
boundRoleName: '',
|
|
boundRoleId: '',
|
|
boundRoleIdKind: 'missing',
|
|
boundZone: '',
|
|
verificationBasis: 'role_name_zone',
|
|
message: '',
|
|
missing: [],
|
|
mismatched: [],
|
|
},
|
|
currentRoleComparison: null,
|
|
pendingRoleComparison: null,
|
|
message: '',
|
|
...input,
|
|
}
|
|
}
|
|
|
|
test('虎牙账号换绑冷却提示使用页面格式化时间,不直接显示 ISO', () => {
|
|
const input = decision({
|
|
message: '当前虎牙登录账号仍在换绑冷却期,暂不可换绑',
|
|
accountRebindAvailableAt: '2026-11-21T16:00:00.000Z',
|
|
})
|
|
const text = formatHuyaBindingDecisionMessage(input)
|
|
|
|
assert.match(text, /当前虎牙登录账号仍在换绑冷却期/)
|
|
assert.match(text, /预计 \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 后可换绑/)
|
|
assert.doesNotMatch(text, /2026-11-21T16:00:00\.000Z/)
|
|
})
|
|
|
|
test('目标角色冷却提示只读取目标角色可换绑时间', () => {
|
|
const input = decision({
|
|
flowState: 'rebind_blocked_target_role',
|
|
rebindBlockScope: 'target_role',
|
|
message: '目标游戏角色仍在换绑冷却期,暂不可换绑',
|
|
accountRebindAvailableAt: '2026-11-20T16:00:00.000Z',
|
|
targetRoleRebindAvailableAt: '2026-11-23T16:00:00.000Z',
|
|
})
|
|
const text = formatHuyaBindingDecisionMessage(input)
|
|
|
|
assert.match(text, /目标游戏角色仍在换绑冷却期/)
|
|
assert.match(text, /预计 \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 后可换绑/)
|
|
assert.doesNotMatch(text, /2026-11-20/)
|
|
})
|
|
|
|
test('没有明确冷却时间时不补造时间', () => {
|
|
const text = formatHuyaBindingDecisionMessage(
|
|
decision({ message: '当前虎牙登录账号仍在换绑冷却期,暂不可换绑' }),
|
|
)
|
|
assert.equal(text, '当前虎牙登录账号仍在换绑冷却期,暂不可换绑')
|
|
})
|