Files
go-sms-V2/web/tests/channel-receipts.spec.ts

45 lines
1.9 KiB
TypeScript

import { vi } from "vitest"
import { beforeEach, describe, expect, it } from 'vitest'
import { channelApi } from '@/api/channel'
vi.stubEnv('VITE_API_BASE_URL', 'http://localhost/api/v1')
// Day 39 验收:链路状态/回执复核(Mock 契约;真实语义见后端 channel_day39_test.go)
describe('链路与回执复核(Day 39 Mock 契约)', () => {
beforeEach(() => {
localStorage.clear()
})
it('link-status:启用 cmpp 运行中 / http 与停用未建链 / 404', async () => {
// 通道1(移动全国,cmpp 启用, conn_count=4) → 运行中
const st = await channelApi.linkStatus(1)
expect(st.running).toBe(true)
expect(st.total).toBe(4)
expect(st.healthy).toBe(4)
expect(st.started_at).toBeTruthy()
// 通道2(http) / 通道3(sgip 停用) → 未建链
const http = await channelApi.linkStatus(2)
expect(http.running).toBe(false)
const off = await channelApi.linkStatus(3)
expect(off.running).toBe(false)
// 不存在 → ISC:404
await expect(channelApi.linkStatus(999)).rejects.toMatchObject({ code: 'ISC:404' })
})
it('receipts:状态报告(DELIVRD/UNDELIV)与上行共存,倒序时间', async () => {
const r = await channelApi.linkReceipts(1, 50)
expect(r.channel_id).toBe(1)
expect(r.total).toBeGreaterThanOrEqual(3)
// 至少一条 DELIVRD 报告与一条上行
expect(r.list.some((x) => x.is_report && x.stat === 'DELIVRD')).toBe(true)
expect(r.list.some((x) => !x.is_report && x.src && x.content)).toBe(true)
// 报告带 dest/时间,时间倒序(非严格,允许同分钟)
const rep = r.list.find((x) => x.is_report)!
expect(rep.dest).toBeTruthy()
for (let i = 1; i < r.list.length; i++) {
expect(r.list[i - 1].at >= r.list[i].at).toBe(true)
}
// 不存在通道 404
await expect(channelApi.linkReceipts(999)).rejects.toMatchObject({ code: 'ISC:404' })
})
})