2026-08-04 21:01:39 +08:00
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
import { http } from '@/shared/api/http'
|
2026-09-07 11:20:43 +08:00
|
|
|
import { downloadInboundCartonLabels, getPlatformInbound, getPlatformInboundHold, holdPlatformInbound, listPlatformInbounds, releasePlatformInbound } from './api'
|
2026-08-04 21:01:39 +08:00
|
|
|
|
|
|
|
|
vi.mock('@/shared/api/http', () => ({
|
2026-08-07 17:16:23 +08:00
|
|
|
ApiResponseError: class ApiResponseError extends Error {
|
|
|
|
|
code: string
|
|
|
|
|
constructor(message: string, code: string) { super(message); this.code = code }
|
|
|
|
|
},
|
|
|
|
|
http: { get: vi.fn(), post: vi.fn() },
|
2026-08-04 21:01:39 +08:00
|
|
|
unwrapApiResponse: <T>(response: { data: T }) => response.data,
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
describe('platform inbound query API', () => {
|
2026-08-07 17:16:23 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.mocked(http.get).mockReset()
|
|
|
|
|
vi.mocked(http.post).mockReset()
|
|
|
|
|
})
|
2026-08-04 21:01:39 +08:00
|
|
|
|
|
|
|
|
it('omits the backend tenant filter for an all-customer list query', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({
|
|
|
|
|
code: '200', message: 'success', data: { records: [], page: 1, size: 20, total: 0, pages: 0 },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await listPlatformInbounds(undefined, { page: 1, size: 20 })
|
|
|
|
|
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/inbounds', { params: { page: 1, size: 20 } })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('uses the implemented non-v1 list path and normalizes page values and IDs', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({
|
|
|
|
|
code: '200', message: 'success', data: {
|
2026-08-17 19:13:25 +08:00
|
|
|
records: [{
|
|
|
|
|
id: 19001, tenantId: 10002, orderId: 18001, customerId: 10001,
|
|
|
|
|
totalPackageCount: '6', palletCount: '2', actualGrossWeightKg: '21.5',
|
|
|
|
|
actualNetWeightKg: '18.25', actualVolumeCbm: '0.456', holdFlag: 'false',
|
|
|
|
|
}],
|
2026-08-04 21:01:39 +08:00
|
|
|
page: '1', size: '20', total: '1', pages: '1',
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await expect(listPlatformInbounds('10001', {
|
|
|
|
|
page: 1, size: 20, tab: 'WAIT_MEASURE', inboundCode: 'RK', holdFlag: false,
|
|
|
|
|
})).resolves.toMatchObject({
|
2026-08-17 19:13:25 +08:00
|
|
|
records: [{
|
|
|
|
|
id: '19001', tenantId: '10002', orderId: '18001', customerId: '10001',
|
|
|
|
|
totalPackageCount: 6, palletCount: 2, actualGrossWeightKg: 21.5,
|
|
|
|
|
actualNetWeightKg: 18.25, actualVolumeCbm: 0.456, holdFlag: false,
|
|
|
|
|
}],
|
2026-08-04 21:01:39 +08:00
|
|
|
total: 1, pages: 1,
|
|
|
|
|
})
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/inbounds', {
|
|
|
|
|
params: { tenantId: '10001', page: 1, size: 20, tab: 'WAIT_MEASURE', inboundCode: 'RK', holdFlag: false },
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('loads a tenant-scoped aggregate detail and keeps nested IDs as strings', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({
|
|
|
|
|
code: '200', message: 'success', data: {
|
2026-08-05 09:11:48 +08:00
|
|
|
summary: { id: 19001, tenantId: 10002, orderId: 18001 }, publicRemark: null,
|
2026-08-04 21:01:39 +08:00
|
|
|
palletLocations: [{ palletId: 21001, locationId: 22001 }], files: [{ fileId: 23001, uploadedBy: 2 }],
|
|
|
|
|
internalNotes: [{ id: 24001, createdBy: 2 }], statusHistory: [{ operatorId: 2 }],
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await expect(getPlatformInbound('10001', '19001')).resolves.toMatchObject({
|
2026-08-05 09:11:48 +08:00
|
|
|
summary: { id: '19001', tenantId: '10002', orderId: '18001' },
|
2026-08-04 21:01:39 +08:00
|
|
|
palletLocations: [{ palletId: '21001', locationId: '22001' }],
|
|
|
|
|
files: [{ fileId: '23001', uploadedBy: '2' }],
|
|
|
|
|
internalNotes: [{ id: '24001', createdBy: '2' }],
|
|
|
|
|
statusHistory: [{ operatorId: '2' }],
|
|
|
|
|
})
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/inbounds/19001', { params: { tenantId: '10001' } })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('passes the implemented order, process, measurement and fee review filters without renaming them', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({
|
|
|
|
|
code: '200', message: 'success', data: { records: [], page: 1, size: 20, total: 0, pages: 0 },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await listPlatformInbounds('10001', {
|
|
|
|
|
page: 1,
|
|
|
|
|
size: 20,
|
|
|
|
|
processStatus: 'MEASURE_PENDING',
|
|
|
|
|
orderStatus: 'APPROVED',
|
|
|
|
|
measureReviewStatus: 'PENDING',
|
|
|
|
|
feeStatus: 'UNPRICED',
|
|
|
|
|
feeReviewStatus: 'PENDING',
|
|
|
|
|
warehouseId: '9007199254740993',
|
|
|
|
|
deliveryWarehouseId: '9007199254740995',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/inbounds', {
|
|
|
|
|
params: {
|
|
|
|
|
tenantId: '10001', page: 1, size: 20, processStatus: 'MEASURE_PENDING',
|
|
|
|
|
orderStatus: 'APPROVED', measureReviewStatus: 'PENDING', feeStatus: 'UNPRICED', feeReviewStatus: 'PENDING',
|
|
|
|
|
warehouseId: '9007199254740993', deliveryWarehouseId: '9007199254740995',
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
})
|
2026-08-07 17:16:23 +08:00
|
|
|
|
|
|
|
|
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',
|
|
|
|
|
})
|
|
|
|
|
})
|
2026-09-07 11:20:43 +08:00
|
|
|
|
|
|
|
|
it('loads and normalizes the tenant-scoped hold state and immutable history', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({ data: {
|
|
|
|
|
inboundId: 19001, tenantId: 10002, holdFlag: true, currentHoldReason: ' 待核对货款 ', version: '4',
|
|
|
|
|
canHold: false, canRelease: true, actionBlockReason: null,
|
|
|
|
|
history: [{ id: 88001, action: 'HOLD', reason: ' 待核对货款 ', evidenceFileId: 99001, operatorName: ' 财务A ', operatedAt: '2026-09-07T10:00:00' }],
|
|
|
|
|
} })
|
|
|
|
|
|
|
|
|
|
await expect(getPlatformInboundHold('10002', '19001')).resolves.toEqual({
|
|
|
|
|
inboundId: '19001', tenantId: '10002', holdFlag: true, currentHoldReason: '待核对货款', version: 4,
|
|
|
|
|
canHold: false, canRelease: true, actionBlockReason: null,
|
|
|
|
|
history: [{ id: '88001', action: 'HOLD', reason: '待核对货款', evidenceFileId: '99001', operatorName: '财务A', operatedAt: '2026-09-07T10:00:00' }],
|
|
|
|
|
})
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/inbounds/19001/hold', { params: { tenantId: '10002' } })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('posts hold and release commands with versions, reasons and independent idempotency keys', async () => {
|
|
|
|
|
const result = { data: { inboundId: '19001', tenantId: '10002', holdFlag: true, currentHoldReason: '待核对货款', version: 4, canHold: false, canRelease: true, actionBlockReason: null, history: [] } }
|
|
|
|
|
vi.mocked(http.post).mockResolvedValue(result)
|
|
|
|
|
|
|
|
|
|
await holdPlatformInbound('10002', '19001', { expectedVersion: 3, reason: '待核对货款' }, 'hold-key')
|
|
|
|
|
expect(http.post).toHaveBeenNthCalledWith(1, '/platform/inbounds/19001/hold', { expectedVersion: 3, reason: '待核对货款' }, {
|
|
|
|
|
params: { tenantId: '10002' }, headers: { 'Idempotency-Key': 'hold-key' },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await releasePlatformInbound('10002', '19001', { expectedVersion: 4, reason: '货款已核对' }, 'release-key')
|
|
|
|
|
expect(http.post).toHaveBeenNthCalledWith(2, '/platform/inbounds/19001/hold/release', { expectedVersion: 4, reason: '货款已核对' }, {
|
|
|
|
|
params: { tenantId: '10002' }, headers: { 'Idempotency-Key': 'release-key' },
|
|
|
|
|
})
|
|
|
|
|
})
|
2026-08-04 21:01:39 +08:00
|
|
|
})
|