60 lines
2.4 KiB
TypeScript
60 lines
2.4 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')
|
|
|
|
// D11 验收:上家 CRUD(Mock 契约,对齐后端 ChannelUpstream 实体)
|
|
describe('上家 API(D11 Mock 契约)', () => {
|
|
beforeEach(() => {
|
|
localStorage.clear()
|
|
})
|
|
|
|
it('列表:默认 3 条(含分类/联系人)', async () => {
|
|
const page = await channelApi.upstreamList({ page: 1, page_size: 10 })
|
|
expect(page.total).toBeGreaterThanOrEqual(3)
|
|
expect(page.list[0].contact).toBeTruthy()
|
|
expect(['运营商直连', '第三方通道']).toContain(page.list[0].category)
|
|
})
|
|
|
|
it('列表:name 过滤命中', async () => {
|
|
const page = await channelApi.upstreamList({ page: 1, page_size: 10, name: '联信' })
|
|
expect(page.list.length).toBe(1)
|
|
expect(page.list[0].name).toBe('联信第三方')
|
|
})
|
|
|
|
it('创建:必填缺失/电话格式不合法拒绝', async () => {
|
|
await expect(
|
|
channelApi.upstreamCreate({ name: '', contact: '张三', phone: '13800001111' }),
|
|
).rejects.toMatchObject({ code: 'ISC:400' })
|
|
await expect(
|
|
channelApi.upstreamCreate({ name: '新上家', contact: '张三', phone: '123' }),
|
|
).rejects.toMatchObject({ code: 'ISC:400' })
|
|
})
|
|
|
|
it('CRUD 闭环:创建 → 列表可见 → 更新 → 删除后消失', async () => {
|
|
const created = await channelApi.upstreamCreate({
|
|
name: 'D11验收上家', contact: '李四', phone: '13912345678', category: '第三方通道', remark: 'D11',
|
|
})
|
|
expect(created.id).toBeGreaterThan(99)
|
|
|
|
let page = await channelApi.upstreamList({ page: 1, page_size: 50, name: 'D11验收' })
|
|
expect(page.total).toBe(1)
|
|
|
|
const updated = await channelApi.upstreamUpdate(created.id, { contact: '李四改' })
|
|
expect(updated.contact).toBe('李四改')
|
|
|
|
page = await channelApi.upstreamList({ page: 1, page_size: 50, name: 'D11验收' })
|
|
expect(page.list[0].contact).toBe('李四改')
|
|
|
|
await channelApi.upstreamRemove(created.id)
|
|
page = await channelApi.upstreamList({ page: 1, page_size: 50, name: 'D11验收' })
|
|
expect(page.total).toBe(0)
|
|
})
|
|
|
|
it('更新/删除不存在 → ISC:404', async () => {
|
|
await expect(channelApi.upstreamUpdate(99999, { name: 'x' })).rejects.toMatchObject({ code: 'ISC:404' })
|
|
await expect(channelApi.upstreamRemove(99999)).rejects.toMatchObject({ code: 'ISC:404' })
|
|
})
|
|
})
|