Files
admin-web/src/modules/overseas-warehouse/api/inboundOrders.test.ts
T

63 lines
3.7 KiB
TypeScript
Raw Normal View History

2026-08-20 18:04:38 +08:00
import { beforeEach, describe, expect, it, vi } from 'vitest'
2026-09-29 17:56:00 +08:00
import { http } from '@/shared/api/http'
import { createFbaAppointment, getFbaAppointment, listFbaAppointmentCalendar, listInboundOrders, updateFbaAppointment } from './inboundOrders'
2026-08-20 18:04:38 +08:00
2026-09-29 17:56:00 +08:00
vi.mock('@/shared/api/http', async (importOriginal) => ({ ...(await importOriginal<typeof import('@/shared/api/http')>()), http: { get: vi.fn(), post: vi.fn(), put: vi.fn() } }))
2026-08-20 18:04:38 +08:00
describe('inbound order overseas API', () => {
beforeEach(() => {
2026-09-29 17:56:00 +08:00
vi.mocked(http.get).mockReset()
vi.mocked(http.post).mockReset()
vi.mocked(http.put).mockReset()
2026-08-20 18:04:38 +08:00
})
it('loads a calendar range in one request and supports cancelling obsolete requests', async () => {
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: [] })
const controller = new AbortController()
const query = { from: '2026-08-31', to: '2026-10-12' }
expect(await listFbaAppointmentCalendar(query, controller.signal)).toEqual([])
expect(http.get).toHaveBeenCalledTimes(1)
expect(http.get).toHaveBeenCalledWith('/platform/v1/last-leg/inbound-plans/fba-appointments/calendar', {
params: query, signal: controller.signal,
})
})
it('does not turn calendar business errors into an empty successful calendar', async () => {
vi.mocked(http.get).mockResolvedValue({ code: '500', message: '日历查询失败', data: null })
await expect(listFbaAppointmentCalendar({ from: '2026-09-01', to: '2026-10-01' })).rejects.toThrow()
})
2026-08-20 18:04:38 +08:00
it('loads appointment details and updates the existing appointment without replacing its lines', async () => {
const detail = { version: 0, id: '1', customerId: '190000000000000001', appointmentNo: 'APT/1', appointmentAt: '2026-08-20T10:30:00', expectedLoadingAt: '2026-08-20T09:00:00', appointmentStatus: 'SUCCESS', selectedCount: 2, fbaWarehouseCode: 'ONT8', items: [] }
2026-09-29 17:56:00 +08:00
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: detail })
vi.mocked(http.put).mockResolvedValue({ code: '200', message: 'success', data: detail })
2026-08-20 18:04:38 +08:00
await getFbaAppointment('APT/1')
await updateFbaAppointment('APT/1', { version: detail.version, appointmentAt: detail.appointmentAt, expectedLoadingAt: detail.expectedLoadingAt, appointmentStatus: 'SUCCESS' })
2026-08-20 18:04:38 +08:00
expect(http.get).toHaveBeenCalledWith('/platform/v1/last-leg/inbound-plans/fba-appointments/APT%2F1')
expect(http.put).toHaveBeenCalledWith('/platform/v1/last-leg/inbound-plans/fba-appointments/APT%2F1', expect.not.objectContaining({ customerId: expect.anything() }))
2026-08-20 18:04:38 +08:00
})
2026-08-21 11:20:09 +08:00
it('loads the paginated list across all customers without a customer scope', async () => {
2026-09-29 17:56:00 +08:00
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: { records: [], page: 1, size: 20, total: 0, pages: 0 } })
2026-08-21 11:20:09 +08:00
await listInboundOrders({ page: 1, size: 20, appointmentStatus: 'UNAPPOINTED' })
2026-09-29 17:56:00 +08:00
expect(http.get).toHaveBeenCalledWith('/platform/v1/last-leg/inbound-plans', {
2026-08-21 11:20:09 +08:00
params: { page: 1, size: 20, appointmentStatus: 'UNAPPOINTED' },
2026-08-20 18:04:38 +08:00
})
})
it('preserves selected line ids as strings when creating an appointment', async () => {
2026-09-29 17:56:00 +08:00
vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: { id: '1', appointmentNo: 'APT-1', appointmentStatus: 'SUCCESS', selectedCount: 1, fbaWarehouseCode: 'ONT8' } })
2026-08-20 18:04:38 +08:00
const payload = {
lineIds: ['190000000000000099'],
appointmentNo: 'APT-1',
appointmentAt: '2026-08-20T10:30:00',
expectedLoadingAt: '2026-08-20T09:00:00',
appointmentStatus: 'SUCCESS' as const,
}
await createFbaAppointment(payload)
2026-09-29 17:56:00 +08:00
expect(http.post).toHaveBeenCalledWith('/platform/v1/last-leg/inbound-plans/fba-appointments/batch', payload)
2026-08-20 18:04:38 +08:00
})
})