This commit is contained in:
2026-09-15 14:18:23 +08:00
parent fb41713930
commit a311ec41c3
13 changed files with 88 additions and 31 deletions
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { listSharedReceivingOverseasWarehouseOptions } from '@/modules/iam'
import { overseasHttp } from '@/shared/api/overseasHttp'
import { createPallet, getPallet, listPallets, listReceivingOverseasWarehouses, updatePallet } from './pallets'
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() } }))
@@ -9,6 +9,19 @@ vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn(), post
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)
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 })
})
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)
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 })
@@ -78,6 +78,16 @@ export async function getPallet(warehouseId: string, palletId: string) {
return unwrapApiResponse(response)
}
export async function getPalletLabelPdf(warehouseId: string, palletId: string) {
const blob = await overseasHttp.get<Blob, Blob>(
`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets/${encodeURIComponent(palletId)}/label`,
{ responseType: 'blob', timeout: 60_000 },
)
if (blob.type.includes('application/json')) unwrapApiResponse(JSON.parse(await blob.text()) as ApiEnvelope<unknown>)
if (!blob.size || !blob.type.includes('application/pdf')) throw new Error('打印服务未返回有效 PDF,请重试')
return blob
}
export async function createPallet(warehouseId: string, payload: SavePalletPayload) {
const response = await overseasHttp.post<ApiEnvelope<string>, ApiEnvelope<string>>(
`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets`, payload,