Files
go-sms-V2/web/tests/record-down.spec.ts

60 lines
2.7 KiB
TypeScript

// record-down.spec.ts Day 53(D24):下行批次记录契约用例(msw fe4-handlers)。
// 锁定:分页 100/页口径/筛选语义/进度五段聚合=mobile_count/拦截下载 CSV。
import { describe, expect, it } from 'vitest'
import { downloadIntercepted, fetchDownRecords, progressOf } from '../src/api/record'
import { downDB } from '../mocks/fe4-handlers'
describe('D24 下行批次记录(Mock 契约,对齐 Day60 record API 计划)', () => {
it('列表分页:默认 100/页,total=种子 12 条', async () => {
const page = await fetchDownRecords({ page: 1, page_size: 100 })
expect(page.total).toBe(downDB.length)
expect(page.list.length).toBe(downDB.length) // 12<100 单页承载
})
it('分页翻页:page_size=5 时第 2 页 5 条,按提交时间倒序', async () => {
const p1 = await fetchDownRecords({ page: 1, page_size: 5 })
const p2 = await fetchDownRecords({ page: 2, page_size: 5 })
expect(p1.list.length).toBe(5)
expect(p2.list.length).toBe(5)
expect(p1.list[0].created_at >= p2.list[0].created_at).toBe(true)
})
it('筛选:任务号精确/发送类型/任务状态组合生效', async () => {
const byNo = await fetchDownRecords({ page: 1, page_size: 100, task_no: 'T20260913103004' })
expect(byNo.total).toBe(1)
expect(byNo.list[0].intercepted_count).toBe(300)
const byType = await fetchDownRecords({ page: 1, page_size: 100, send_type: 3 })
expect(byType.total).toBe(2) // id 5/12
const byStatus = await fetchDownRecords({ page: 1, page_size: 100, status: 1 })
expect(byStatus.total).toBe(1) // id 3 进行中
expect(byStatus.list[0].sending_count).toBeGreaterThan(0)
})
it('进度口径锁定:全量种子 progressOf 五段之和=mobile_count(与后端计数一致验收)', async () => {
const page = await fetchDownRecords({ page: 1, page_size: 100 })
for (const r of page.list) {
const sum = progressOf(r).reduce((acc, s) => acc + s.n, 0)
expect(sum, `任务 ${r.task_no} 五段聚合应等于号码数`).toBe(r.mobile_count)
}
})
it('拦截下载:全拦批次返回 CSV(首行表头+300 数据行)', async () => {
const blob = await downloadIntercepted(4)
const text = await blob.text()
const lines = text.trim().split('\n')
expect(lines[0]).toBe('mobile,error_code,reason')
expect(lines.length).toBe(301)
expect(lines[1]).toContain('ISC:032')
})
it('拦截下载:无拦截批次 404 业务码(BizError)', async () => {
await expect(downloadIntercepted(2)).rejects.toThrow('该批次无拦截号码')
})
it('拦截下载:不存在任务 404', async () => {
await expect(downloadIntercepted(999)).rejects.toThrow('任务不存在')
})
})