feat(fulfillment): 增加斗鱼工作台双向自动同步

This commit is contained in:
yml
2026-11-18 11:00:28 +08:00
parent 4da670ce14
commit b48509c34f
7 changed files with 355 additions and 60 deletions
+46
View File
@@ -38,3 +38,49 @@ test('HTTP health route and explicit CORS preflight', async () => {
await once(server, 'close')
}
})
test('履约状态集成接口要求密钥并接受空快照', async () => {
const previousKey = process.env.PLATFORM_FULFILLMENT_INTEGRATION_KEY
process.env.PLATFORM_FULFILLMENT_INTEGRATION_KEY = 'integration-test-key'
const startupState = createStartupState()
startupState.core.ready = true
const config = createDefaultRuntimeConfig('/tmp/order-site')
const server = createApp({
startupState,
isShutdownStarted: () => false,
config,
}).listen(0, '127.0.0.1')
await once(server, 'listening')
try {
const address = server.address()
assert.ok(address && typeof address === 'object')
const endpoint = `http://127.0.0.1:${address.port}/api/integration/platform-fulfillment/binding-state`
const unauthorized = await fetch(endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ items: [] }),
})
assert.equal(unauthorized.status, 401)
const accepted = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Integration-Key': 'integration-test-key',
},
body: JSON.stringify({ items: [] }),
})
assert.equal(accepted.status, 200)
assert.deepEqual((await accepted.json()).data, { received: 0, updated: 0 })
} finally {
if (previousKey === undefined) {
delete process.env.PLATFORM_FULFILLMENT_INTEGRATION_KEY
} else {
process.env.PLATFORM_FULFILLMENT_INTEGRATION_KEY = previousKey
}
server.close()
await once(server, 'close')
}
})