完善半自动真实履约链路及虎牙账号资料保存

This commit is contained in:
yml
2026-11-14 09:23:37 +08:00
parent 3ea5dd5ce4
commit 81a7721ee1
13 changed files with 662 additions and 31 deletions
@@ -14,7 +14,7 @@ test(
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
async () => {
process.env.DATABASE_URL = TEST_DATABASE_URL
const { closeDb, query } = await import('../../db/client.js')
const { closeDb, query, withTransaction } = await import('../../db/client.js')
const {
ensureSemiAutoTasksForOrder,
exportAdminSemiAutoCredential,
@@ -164,7 +164,10 @@ test(
reauthorized.events.some((event) => event.eventType === 'customer_reauth_requested'),
)
} finally {
if (orderId > 0) await query('DELETE FROM orders WHERE id = $1', [orderId])
if (orderId > 0) {
await query('DELETE FROM order_source_snapshots WHERE order_id = $1', [orderId])
await query('DELETE FROM orders WHERE id = $1', [orderId])
}
if (credentialId > 0) {
await query('DELETE FROM semi_auto_credentials WHERE id = $1', [credentialId])
}
@@ -644,14 +647,19 @@ test(
assert.equal(tasks[0]?.loginStatus, 'authenticated')
assert.equal(tasks[0]?.executionStatus, 'waiting_operator')
assert.equal(tasks[0]?.credentialSource, 'sms')
assert.ok(tasks[0]?.huyaUid)
assert.equal(tasks[0]?.platformNickname, 'Mock虎牙用户')
const stored = await query<{
id: number
credential_source: string
credential_payload_json: string
platform_nickname: string
huya_uid: string
}>(
`SELECT credential.id, credential.credential_source,
credential.credential_payload_json
credential.credential_payload_json,
task.platform_nickname, task.huya_uid
FROM semi_auto_tasks task
JOIN semi_auto_credentials credential ON credential.id = task.credential_id
WHERE task.id = $1`,
@@ -661,6 +669,8 @@ test(
assert.ok(credentialId > 0)
assert.equal(stored.rows[0]?.credential_source, 'sms')
assert.match(stored.rows[0]?.credential_payload_json || '', /mock_huya_session/)
assert.equal(stored.rows[0]?.platform_nickname, 'Mock虎牙用户')
assert.equal(stored.rows[0]?.huya_uid, tasks[0]?.huyaUid)
} finally {
if (orderId > 0) await query('DELETE FROM orders WHERE id = $1', [orderId])
if (configId > 0) {
@@ -675,3 +685,84 @@ test(
}
},
)
test(
'真实订单入口可生成 manual 履约和半自动任务',
{ 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 suffix = `${Date.now()}_${Math.floor(Math.random() * 1_000_000)}`
const orderNo = `IT-INTEGRATION-SA-${suffix}`
let orderId = 0
let configId = 0
let mappingId = 0
try {
const result = await createSemiAutoIntegrationMock({
platform: 'huya',
orderNo,
skuName: `真实链路虎牙测试-${suffix}`,
quantity: 1,
connectorMode: 'embedded',
})
orderId = result.orderId
configId = result.configId
mappingId = result.mappingId
assert.equal(result.pipeline, 'order_service')
assert.equal(result.orderNo, orderNo)
assert.ok(result.orderItemId > 0)
assert.ok(result.fulfillmentId > 0)
assert.ok(result.taskId > 0)
const stored = await query<{
channel: string
fulfillment_status: string
login_status: string
execution_status: string
config_id: number
}>(
`
SELECT
f.channel,
f.status AS fulfillment_status,
task.login_status,
task.execution_status,
task.manual_fulfillment_config_id AS config_id
FROM semi_auto_tasks task
JOIN fulfillments f ON f.id = task.fulfillment_id
WHERE task.id = $1
`,
[result.taskId],
)
assert.equal(stored.rows[0]?.channel, 'manual')
assert.equal(stored.rows[0]?.fulfillment_status, 'assigned')
assert.equal(stored.rows[0]?.login_status, 'waiting_login')
assert.equal(stored.rows[0]?.execution_status, 'waiting_customer')
assert.equal(Number(stored.rows[0]?.config_id), result.configId)
const mapping = await query<{ internal_sku: string }>(
'SELECT internal_sku FROM internal_sku_mappings WHERE id = $1',
[result.mappingId],
)
assert.equal(mapping.rows[0]?.internal_sku, result.skuKey)
} 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()
}
},
)