This commit is contained in:
2026-09-29 17:56:00 +08:00
parent 4ead51a5fe
commit 2bf4353b1b
46 changed files with 481 additions and 638 deletions
@@ -1,32 +1,32 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { listSharedReceivingOverseasWarehouseOptions } from '@/modules/iam'
import { overseasHttp } from '@/shared/api/overseasHttp'
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/overseasHttp', () => ({ overseasHttp: { get: vi.fn(), post: vi.fn(), put: 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(overseasHttp.get).mockResolvedValueOnce(pdf)
vi.mocked(http.get).mockResolvedValueOnce(pdf)
await expect(getPalletLabelPdf('200', '9007199254740993')).resolves.toBe(pdf)
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/warehouse-admin/200/pallets/9007199254740993/label', { responseType: 'blob', timeout: 60_000 })
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(overseasHttp.get).mockResolvedValueOnce(error)
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(overseasHttp.get).mockResolvedValue({ code: '200', data: page })
vi.mocked(overseasHttp.post).mockResolvedValue({ code: '200', data: '9' })
vi.mocked(overseasHttp.put).mockResolvedValue({ code: '200', data: null })
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' }
@@ -37,11 +37,11 @@ describe('overseas pallet API', () => {
await updatePallet('200', '9', { ...payload, version: 7 })
expect(listSharedReceivingOverseasWarehouseOptions).toHaveBeenCalledOnce()
expect(overseasHttp.get).toHaveBeenNthCalledWith(1, '/platform/v1/warehouse-admin/200/pallets', { params: { page: 1, size: 20, keyword: 'PLT' } })
expect(overseasHttp.get).toHaveBeenNthCalledWith(2, '/platform/v1/warehouse-admin/200/pallets/9', {})
expect(overseasHttp.post).toHaveBeenCalledWith('/platform/v1/warehouse-admin/200/pallets', payload)
expect(overseasHttp.put).toHaveBeenCalledWith('/platform/v1/warehouse-admin/200/pallets/9', { ...payload, version: 7 })
expect(overseasHttp.put).toHaveBeenCalledWith('/platform/v1/warehouse-admin/200/pallets/9', expect.objectContaining({ palletCode: 'PLT-NEW', fbaWarehouseCode: 'ABE3', status: 'IDLE', version: 7 }))
expect(overseasHttp.post).toHaveBeenCalledWith('/platform/v1/warehouse-admin/200/pallets', expect.not.objectContaining({ version: expect.anything() }))
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() }))
})
})