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']")) const pipelineRealtimeBlock = layout.slice( layout.indexOf("event.type === 'fulfillment_pipeline.changed'"), layout.indexOf("event.type === 'work_order.changed'"), ) assert.ok(!pipelineRealtimeBlock.includes("queryKey: ['fulfillment-pending']")) assert.ok(page.includes('loading={query.isLoading}')) }) 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'")) })