调整(微博绑定): 确认后同样引导截图联系客服,换绑冷却按平台天数并留证

- 客户页抽出统一的「绑定已确认」渲染:标题 + 「请截图本页,把订单号和这张截图发给客服」+
  可复制订单号;虎牙与微博共用同一段文案,删除微博原来的「客服正在安排 / 请耐心等待」。
- 微博换绑冷却:天数只取后端 `rebindCooldownDays`(来自平台 `rebind_remain_days`);
  冷却中且已有绑定角色时禁用「微信绑定 / QQ 绑定」并提示剩余天数,
  「刷新角色状态」不受影响。
- 微博绑定失败原因改为常驻展示(平台原因 + 任务 lastError 去重),
  冷却拒绝不再只弹一个瞬时 toast。
- 后端补留证:微博换绑被平台冷却拒绝时写 `last_error` 并追加
  `weibo_binding_rejected` 事件(channel + 原因),便于客服排障。
- 权威文档补微博第 ⑥ 条:冷却天数只认平台、拒绝需留证、确认后直接引导截图联系客服。
- 测试:新增微博冷却与共用渲染断言(前端 491 全绿),后端补微博留证回归断言(1552 全绿)。
This commit is contained in:
yml
2026-12-02 11:23:33 +08:00
parent 0314955f9b
commit 7d7a996f7d
6 changed files with 278 additions and 96 deletions
@@ -0,0 +1,100 @@
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',
)
/** 取样一段源码,找不到时直接失败,避免测试静默通过。 */
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)
}
const weiboBindingCard = () => pickSlice('{showWeiboBindingStage ? (', '{showBindingStage ? (')
test('换绑冷却天数只来自后端 rebindCooldownDays,不用其它字段推算', () => {
// 页面内冷却天数只有一个来源。
assert.ok(
source.includes('const rebindCooldownDays = Number(bindingInfo?.rebindCooldownDays || 0)'),
)
assert.equal(source.split('rebindCooldownDays =').length - 1, 1)
// 不得从平台规则字段或原始天数推算「从现在起还剩几天」。
assert.ok(!source.includes('rebindRemainDays'))
assert.ok(!source.includes('rebindCooldownDays + '))
assert.ok(!source.includes('rebindCooldownDays - '))
assert.ok(!/(platformChangeBindDay|platformChangeBindTime)[^\n]*rebindCooldownDays/.test(source))
assert.ok(!/rebindCooldownDays[^\n]*(platformChangeBindDay|platformChangeBindTime)/.test(source))
})
test('冷却天数 > 0 且已有绑定角色时微信/QQ 按钮 disabled,刷新角色状态仍可用', () => {
const cooldown = pickSlice('const weiboBoundRoleName', 'const isRebindBlocked')
// 判断条件 = 后端天数 > 0 且已经有绑定角色,天数本身直接来自 rebindCooldownDays。
assert.ok(cooldown.includes('bindingInfo?.bindGameRole || selectedTask?.bindGameRole'))
assert.ok(
cooldown.includes(
'const weiboRebindCooldownBlocked = rebindCooldownDays > 0 && Boolean(weiboBoundRoleName)',
),
)
// 文案:剩余约 N 天 + 冷却结束后才能换绑,N 只来自 rebindCooldownDays。
assert.ok(
cooldown.includes(
'当前角色仍在换绑冷却期,剩余约 ${rebindCooldownDays} 天,冷却结束后才能换绑',
),
)
const card = weiboBindingCard()
// 微信绑定 / QQ 绑定两个按钮都受冷却门禁约束。
assert.equal(
card.split('disabled={bindingSessionExpired || weiboRebindCooldownBlocked}').length - 1,
2,
)
const wxStart = card.indexOf('微信绑定')
const qqStart = card.indexOf('QQ 绑定')
assert.ok(wxStart > 0 && qqStart > wxStart)
// 冷却提示必须在两个绑定按钮之前(按钮上方)。
const cooldownNotice = card.indexOf('weiboRebindCooldownText ? (')
assert.ok(cooldownNotice > 0)
assert.ok(cooldownNotice < card.indexOf("handleStartWeiboBinding('wx')"))
// 「刷新角色状态」始终可用:只受登录会话影响,不受冷却影响。
const refreshStart = card.lastIndexOf('刷新角色状态')
assert.ok(refreshStart > 0)
const refreshButton = card.slice(card.lastIndexOf('<Button', refreshStart), refreshStart)
assert.ok(refreshButton.includes('disabled={bindingSessionExpired}'))
assert.ok(!refreshButton.includes('weiboRebindCooldownBlocked'))
assert.ok(refreshButton.includes('onClick={() => void handlePollBindingNow()}'))
})
test('微博绑定失败原因同时展示平台原因与任务 lastError,且同一句不重复', () => {
// 任务 lastError 与平台原因统一由去重收集器完成。
const collected = pickSlice(
'const bindingFailureReasons = collectBindingFailureReasons([',
'const weiboBindingFailureReasons',
)
assert.ok(collected.includes('bindingInfo?.bindConfirmMessage'))
assert.ok(collected.includes('bindingDecision?.message'))
assert.ok(collected.includes('selectedTask?.lastError'))
// 微信/QQ 绑定抛错(如冷却拒绝)写进 bindingLoadError,和平台原因共用同一个展示位。
const weiboReasons = pickSlice('const weiboBindingFailureReasons', 'const bindingRequiresSupport')
assert.ok(weiboReasons.includes('...bindingFailureReasons'))
assert.ok(weiboReasons.includes('bindingLoadError'))
const card = weiboBindingCard()
assert.ok(card.includes('weiboBindingFailureReasons.length'))
assert.ok(card.includes('weiboBindingFailureReasons.map((reason) => ('))
// 不再用单条瞬时提示代替失败原因展示。
assert.ok(!card.includes('message={bindingLoadError}'))
assert.ok(!card.includes('description={bindingInfo?.message}'))
// 去重逻辑只有一份(页面与微博区共用同一函数)。
assert.equal(source.split('const seen = new Set<string>()').length - 1, 1)
assert.ok(source.includes('function collectBindingFailureReasons('))
})