48 lines
3.5 KiB
TypeScript
48 lines
3.5 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { listSharedReceivingOverseasWarehouseOptions } from '@/modules/iam'
|
|
import { http } from '@/shared/api/http'
|
|
import { createPallet, getPallet, getPalletLabelPdf, listPallets, listReceivingOverseasWarehouses, updatePallet } from './pallets'
|
|
|
|
vi.mock('@/modules/iam', () => ({ listSharedReceivingOverseasWarehouseOptions: vi.fn() }))
|
|
vi.mock('@/shared/api/http', async (importOriginal) => ({ ...(await importOriginal<typeof import('@/shared/api/http')>()), http: { get: vi.fn(), post: vi.fn(), put: vi.fn() } }))
|
|
|
|
describe('overseas pallet API', () => {
|
|
beforeEach(() => { vi.clearAllMocks() })
|
|
|
|
it('downloads only the selected pallet through the overseas gateway', async () => {
|
|
const pdf = new Blob(['%PDF-label'], { type: 'application/pdf' })
|
|
vi.mocked(http.get).mockResolvedValueOnce(pdf)
|
|
await expect(getPalletLabelPdf('200', '9007199254740993')).resolves.toBe(pdf)
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/overseas-warehouse-resources/200/pallets/9007199254740993/label', { responseType: 'blob', timeout: 60_000 })
|
|
})
|
|
|
|
it('surfaces a JSON business failure instead of saving it as a PDF', async () => {
|
|
const error = new Blob([JSON.stringify({ code: 'A0422', message: '托盘编码不支持打印', requestId: 'r1' })], { type: 'application/json' })
|
|
vi.mocked(http.get).mockResolvedValueOnce(error)
|
|
await expect(getPalletLabelPdf('200', '9')).rejects.toMatchObject({ message: '托盘编码不支持打印', code: 'A0422', requestId: 'r1' })
|
|
})
|
|
|
|
it('uses the public warehouse scoped pallet CRUD contract', async () => {
|
|
const page = { records: [], page: 1, size: 20, total: 0, pages: 0 }
|
|
vi.mocked(http.get).mockResolvedValue({ code: '200', data: page })
|
|
vi.mocked(http.post).mockResolvedValue({ code: '200', data: '9' })
|
|
vi.mocked(http.put).mockResolvedValue({ code: '200', data: null })
|
|
vi.mocked(listSharedReceivingOverseasWarehouseOptions).mockResolvedValue([{ id: '200', warehouseCode: 'LAX', warehouseName: '洛杉矶仓', countryCode: 'US' }])
|
|
const payload = { palletCode: 'PLT-NEW', palletType: 'WOOD', fbaWarehouseCode: 'ABE3', capacityCbm: 2, unitPrice: 10, status: 'IDLE' }
|
|
|
|
await expect(listReceivingOverseasWarehouses()).resolves.toMatchObject({ records: [{ id: '200', customerId: '0', warehouseCode: 'LAX', warehouseType: 'OVERSEAS', status: 'ACTIVE' }] })
|
|
await listPallets('200', { page: 1, size: 20, keyword: 'PLT' })
|
|
await getPallet('200', '9')
|
|
await createPallet('200', payload)
|
|
await updatePallet('200', '9', { ...payload, version: 7 })
|
|
|
|
expect(listSharedReceivingOverseasWarehouseOptions).toHaveBeenCalledOnce()
|
|
expect(http.get).toHaveBeenNthCalledWith(1, '/platform/v1/overseas-warehouse-resources/200/pallets', { params: { page: 1, size: 20, keyword: 'PLT' } })
|
|
expect(http.get).toHaveBeenNthCalledWith(2, '/platform/v1/overseas-warehouse-resources/200/pallets/9', {})
|
|
expect(http.post).toHaveBeenCalledWith('/platform/v1/overseas-warehouse-resources/200/pallets', payload)
|
|
expect(http.put).toHaveBeenCalledWith('/platform/v1/overseas-warehouse-resources/200/pallets/9', { ...payload, version: 7 })
|
|
expect(http.put).toHaveBeenCalledWith('/platform/v1/overseas-warehouse-resources/200/pallets/9', expect.objectContaining({ palletCode: 'PLT-NEW', fbaWarehouseCode: 'ABE3', status: 'IDLE', version: 7 }))
|
|
expect(http.post).toHaveBeenCalledWith('/platform/v1/overseas-warehouse-resources/200/pallets', expect.not.objectContaining({ version: expect.anything() }))
|
|
})
|
|
})
|