优化(直播履约): 改为订单快照事件驱动

This commit is contained in:
yml
2026-11-18 16:57:57 +08:00
parent 623a4ffa05
commit 86c8417d4b
21 changed files with 934 additions and 77 deletions
@@ -0,0 +1,36 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import test from 'node:test'
const root = dirname(fileURLToPath(import.meta.url))
function source(relativePath: string) {
return readFileSync(join(root, '..', relativePath), 'utf8')
}
test('斗鱼领取页使用订单级 SSE,不再固定 3 秒轮询绑定状态', () => {
const page = source('src/pages/douyu-fulfillment/DouyuFulfillmentPage.tsx')
assert.ok(page.includes('useRealtimeEvents'))
assert.ok(page.includes('/realtime'))
assert.ok(page.includes("event.type === 'customer_order.changed'"))
assert.ok(!page.includes('POLL_INTERVAL_MS'))
assert.ok(!page.includes('pollDouyuBinding('))
})
test('履约管道状态由后台 SSE 失效刷新,不再 30 秒轮询', () => {
const page = source('src/pages/admin/AdminFulfillmentChannelPage.tsx')
const layout = source('src/layouts/AdminLayout.tsx')
assert.ok(!page.includes('refetchInterval: 30_000'))
assert.match(page, /SSE\s+自动刷新/)
assert.ok(layout.includes("event.type === 'fulfillment_pipeline.changed'"))
assert.ok(layout.includes("queryKey: ['fulfillment-pipelines']"))
})
test('公共订单 SSE 允许匿名连接且只携带重读信号', () => {
const hook = source('src/hooks/useRealtimeEvents.ts')
assert.ok(hook.includes('allowAnonymous'))
assert.ok(hook.includes("| 'customer_order.changed'"))
assert.ok(hook.includes("| 'fulfillment_pipeline.changed'"))
})