完善虎牙短信登录与图形安全验证
This commit is contained in:
@@ -594,3 +594,84 @@ test(
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
'客户手动触发虎牙短信登录后保存 CK 并进入等待客服',
|
||||
{ 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 } = await import('../../db/client.js')
|
||||
const { createSemiAutoMock } = await import('../dev-mock/dev-mock-service.js')
|
||||
const { resetMockSessions } = await import('../dev-mock/mock-semi-auto-connector.js')
|
||||
const { listPublicSemiAutoTasks, loginPublicHuyaSms, sendPublicHuyaSmsCode } =
|
||||
await import('./semi-auto-task-service.js')
|
||||
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1_000_000)}`
|
||||
const orderNo = `IT-HUYA-SMS-${suffix}`
|
||||
let orderId = 0
|
||||
let configId = 0
|
||||
let credentialId = 0
|
||||
try {
|
||||
const result = await createSemiAutoMock({
|
||||
orderNo,
|
||||
skuName: `虎牙短信登录-${suffix}`,
|
||||
quantity: 1,
|
||||
connectorMode: 'mock',
|
||||
})
|
||||
orderId = result.orderId
|
||||
configId = result.configId
|
||||
|
||||
const sent = await sendPublicHuyaSmsCode(orderNo, result.taskId, '13800138000')
|
||||
assert.equal(sent.ok, true)
|
||||
const waiting = await query<{
|
||||
connector_session_id: string
|
||||
login_status: string
|
||||
execution_status: string
|
||||
}>(
|
||||
`SELECT connector_session_id, login_status, execution_status
|
||||
FROM semi_auto_tasks WHERE id = $1`,
|
||||
[result.taskId],
|
||||
)
|
||||
assert.ok(waiting.rows[0]?.connector_session_id)
|
||||
assert.equal(waiting.rows[0]?.login_status, 'waiting_login')
|
||||
assert.equal(waiting.rows[0]?.execution_status, 'waiting_customer')
|
||||
|
||||
await loginPublicHuyaSms(orderNo, result.taskId, {
|
||||
mobile: '13800138000',
|
||||
code: '123456',
|
||||
})
|
||||
const tasks = await listPublicSemiAutoTasks(orderNo)
|
||||
assert.equal(tasks[0]?.loginStatus, 'authenticated')
|
||||
assert.equal(tasks[0]?.executionStatus, 'waiting_operator')
|
||||
assert.equal(tasks[0]?.credentialSource, 'sms')
|
||||
|
||||
const stored = await query<{
|
||||
id: number
|
||||
credential_source: string
|
||||
credential_payload_json: string
|
||||
}>(
|
||||
`SELECT credential.id, credential.credential_source,
|
||||
credential.credential_payload_json
|
||||
FROM semi_auto_tasks task
|
||||
JOIN semi_auto_credentials credential ON credential.id = task.credential_id
|
||||
WHERE task.id = $1`,
|
||||
[result.taskId],
|
||||
)
|
||||
credentialId = Number(stored.rows[0]?.id || 0)
|
||||
assert.ok(credentialId > 0)
|
||||
assert.equal(stored.rows[0]?.credential_source, 'sms')
|
||||
assert.match(stored.rows[0]?.credential_payload_json || '', /mock_huya_session/)
|
||||
} finally {
|
||||
if (orderId > 0) await query('DELETE FROM orders WHERE id = $1', [orderId])
|
||||
if (configId > 0) {
|
||||
await query('DELETE FROM manual_fulfillment_configs WHERE id = $1', [configId])
|
||||
}
|
||||
if (credentialId > 0) {
|
||||
await query('DELETE FROM semi_auto_credentials WHERE id = $1', [credentialId])
|
||||
}
|
||||
resetMockSessions()
|
||||
delete process.env.ENABLE_DEV_MOCK
|
||||
await closeDb()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user