89 lines
3.9 KiB
TypeScript
89 lines
3.9 KiB
TypeScript
// record-uplink.spec.ts Day 56(D27):上行记录契约用例(msw fe4UplinkHandlers)
|
||
// +权限导出显隐(v-permission 语义在页面 v-if canExport 的等价单测)。
|
||
// 锁定:码号前缀/手机号尾号模糊/匹配态筛选/15 天窗口外未匹配种子/
|
||
// 导出任务提交反馈(scope 快照含上行条件)。
|
||
import { mount } from '@vue/test-utils'
|
||
import { createPinia, setActivePinia } from 'pinia'
|
||
import { defineComponent } from 'vue'
|
||
import { beforeEach, describe, expect, it } from 'vitest'
|
||
import { createUplinkExport, fetchUplinkRecords } from '../src/api/record'
|
||
import { exportDB, uplinkDB } from '../mocks/fe4-handlers'
|
||
import { permission } from '../src/directives/permission'
|
||
import { useUserStore } from '../src/stores/user'
|
||
|
||
describe('D27 上行记录(Mock 契约,对齐 Day60 record API)', () => {
|
||
it('列表:倒序分页,种子含已匹配/未匹配/窗口外三态', async () => {
|
||
const page = await fetchUplinkRecords({ page: 1, page_size: 100 })
|
||
expect(page.total).toBe(uplinkDB.length)
|
||
expect(page.list.length).toBe(uplinkDB.length)
|
||
// 时间倒序
|
||
for (let i = 1; i < page.list.length; i++) {
|
||
expect(page.list[i - 1].recv_at >= page.list[i].recv_at).toBe(true)
|
||
}
|
||
const matched = page.list.filter((r) => r.match_task_id > 0).length
|
||
const unmatched = page.list.length - matched
|
||
expect(matched).toBeGreaterThan(0)
|
||
expect(unmatched).toBeGreaterThan(0)
|
||
})
|
||
|
||
it('码号前缀筛选:10690331 命中含扩展码号(两级匹配口径)', async () => {
|
||
const page = await fetchUplinkRecords({ page: 1, page_size: 100, dest_code: '10690331' })
|
||
expect(page.total).toBe(3) // 10690331×2 + 10690331001(前缀)
|
||
for (const r of page.list) expect(r.dest_code.startsWith('10690331')).toBe(true)
|
||
})
|
||
|
||
it('手机号尾号模糊+匹配态:未匹配圈出窗口外/无下行记录', async () => {
|
||
const page = await fetchUplinkRecords({ page: 1, page_size: 100, matched: 0 })
|
||
expect(page.total).toBe(2)
|
||
for (const r of page.list) expect(r.match_task_id).toBe(0)
|
||
// 18 天前种子=15 天窗口外(窗口提示语义锚点)
|
||
const outside = page.list.find((r) => r.src_mobile === '13699887766')
|
||
expect(outside).toBeTruthy()
|
||
})
|
||
|
||
it('导出:提交返回任务号,scope 快照含上行条件(下载中心可辨识)', async () => {
|
||
const before = exportDB.length
|
||
const res = await createUplinkExport({ dest_code: '10690331', matched: 1 })
|
||
expect(res.id).toBeGreaterThan(8900)
|
||
expect(exportDB.length).toBe(before + 1)
|
||
expect(exportDB[0].scope).toContain('上行')
|
||
expect(exportDB[0].scope).toContain('码号=10690331')
|
||
expect(exportDB[0].status).toBe('pending')
|
||
})
|
||
})
|
||
|
||
// 权限导出显隐:页面判定=canExport(等价 v-permission 'uplink:export';
|
||
// 实页面用 v-if,此处用指令挂载验证同语义)。
|
||
describe('D27 导出权限(uplink:export)', () => {
|
||
beforeEach(() => {
|
||
setActivePinia(createPinia())
|
||
})
|
||
|
||
function setupUser(roles: string[], permissions: string[]) {
|
||
const s = useUserStore()
|
||
s.user = { account_id: 1, username: 'u', roles, permissions }
|
||
return s
|
||
}
|
||
|
||
const host = defineComponent({
|
||
template: `<div><button v-permission="'uplink:export'" data-q="export">导出</button></div>`,
|
||
})
|
||
|
||
it('admin 直通:导出按钮保留', () => {
|
||
setupUser(['admin'], [])
|
||
const w = mount(host, { global: { directives: { permission } } })
|
||
expect(w.find('[data-q="export"]').exists()).toBe(true)
|
||
})
|
||
|
||
it('customer 无 uplink:export:导出按钮隐藏(D27 验收口径)', () => {
|
||
setupUser(['customer'], ['message:write'])
|
||
const w = mount(host, { global: { directives: { permission } } })
|
||
expect(w.find('[data-q="export"]').exists()).toBe(false)
|
||
})
|
||
|
||
it('ops 授予 uplink:export:导出按钮保留', () => {
|
||
setupUser(['ops'], ['uplink:export'])
|
||
const w = mount(host, { global: { directives: { permission } } })
|
||
expect(w.find('[data-q="export"]').exists()).toBe(true)
|
||
})
|
||
}) |