Files
order_site/apps/frontend/tests/customer-fulfillment-binding-compare.test.ts
T

115 lines
5.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import test from 'node:test'
const root = dirname(fileURLToPath(import.meta.url))
const source = readFileSync(
join(root, '../src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx'),
'utf8',
)
const styles = readFileSync(join(root, '../src/styles/customer/binding.css'), 'utf8')
test('只有唯一绑定决策允许时才自动弹核对框', () => {
assert.ok(source.includes('if (!bindingDecision?.canConfirmBinding) return'))
assert.ok(source.includes('if (nextDecision?.canConfirmBinding) {'))
assert.ok(!source.includes("bindingInfo.comparison.verdict === 'match'"))
})
test('资料不一致时固定提供重新扫码换绑与上一步修改资料', () => {
assert.ok(source.includes('decisionRequiresRebind || decisionCanRefreshQr'))
assert.ok(source.includes('decisionCanEditProfile'))
assert.ok(source.includes('重新扫码换绑'))
assert.ok(source.includes('上一步修改资料'))
assert.ok(source.includes('onClick={() => void openProfileEditor()}'))
// 取消同步平台角色与直接使用原角色的快捷路径。
assert.ok(!source.includes('同步平台角色'))
assert.ok(!source.includes('确认使用原角色'))
assert.ok(styles.includes('.customer-binding-role-actions'))
})
test('保存资料后只由单一自动绑定流程推进,不再并发轮询', () => {
assert.ok(!source.includes('function reopenBindingConfirm('))
const saveStart = source.indexOf('async function handleSaveProfile()')
assert.ok(saveStart > 0)
const saveBody = source.slice(saveStart, saveStart + 1800)
assert.ok(!saveBody.includes('pollCustomerBinding('))
assert.ok(source.includes("'资料已保存,正在重新核对平台角色'"))
assert.ok(source.includes("'资料已保存,请继续登录虎牙账号'"))
assert.ok(source.includes("!['query_binding', 'start_first_binding'].includes"))
})
test('虎牙客户页固定先填写资料,再登录并绑定角色', () => {
const stepsStart = source.indexOf('const HUYA_FLOW_STEPS')
const stepsSource = source.slice(stepsStart, stepsStart + 260)
assert.ok(stepsSource.includes("'填写游戏资料'"))
assert.ok(stepsSource.includes("'登录虎牙账号'"))
assert.ok(stepsSource.includes("'绑定游戏角色'"))
assert.ok(source.includes('showHuyaProfileStage'))
assert.ok(source.includes('(isWeibo || profileComplete) &&'))
})
test('资料完整要求区服、角色名和 UID,但 UID 不做格式校验', () => {
const profileStart = source.indexOf('const profileComplete = Boolean(')
const profileEnd = source.indexOf('\n\n const load =', profileStart)
const profileSource = source.slice(profileStart, profileEnd)
assert.ok(profileSource.includes('customerServerZone'))
assert.ok(profileSource.includes('customerGameRoleId'))
assert.ok(profileSource.includes('customerGameRoleName'))
assert.ok(source.includes('请完整填写区服、游戏角色 UID 和角色名'))
assert.ok(source.includes('UID 只做资料留档,不参与绑定核验'))
assert.ok(source.includes('游戏角色 UID <span>*</span>'))
assert.ok(!source.includes('游戏角色 UID 只能是数字'))
assert.ok(!source.includes('!/^\\d+$/.test(profileRoleId.trim())'))
})
test('登录和绑定专用同步阶段暂停整单轮询', () => {
assert.ok(source.includes('const dedicatedLoginPoll ='))
assert.ok(source.includes('const dedicatedBindingPoll ='))
assert.ok(source.includes('if (dedicatedLoginPoll || dedicatedBindingPoll) return'))
assert.ok(source.includes('}, 10_000)'))
})
test('虎牙绑定只在二维码或平台生效等待态轮询,过期二维码不再持续请求', () => {
assert.ok(source.includes("'first_bind_qr_pending'"))
assert.ok(source.includes("'rebind_qr_pending'"))
assert.ok(source.includes("'rebind_effect_pending'"))
const pollingStart = source.indexOf('const huyaBindingPolling')
const pollingEnd = source.indexOf('const isWeibo', pollingStart)
const pollingSource = source.slice(pollingStart, pollingEnd)
assert.ok(!pollingSource.includes('bindingActions.has('))
})
test('角色名和区服一致才出现确认绑定,不一致时展示原因', () => {
assert.ok(source.includes('确认绑定此角色'))
assert.ok(source.includes('canConfirmDecision'))
assert.ok(source.includes('两侧角色信息不一致,无法提交平台绑定'))
assert.ok(source.includes('customer-binding-modal-error'))
})
test('二维码区明确只核验角色名与区服,UID 不参与绑定', () => {
assert.ok(source.includes('扫码后系统只核对角色名称与区服,UID 不参与绑定判定'))
assert.ok(source.includes('游戏角色 UID 为必填留档,不参与绑定判定'))
assert.ok(source.includes('本次待确认角色'))
assert.ok(source.includes('登录账号'))
assert.ok(source.includes('当前绑定角色'))
assert.ok(!source.includes('虎牙账号 UID'))
assert.ok(!source.includes('目标角色 UID'))
assert.ok(!source.includes('待确认角色 UID'))
assert.ok(!source.includes('平台角色 UID:'))
assert.ok(!source.includes('平台已返回加密角色标识'))
assert.ok(!source.includes('平台加密标识已识别'))
assert.ok(!source.includes('const bindingPendingUid'))
assert.ok(!source.includes('const huyaUid = String(selectedTask?.huyaUid'))
})
test('换绑流程刷新二维码必须带 forceRebind,避免直接返回已有角色', () => {
assert.ok(source.includes('function handleRefreshBindingQr()'))
assert.ok(source.includes("bindingDecision?.primaryAction === 'start_rebind'"))
assert.ok(source.includes("bindingDecision?.primaryAction === 'refresh_rebind_qr'"))
// 三处刷新/重新获取入口都不能再固定传 false。
assert.ok(!source.includes('handleRefreshBinding(false)'))
assert.ok(source.includes('onClick={handleRefreshBindingQr}'))
})