feat(半自动履约): 补齐微博游戏角色绑定流程

This commit is contained in:
yml
2026-11-18 15:45:13 +08:00
parent f76b9c452d
commit 623a4ffa05
21 changed files with 1366 additions and 156 deletions
@@ -748,6 +748,104 @@ test(
},
)
test(
'微博平台角色绑定事实收敛为等待客服处理',
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
async () => {
process.env.DATABASE_URL = TEST_DATABASE_URL
process.env.ENABLE_DEV_MOCK = '1'
const { closeDb, query, withTransaction } = await import('../../db/client.js')
const { createSemiAutoIntegrationMock } = await import('../dev-mock/dev-mock-service.js')
const { loadTask, updateBindingTask } = await import('./semi-auto-task-core.js')
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1_000_000)}`
const orderNo = `IT-WEIBO-BINDING-${suffix}`
let orderId = 0
let configId = 0
let mappingId = 0
try {
const result = await createSemiAutoIntegrationMock({
platform: 'weibo',
orderNo,
skuName: `微博绑定真实链路-${suffix}`,
quantity: 1,
connectorMode: 'embedded',
})
orderId = result.orderId
configId = result.configId
mappingId = result.mappingId
assert.equal(result.semiAutoPlatform, 'weibo')
assert.ok(result.taskId > 0)
await query(
`
UPDATE semi_auto_tasks
SET connector_session_id = $2,
login_status = 'authenticated',
execution_status = 'waiting_customer',
authenticated_at = NOW(),
updated_at = NOW()
WHERE id = $1
`,
[result.taskId, `it-weibo-session-${suffix}`],
)
const task = await loadTask(result.taskId)
const binding = await updateBindingTask(
task,
{
sessionId: `it-weibo-session-${suffix}`,
status: 'confirmed',
qrImage: '',
qrExpiresAt: '',
qrUrl: '',
bindGameAccount: '集成测试微博',
bindGameRole: '微博游戏角色',
bindGameRoleId: '',
bindGameChannel: '微信',
hasExistingBinding: true,
rebindRequested: false,
rebindCooldownDays: 0,
nextRebindAt: '',
message: '微博账号已绑定角色',
},
'connector',
)
assert.equal(binding.status, 'confirmed')
assert.equal(binding.comparison.verdict, 'match')
const stored = await query<{
binding_status: string
execution_status: string
bind_game_role: string
bind_game_channel: string
}>(
`SELECT binding_status, execution_status, bind_game_role, bind_game_channel
FROM semi_auto_tasks WHERE id = $1`,
[result.taskId],
)
assert.equal(stored.rows[0]?.binding_status, 'confirmed')
assert.equal(stored.rows[0]?.execution_status, 'waiting_operator')
assert.equal(stored.rows[0]?.bind_game_role, '微博游戏角色')
assert.equal(stored.rows[0]?.bind_game_channel, '微信')
} finally {
await withTransaction(async (client) => {
await client.query("SET LOCAL session_replication_role = 'replica'")
if (configId > 0) {
await client.query('DELETE FROM manual_fulfillment_configs WHERE id = $1', [configId])
}
if (orderId > 0) {
await client.query('DELETE FROM order_source_snapshots WHERE order_id = $1', [orderId])
await client.query('DELETE FROM orders WHERE id = $1', [orderId])
}
if (mappingId > 0) {
await client.query('DELETE FROM internal_sku_mappings WHERE id = $1', [mappingId])
}
})
delete process.env.ENABLE_DEV_MOCK
await closeDb()
}
},
)
test(
'开发 Mock 可显式选择内置 Mock Connector',
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },