2026-09-15 16:11:20 +08:00
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
2026-09-29 17:56:00 +08:00
|
|
|
import { http } from '@/shared/api/http'
|
2026-09-15 16:11:20 +08:00
|
|
|
import { listContainerArrivalTimes, updateContainerExpectedArrival } from './containerArrivalTimes'
|
|
|
|
|
|
2026-09-29 17:56:00 +08:00
|
|
|
vi.mock('@/shared/api/http', async (importOriginal) => ({ ...(await importOriginal<typeof import('@/shared/api/http')>()), http: { post: vi.fn(), put: vi.fn() } }))
|
2026-09-15 16:11:20 +08:00
|
|
|
|
|
|
|
|
describe('container arrival-time overseas API', () => {
|
|
|
|
|
beforeEach(() => vi.clearAllMocks())
|
|
|
|
|
|
|
|
|
|
it('queries visible containers and updates the whole-container expected arrival', async () => {
|
2026-10-21 15:49:35 +08:00
|
|
|
vi.mocked(http.post).mockResolvedValue({ code: '200', data: [{ sourceContainerBookingId: '9001', estimatedWarehouseArrivalAt: null, actualWarehouseArrivalAt: null, version: 0, planCount: 0 }] })
|
|
|
|
|
vi.mocked(http.put).mockResolvedValue({ code: '200', data: { sourceContainerBookingId: '9001', estimatedWarehouseArrivalAt: '2026-09-25T15:31:00', actualWarehouseArrivalAt: null, version: 1, planCount: 0 } } as never)
|
2026-09-15 16:11:20 +08:00
|
|
|
|
|
|
|
|
await listContainerArrivalTimes(['9001'])
|
|
|
|
|
await updateContainerExpectedArrival('9001', { estimatedWarehouseArrivalAt: '2026-09-25T15:31:00', expectedVersion: 0 })
|
|
|
|
|
|
2026-09-29 17:56:00 +08:00
|
|
|
expect(http.post).toHaveBeenCalledWith('/platform/v1/last-leg/orders/container-arrival-times/query', { sourceContainerBookingIds: ['9001'] })
|
|
|
|
|
expect(http.put).toHaveBeenCalledWith('/platform/v1/last-leg/orders/container-summaries/9001/expected-arrival', { estimatedWarehouseArrivalAt: '2026-09-25T15:31:00', expectedVersion: 0 }, { headers: { 'Idempotency-Key': expect.stringContaining('container-expected-arrival-9001-') } })
|
2026-09-15 16:11:20 +08:00
|
|
|
})
|
2026-10-21 15:49:35 +08:00
|
|
|
|
|
|
|
|
it('normalizes serialized plan counts and rejects unknown counts instead of showing a default', async () => {
|
|
|
|
|
const row = { sourceContainerBookingId: '9001', estimatedWarehouseArrivalAt: null, actualWarehouseArrivalAt: null, version: 0 }
|
|
|
|
|
vi.mocked(http.post).mockResolvedValue({ code: '200', data: [{ ...row, planCount: '1' }] })
|
|
|
|
|
expect(await listContainerArrivalTimes(['9001'])).toEqual([{ ...row, planCount: 1 }])
|
|
|
|
|
for (const planCount of [undefined, null, '', 'unknown', -1, 0.5]) {
|
|
|
|
|
vi.mocked(http.post).mockResolvedValue({ code: '200', data: [{ ...row, planCount }] })
|
|
|
|
|
await expect(listContainerArrivalTimes(['9001'])).rejects.toThrow('入库计划数量无效')
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-09-15 16:11:20 +08:00
|
|
|
})
|