2026-08-10 15:36:53 +08:00
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
import { http } from '@/shared/api/http'
|
|
|
|
|
import {
|
|
|
|
|
adjustSmartLoadingItem, assignSmartLoadingItem, createSmartLoadingPlan, getContainer,
|
|
|
|
|
listContainers, listSmartLoadingCandidates, pushSmartLoadingPreload, removeSmartLoadingItem,
|
|
|
|
|
updateContainer, updateContainerTransport,
|
|
|
|
|
} from './platformContainerLoading'
|
|
|
|
|
|
|
|
|
|
vi.mock('@/shared/api/http', () => ({
|
|
|
|
|
http: { get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn(), delete: vi.fn() },
|
|
|
|
|
unwrapApiResponse: <T>(response: { data: T }) => response.data,
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
const container = { id: 9007199254740993, planId: 9007199254740994, warehouseId: 9007199254740995, shippingCompanyId: 9007199254740996, version: '2', capacityCbm: '68', maxWeightKg: '28000' }
|
|
|
|
|
const plan = { id: 9007199254740993, bookingId: 9007199254740994, version: '3', status: 'EDITING', items: [{ id: 9007199254740995, loadingPlanId: 9007199254740993, accountId: 1, inboundId: 2, inboundDetailId: 3, orderId: 4, destinationWarehouseId: 5, packageCount: '6', version: '1' }] }
|
|
|
|
|
|
|
|
|
|
describe('platform container loading API', () => {
|
|
|
|
|
beforeEach(() => vi.clearAllMocks())
|
|
|
|
|
|
|
|
|
|
it('normalizes paged container ids and numeric metadata', async () => {
|
|
|
|
|
vi.mocked(http.get).mockResolvedValueOnce({ code: '200', data: { records: [container], page: '1', size: '20', total: '1', pages: '1' } })
|
|
|
|
|
const result = await listContainers({ page: 1, size: 20 })
|
|
|
|
|
expect(result.records[0]).toMatchObject({ id: String(container.id), planId: String(container.planId), warehouseId: String(container.warehouseId), version: 2, capacityCbm: 68 })
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/containers', { params: { page: 1, size: 20 } })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('uses full-edit and transport whitelist request shapes', async () => {
|
|
|
|
|
vi.mocked(http.put).mockResolvedValue({ code: '200', data: container })
|
|
|
|
|
vi.mocked(http.patch).mockResolvedValue({ code: '200', data: container })
|
|
|
|
|
const data = { cabinetNo: 'CB-1', warehouseId: '8', warehouseName: '义乌仓', containerType: '40HQ', containerNo: null, billOfLadingNo: null, vesselName: null, voyageNo: null, shippingCompanyId: null, shippingCompanyName: null, departurePortCode: null, departurePortName: null, destinationPortCode: null, destinationPortName: null, destinationWarehouseCode: null, destinationWarehouseName: null, capacityCbm: null, maxWeightKg: null, terminalTruckingCompany: null, loadingAt: null, estimatedSailingAt: null, actualSailingAt: null, estimatedPortArrivalAt: null, actualPortArrivalAt: null, estimatedWarehouseArrivalAt: null, actualWarehouseArrivalAt: null }
|
|
|
|
|
await updateContainer('7', 2, data)
|
|
|
|
|
await updateContainerTransport('7', 3, { containerNo: 'MSCU1', voyageNo: 'V8' })
|
|
|
|
|
expect(http.put).toHaveBeenCalledWith('/platform/v1/containers/7', { version: 2, data })
|
|
|
|
|
expect(http.patch).toHaveBeenCalledWith('/platform/v1/containers/7/transport', { version: 3, containerNo: 'MSCU1', voyageNo: 'V8' })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('normalizes every long id in candidates and plans', async () => {
|
|
|
|
|
vi.mocked(http.get)
|
|
|
|
|
.mockResolvedValueOnce({ code: '200', data: container })
|
|
|
|
|
.mockResolvedValueOnce({ code: '200', data: [{ accountId: 1, inboundId: 2, inboundDetailId: 3, orderId: 4, warehouseId: 5, destinationWarehouseId: 6, availablePackageCount: '7' }] })
|
|
|
|
|
expect((await getContainer('9')).id).toBe(String(container.id))
|
2026-08-12 18:43:54 +08:00
|
|
|
expect(await listSmartLoadingCandidates('7', '5')).toMatchObject([{ accountId: '1', inboundDetailId: '3', destinationWarehouseId: '6', availablePackageCount: 7 }])
|
|
|
|
|
expect(http.get).toHaveBeenLastCalledWith('/platform/v1/first-leg/smart-loading/candidates', { params: { bookingId: '7', warehouseId: '5' } })
|
2026-08-10 15:36:53 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('sends plan and item versions plus operation and idempotency keys', async () => {
|
|
|
|
|
vi.mocked(http.post).mockResolvedValue({ code: '200', data: plan })
|
|
|
|
|
vi.mocked(http.patch).mockResolvedValue({ code: '200', data: plan })
|
|
|
|
|
vi.mocked(http.delete).mockResolvedValue({ code: '200', data: plan })
|
|
|
|
|
await createSmartLoadingPlan('7', null)
|
|
|
|
|
await assignSmartLoadingItem('10', { inboundId: '2', inboundDetailId: '3', packageCount: 4, expectedVersion: 5 })
|
|
|
|
|
await adjustSmartLoadingItem('10', '11', 6, 7, 8)
|
|
|
|
|
await removeSmartLoadingItem('10', '11', 9, 10)
|
|
|
|
|
await pushSmartLoadingPreload('10', 11)
|
|
|
|
|
expect(http.post).toHaveBeenNthCalledWith(1, '/platform/v1/first-leg/smart-loading/plans', { bookingId: '7', remark: null })
|
|
|
|
|
expect(vi.mocked(http.post).mock.calls[1]?.[1]).toMatchObject({ expectedVersion: 5, operationId: expect.stringContaining('assign-') })
|
|
|
|
|
expect(vi.mocked(http.patch).mock.calls[0]?.[1]).toMatchObject({ expectedPlanVersion: 7, expectedItemVersion: 8, operationId: expect.stringContaining('adjust-') })
|
|
|
|
|
expect(vi.mocked(http.delete).mock.calls[0]?.[1]).toMatchObject({ data: { expectedPlanVersion: 9, expectedItemVersion: 10, operationId: expect.stringContaining('remove-') } })
|
|
|
|
|
expect(vi.mocked(http.post).mock.calls[2]?.[2]).toMatchObject({ headers: { 'Idempotency-Key': expect.stringContaining('push-preload-') } })
|
|
|
|
|
})
|
|
|
|
|
})
|