重构(半自动履约): 收敛状态同步并拆分任务服务
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
* npx tsx --test src/services/semi-auto/semi-auto-task.integration.test.ts
|
||||
*/
|
||||
import assert from 'node:assert/strict'
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import test from 'node:test'
|
||||
|
||||
const TEST_DATABASE_URL = String(process.env.SEMI_AUTO_TASK_TEST_DATABASE_URL || '').trim()
|
||||
@@ -24,6 +25,7 @@ test(
|
||||
process.env.DATABASE_URL = TEST_DATABASE_URL
|
||||
const { closeDb, query, withTransaction } = await import('../../db/client.js')
|
||||
const {
|
||||
applySemiAutoTaskStateSnapshot,
|
||||
confirmPublicBinding,
|
||||
ensureSemiAutoTasksForOrder,
|
||||
exportAdminSemiAutoCredential,
|
||||
@@ -268,6 +270,23 @@ test(
|
||||
)
|
||||
assert.equal(resetEvents.rows[0]?.detail_json?.reason, 'customer_profile_edit')
|
||||
|
||||
// 已确认绑定后的重新授权必须完整退出已授权状态,不能只清登录状态。
|
||||
await query(
|
||||
`
|
||||
UPDATE semi_auto_tasks
|
||||
SET binding_status = 'confirmed',
|
||||
bind_game_account = '集成测试虎牙账号',
|
||||
bind_game_role = '集成测试角色',
|
||||
bind_game_role_id = '1192083858',
|
||||
bind_game_channel = '安卓(iOS) · QQ',
|
||||
binding_started_at = NOW(),
|
||||
bound_at = NOW(),
|
||||
execution_status = 'waiting_operator',
|
||||
updated_at = NOW()
|
||||
WHERE id = $1
|
||||
`,
|
||||
[taskId],
|
||||
)
|
||||
const reauthorized = await requestAdminSemiAutoCustomerReauth(taskId, {
|
||||
userId: 1,
|
||||
role: 'support',
|
||||
@@ -277,6 +296,11 @@ test(
|
||||
assert.equal(reauthorized.task.bindingStatus, 'not_started')
|
||||
assert.equal(reauthorized.task.executionStatus, 'waiting_customer')
|
||||
assert.equal(reauthorized.task.customerLinkOpenedAt, null)
|
||||
assert.equal(reauthorized.task.bindGameAccount, '')
|
||||
assert.equal(reauthorized.task.bindGameRole, '')
|
||||
assert.equal(reauthorized.task.bindGameRoleId, '')
|
||||
assert.equal(reauthorized.task.bindGameChannel, '')
|
||||
assert.equal(reauthorized.task.boundAt, null)
|
||||
const retainedCredential = await query<{ credential_id: number }>(
|
||||
'SELECT credential_id FROM semi_auto_tasks WHERE id = $1',
|
||||
[taskId],
|
||||
@@ -285,6 +309,49 @@ test(
|
||||
assert.ok(
|
||||
reauthorized.events.some((event) => event.eventType === 'customer_reauth_requested'),
|
||||
)
|
||||
|
||||
const snapshotEventId = randomUUID()
|
||||
const snapshot = await applySemiAutoTaskStateSnapshot(
|
||||
{
|
||||
eventId: snapshotEventId,
|
||||
taskId,
|
||||
orderNo,
|
||||
loginStatus: 'authenticated',
|
||||
bindingStatus: 'confirmed',
|
||||
huyaUid: `it-huya-${suffix}`,
|
||||
bindGameAccount: '集成测试虎牙账号',
|
||||
bindGameRole: '集成测试角色',
|
||||
bindGameRoleId: '1192083858',
|
||||
bindGameChannel: '安卓(android) · QQ',
|
||||
},
|
||||
{ eventId: snapshotEventId, eventType: 'semi_auto.task_state' },
|
||||
)
|
||||
assert.equal(snapshot.applied, true)
|
||||
const duplicateSnapshot = await applySemiAutoTaskStateSnapshot(
|
||||
{
|
||||
eventId: snapshotEventId,
|
||||
taskId,
|
||||
orderNo,
|
||||
loginStatus: 'authenticated',
|
||||
bindingStatus: 'confirmed',
|
||||
},
|
||||
{ eventId: snapshotEventId, eventType: 'semi_auto.task_state' },
|
||||
)
|
||||
assert.equal(duplicateSnapshot.applied, false)
|
||||
const synced = await query<{
|
||||
login_status: string
|
||||
binding_status: string
|
||||
execution_status: string
|
||||
}>(
|
||||
`SELECT login_status, binding_status, execution_status
|
||||
FROM semi_auto_tasks WHERE id = $1`,
|
||||
[taskId],
|
||||
)
|
||||
assert.deepEqual(synced.rows[0], {
|
||||
login_status: 'authenticated',
|
||||
binding_status: 'confirmed',
|
||||
execution_status: 'waiting_operator',
|
||||
})
|
||||
} finally {
|
||||
if (orderId > 0) {
|
||||
await query('DELETE FROM order_source_snapshots WHERE order_id = $1', [orderId])
|
||||
|
||||
Reference in New Issue
Block a user