Files
order_site/apps/frontend/tests/customer-fulfillment-binding-compare.test.ts
T
yml 79baab0cf7 修复(虎牙绑定): 扫错角色可重新扫码、绑定失败留证、确认后引导截图联系客服
按业务口径重审「资料 → 登录 → 读角色 → 绑定」全链路,修复 3 个 P0 与 4 处口径问题:

P0 重新扫码空转
- startPublicBinding 改为按 allowedActions 判定能否重新出码,不再只看 primaryAction。
  此前 first_bind_role_mismatch(primaryAction=contact_support)点「刷新绑定二维码」
  后端直接早退:二维码不重生成、旧 pending 不清,客户扫错角色后卡死。

P0 扫错角色被判成人工核实
- 换绑 pending 与目标资料不一致时不再返回 manual_review,改为 rebind_required
  (start_rebind + edit_profile + contact_support),客户可自愈。
- first_bind_role_mismatch 保留(后端仍会产出),客户页重新渲染该状态,
  确认按钮不再吞掉「重新扫码」「上一步修改资料」两个退回入口。
- requiresSupport 只在 manual_review 为真;canGenerateBindingQr 改为从 allowedActions 推导。
- 新增前端守卫测试:后端会产出的每个 flowState 在客户页都必须有可操作落点。

P0 确认后没有下一步引导
- confirmed 区块改为「绑定已确认」+「请截图本页,把订单号和这张截图发给客服」,
  展示并可复制订单号,保留刷新按钮。

失败留证
- Connector 拒绝时 bind_confirm_message 带平台返回码;确认写接口抛异常也落
  bind_confirm_message + last_error,不再只停在 submitting 等超时。
- rebind_platform_message 不再被「本次无消息」覆盖成空串;DTO 暴露
  bindConfirmState / bindConfirmMessage,客户页按去重顺序展示真实失败原因。
- 加密 role token 不再写入任务事件(仅保留 hasRoleToken 布尔标记)。

换绑冷却
- 平台未返回 changeBindTime 时不再推算「从现在起 N 天」;
  页面只在剩余天数 > 0 时展示「剩余约 N 天」,否则提示平台未返回。
- 冷却态补「刷新绑定状态」入口与「冷却结束后再回来点重新扫码换绑」指引。

文档同步虎牙绑定的可自愈动作、确认后截图引导、冷却与失败留证口径。
2026-12-02 11:02:37 +08:00

148 lines
7.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')
const huyaStyles = readFileSync(join(root, '../src/styles/customer/platform/huya.css'), 'utf8')
test('绑定确认只保留页内按钮,不再自动弹窗', () => {
assert.ok(!source.includes('customer-binding-modal'))
assert.ok(!source.includes('bindingConfirmOpen'))
assert.ok(!source.includes('setBindingConfirmOpen'))
assert.ok(!source.includes('handlePollBindingNow(true)'))
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('资料完整只判断已保存的三要素,截图由提交校验强制', () => {
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(!profileSource.includes('homepageScreenshotUrl'))
// 必填与格式校验统一收敛到纯函数,页面只负责展示提示。
assert.ok(source.includes('validateCustomerProfileSubmit({'))
assert.ok(source.includes('UID 只做资料留档,不参与绑定核验'))
assert.ok(source.includes('游戏角色 UID <span>*</span>'))
assert.ok(source.includes('游戏主页截图 <span>*</span>'))
assert.ok(source.includes("event.target.value.replace(/\\D/g, '')"))
assert.ok(source.includes('maxLength={20}'))
})
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('onClick={() => void handleConfirmBinding()}'))
assert.ok(source.includes('{canConfirmDecision ? ('))
const panelStart = source.indexOf('className="customer-binding-role-actions"')
const panelEnd = source.indexOf('</div>', panelStart)
const panel = source.slice(panelStart, panelEnd)
const confirmIndex = panel.indexOf('确认绑定这个角色到虎牙')
assert.ok(confirmIndex > 0)
// 确认按钮排在最上面,但重新扫码 / 修改资料必须同时可点,不能落进 else 分支。
assert.ok(panel.includes('重新扫码换绑'))
assert.ok(panel.includes('刷新绑定二维码'))
assert.ok(panel.includes('上一步修改资料'))
assert.ok(confirmIndex < panel.indexOf('刷新绑定二维码'))
assert.ok(confirmIndex < panel.indexOf('上一步修改资料'))
assert.ok(!panel.includes(') : ('))
assert.ok(source.includes('平台角色与已填资料不一致'))
assert.ok(source.includes('角色名称、区服和平台信息一致后才能确认绑定'))
assert.ok(!styles.includes('.customer-binding-modal'))
assert.ok(!styles.includes('.customer-binding-compare'))
})
test('虎牙二维码使用深色紧凑卡片并删除重复说明', () => {
assert.ok(source.includes('微信扫码绑定'))
assert.ok(source.includes('使用微信扫码选择目标游戏角色'))
assert.ok(source.includes('已扫码,核对角色'))
assert.ok(source.includes('customer-huya-qr-code'))
assert.ok(!source.includes('扫码后系统只核对角色名称与区服,UID 不参与绑定判定'))
assert.ok(!source.includes('游戏角色 UID 为必填留档,不参与绑定判定'))
assert.ok(!source.includes('本次换绑成功后,下次可换绑'))
assert.ok(huyaStyles.includes('.customer-auth-page.is-huya .customer-binding-qr-card'))
assert.ok(huyaStyles.includes('.customer-huya-qr-code'))
assert.ok(huyaStyles.includes('background: #202631'))
assert.ok(source.includes('本次待确认角色'))
assert.ok(source.includes('登录账号'))
assert.ok(source.includes('当前绑定角色'))
assert.ok(source.includes('(bindingAccountName || currentRoleName || pendingRoleName)'))
assert.ok(source.includes('!bindingQrVisible'))
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}'))
})