修复(虎牙绑定): 扫错角色可重新扫码、绑定失败留证、确认后引导截图联系客服
按业务口径重审「资料 → 登录 → 读角色 → 绑定」全链路,修复 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 天」,否则提示平台未返回。 - 冷却态补「刷新绑定状态」入口与「冷却结束后再回来点重新扫码换绑」指引。 文档同步虎牙绑定的可自愈动作、确认后截图引导、冷却与失败留证口径。
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
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 customerTypes = readFileSync(join(root, '../src/types/customer-fulfillment.ts'), 'utf8')
|
||||
|
||||
/** 取样一段源码,找不到时直接失败,避免测试静默通过。 */
|
||||
function pickSlice(startMarker: string, endMarker: string) {
|
||||
const start = source.indexOf(startMarker)
|
||||
assert.ok(start >= 0, `源码缺少 ${startMarker}`)
|
||||
const end = source.indexOf(endMarker, start)
|
||||
assert.ok(end > start, `源码缺少 ${endMarker}`)
|
||||
return source.slice(start, end)
|
||||
}
|
||||
|
||||
test('确认成功区块引导客户截图并发给客服,同时给出可复制订单号', () => {
|
||||
const block = pickSlice(
|
||||
"bindingDecision?.flowState === 'confirmed' && !profileEditing",
|
||||
'{isWeibo &&',
|
||||
)
|
||||
assert.ok(block.includes('绑定已确认'))
|
||||
assert.ok(block.includes('截图'))
|
||||
assert.ok(block.includes('发给客服'))
|
||||
assert.ok(block.includes('刷新订单状态'))
|
||||
assert.ok(block.includes('订单号'))
|
||||
// 订单号直接取页面已有的 orderNo / task.orderNo,不另建字段。
|
||||
assert.ok(block.includes('{orderNo || selectedTask?.orderNo || '))
|
||||
assert.ok(block.includes('copyOrderNoForSupport('))
|
||||
// 旧文案已被替换。
|
||||
assert.ok(!source.includes('平台角色绑定已确认,客服正在处理订单'))
|
||||
})
|
||||
|
||||
test('确认按钮不吞掉重新扫码与修改资料两个退回入口', () => {
|
||||
const panel = pickSlice('className="customer-binding-role-actions"', '</div>')
|
||||
const confirmIndex = panel.indexOf('确认绑定这个角色到虎牙')
|
||||
assert.ok(confirmIndex > 0)
|
||||
assert.ok(panel.indexOf('重新扫码换绑') > confirmIndex)
|
||||
assert.ok(panel.indexOf('上一步修改资料') > confirmIndex)
|
||||
assert.ok(panel.includes('onClick={() => void openProfileEditor()}'))
|
||||
assert.ok(panel.includes('onClick={() => void handleRefreshBinding(true)}'))
|
||||
// 不再用 canConfirmDecision ? confirm : 其它动作 的三元结构。
|
||||
assert.ok(!panel.includes(') : ('))
|
||||
})
|
||||
|
||||
test('页面任何位置都不渲染 40 位 role token', () => {
|
||||
const confirmStart = source.indexOf('async function handleConfirmBinding()')
|
||||
const confirmEnd = source.indexOf('async function openProfileEditor()')
|
||||
assert.ok(confirmStart > 0 && confirmEnd > confirmStart)
|
||||
const confirmFn = source.slice(confirmStart, confirmEnd)
|
||||
// token 只用于「确认绑定」请求体,不参与展示。
|
||||
assert.ok(confirmFn.includes('expectedRoleToken'))
|
||||
const outside = source.slice(0, confirmStart) + source.slice(confirmEnd)
|
||||
assert.ok(!outside.includes('bindGameRoleToken'))
|
||||
assert.ok(!source.includes('>{bindingInfo?.bindGameRoleToken'))
|
||||
assert.ok(!source.includes('>{selectedTask?.bindGameRoleToken'))
|
||||
})
|
||||
|
||||
test('冷却天数只按后端返回值展示,为 0 时不出现「剩余约」', () => {
|
||||
const needle = '剩余约'
|
||||
let index = source.indexOf(needle)
|
||||
assert.ok(index > 0, '冷却期文案应当存在')
|
||||
let occurrences = 0
|
||||
while (index > 0) {
|
||||
occurrences += 1
|
||||
const guard = source.slice(Math.max(0, index - 200), index)
|
||||
assert.ok(
|
||||
guard.includes('rebindCooldownDays > 0'),
|
||||
'「剩余约」必须由 rebindCooldownDays > 0 守卫',
|
||||
)
|
||||
index = source.indexOf(needle, index + needle.length)
|
||||
}
|
||||
assert.ok(occurrences >= 1)
|
||||
// 虎牙口径的冷却文案必须存在(客户页绑定阶段使用)。
|
||||
assert.ok(source.includes('当前仍处于虎牙换绑冷却期,剩余约 ${rebindCooldownDays} 天'))
|
||||
// 冷却天数不得由 platformChangeBindDay 推算:窗口天数只用于「每 N 天可换绑 1 次」说明。
|
||||
const dayMarkers = source.split('platformChangeBindDay').length - 1
|
||||
assert.ok(dayMarkers <= 3)
|
||||
assert.ok(!source.includes('rebindCooldownDays + '))
|
||||
})
|
||||
|
||||
test('首次绑定缺码时给出生成二维码主按钮,二维码待扫态可退回改资料', () => {
|
||||
const initialBlock = pickSlice(
|
||||
"bindingDecision?.flowState === 'initial_bind_required'",
|
||||
'{bindingQrVisible && !bindingSessionExpired',
|
||||
)
|
||||
assert.ok(initialBlock.includes('生成绑定二维码'))
|
||||
assert.ok(initialBlock.includes('handleRefreshBinding(true)'))
|
||||
assert.ok(initialBlock.includes('bindingDecision.message'))
|
||||
|
||||
const qrStart = source.indexOf('customer-binding-qr-card customer-huya-qr-card')
|
||||
const qrBlock = source.slice(qrStart, source.indexOf('绑定二维码已过期', qrStart))
|
||||
assert.ok(qrBlock.includes('上一步修改资料'))
|
||||
assert.ok(qrBlock.includes('openProfileEditor()'))
|
||||
})
|
||||
|
||||
test('换绑冷却态提供只读刷新,并明确冷却后的下一步', () => {
|
||||
const blocked = pickSlice('isRebindBlocked ? (', ') : showRebindFailure ? (')
|
||||
assert.ok(blocked.includes('冷却结束后再回来点「重新扫码换绑」'))
|
||||
assert.ok(blocked.includes('平台未返回下次可换绑时间,请联系客服核实'))
|
||||
assert.ok(!blocked.includes('剩余约'))
|
||||
// 冷却态没有换绑动作,只能用只读刷新按钮重新查状态。
|
||||
assert.ok(
|
||||
source.includes('const canRefreshBindingState = decisionCanRefreshBinding || isRebindBlocked'),
|
||||
)
|
||||
assert.ok(source.includes('刷新绑定状态'))
|
||||
})
|
||||
|
||||
test('失败提示展示平台原因与任务异常且去重', () => {
|
||||
assert.ok(source.includes('bindingInfo?.bindConfirmMessage'))
|
||||
assert.ok(source.includes('selectedTask?.bindConfirmMessage'))
|
||||
assert.ok(source.includes('bindingDecision?.message'))
|
||||
assert.ok(source.includes('selectedTask?.lastError'))
|
||||
assert.ok(source.includes('seen.has(text)'))
|
||||
assert.ok(source.includes('bindingFailureReasons'))
|
||||
// 任务 DTO 新增字段已进类型。
|
||||
assert.ok(customerTypes.includes('bindConfirmState'))
|
||||
assert.ok(customerTypes.includes('bindConfirmMessage'))
|
||||
assert.ok(customerTypes.includes('lastError'))
|
||||
})
|
||||
|
||||
test('first_bind_role_mismatch 走可自愈动作,不归到人工核实', () => {
|
||||
// 首次绑定扫错角色仍由后端产出该状态,页面必须渲染它(含重新扫码 + 修改资料),
|
||||
// 且不能把它当成「两侧信息不完整,只能联系客服」。
|
||||
assert.ok(source.includes("'first_bind_role_mismatch'"))
|
||||
assert.ok(source.includes('bindingRequiresSupport'))
|
||||
assert.ok(!source.includes("['manual_review', 'first_bind_role_mismatch']"))
|
||||
})
|
||||
|
||||
test('后端可能产出的每个 flowState 都在客户页有落点,不存在只提示无动作的死状态', () => {
|
||||
const pageSource = readFileSync(
|
||||
join(root, '../src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx'),
|
||||
'utf8',
|
||||
)
|
||||
const policySource = readFileSync(
|
||||
join(root, '../../../apps/backend/src/services/semi-auto/huya-binding-policy.ts'),
|
||||
'utf8',
|
||||
)
|
||||
const enumBlock = policySource.slice(
|
||||
policySource.indexOf('export type HuyaBindingFlowState ='),
|
||||
policySource.indexOf('export type HuyaBindingAction ='),
|
||||
)
|
||||
const flowStates = [...enumBlock.matchAll(/'([a-z_]+)'/g)].map((match) => match[1])
|
||||
assert.ok(flowStates.length >= 15, '未解析到 flowState 枚举')
|
||||
|
||||
// 这些状态由其它区块承载:二维码卡片、已确认区块、过期提示、首查、初绑。
|
||||
const handledElsewhere = new Set([
|
||||
'binding_query_required',
|
||||
'initial_bind_required',
|
||||
'first_bind_qr_pending',
|
||||
'rebind_qr_pending',
|
||||
'confirmed',
|
||||
'expired',
|
||||
])
|
||||
const decisionStageBlock = pageSource.slice(
|
||||
pageSource.indexOf('const showBindingDecisionStage = Boolean('),
|
||||
pageSource.indexOf('const bindingComparison ='),
|
||||
)
|
||||
const missing = flowStates.filter(
|
||||
(state) => !handledElsewhere.has(state) && !decisionStageBlock.includes(`'${state}'`),
|
||||
)
|
||||
assert.deepEqual(missing, [], `以下状态在客户页没有任何可操作落点:${missing.join(', ')}`)
|
||||
})
|
||||
@@ -88,17 +88,23 @@ test('虎牙绑定只在二维码或平台生效等待态轮询,过期二维
|
||||
assert.ok(!pollingSource.includes('bindingActions.has('))
|
||||
})
|
||||
|
||||
test('角色名和区服一致才显示页内确认按钮,不一致时展示原因', () => {
|
||||
test('角色名和区服一致时确认按钮在最上,退回入口不被吞掉', () => {
|
||||
assert.ok(source.includes('确认绑定这个角色到虎牙'))
|
||||
assert.ok(source.includes('canConfirmDecision'))
|
||||
assert.ok(source.includes('onClick={() => void handleConfirmBinding()}'))
|
||||
assert.ok(source.includes('{canConfirmDecision ? ('))
|
||||
const confirmBranchStart = source.indexOf('{canConfirmDecision ? (')
|
||||
const confirmBranchEnd = source.indexOf(') : (', confirmBranchStart)
|
||||
const confirmBranch = source.slice(confirmBranchStart, confirmBranchEnd)
|
||||
assert.ok(confirmBranch.includes('确认绑定这个角色到虎牙'))
|
||||
assert.ok(!confirmBranch.includes('刷新绑定二维码'))
|
||||
assert.ok(!confirmBranch.includes('上一步修改资料'))
|
||||
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'))
|
||||
|
||||
Reference in New Issue
Block a user