优化
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { http } from '@/shared/api/http'
|
||||
import { getPlatformInbound, listPlatformInbounds } from './api'
|
||||
import { downloadInboundCartonLabels, getPlatformInbound, listPlatformInbounds } from './api'
|
||||
|
||||
vi.mock('@/shared/api/http', () => ({
|
||||
http: { get: vi.fn() },
|
||||
ApiResponseError: class ApiResponseError extends Error {
|
||||
code: string
|
||||
constructor(message: string, code: string) { super(message); this.code = code }
|
||||
},
|
||||
http: { get: vi.fn(), post: vi.fn() },
|
||||
unwrapApiResponse: <T>(response: { data: T }) => response.data,
|
||||
}))
|
||||
|
||||
describe('platform inbound query API', () => {
|
||||
beforeEach(() => vi.mocked(http.get).mockReset())
|
||||
beforeEach(() => {
|
||||
vi.mocked(http.get).mockReset()
|
||||
vi.mocked(http.post).mockReset()
|
||||
})
|
||||
|
||||
it('omits the backend tenant filter for an all-customer list query', async () => {
|
||||
vi.mocked(http.get).mockResolvedValue({
|
||||
@@ -83,4 +90,22 @@ describe('platform inbound query API', () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('downloads stable carton labels and rejects JSON business errors', async () => {
|
||||
const pdf = new Blob(['pdf'], { type: 'application/pdf' })
|
||||
vi.mocked(http.post).mockResolvedValueOnce(pdf)
|
||||
|
||||
await expect(downloadInboundCartonLabels('10001', '19001', [1, 3])).resolves.toBe(pdf)
|
||||
expect(http.post).toHaveBeenCalledWith('/platform/inbounds/19001/carton-label-pdf', null, {
|
||||
params: { tenantId: '10001', cartonIndex: [1, 3] }, responseType: 'blob', timeout: 60_000,
|
||||
})
|
||||
|
||||
vi.mocked(http.post).mockResolvedValueOnce({
|
||||
type: 'application/json',
|
||||
text: async () => JSON.stringify({ code: 'A0422', message: '箱号映射不完整' }),
|
||||
} as Blob)
|
||||
await expect(downloadInboundCartonLabels('10001', '19001')).rejects.toMatchObject({
|
||||
message: '箱号映射不完整', code: 'A0422',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user