2026-08-26 15:48:34 +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-08-26 15:48:34 +08:00
|
|
|
import { createExceptionOrder, listExceptionOrders, resolveExceptionRelation } from './exceptionOrders'
|
|
|
|
|
|
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() } }))
|
2026-08-26 15:48:34 +08:00
|
|
|
|
|
|
|
|
describe('exception order API', () => {
|
2026-09-29 17:56:00 +08:00
|
|
|
beforeEach(() => { vi.mocked(http.get).mockReset(); vi.mocked(http.post).mockReset() })
|
2026-08-26 15:48:34 +08:00
|
|
|
|
|
|
|
|
it('queries the real paginated exception endpoint', async () => {
|
2026-09-29 17:56:00 +08:00
|
|
|
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [], page: '1', size: '20', total: '2', pages: '1' } })
|
2026-08-26 15:48:34 +08:00
|
|
|
const result = await listExceptionOrders({ page: 1, size: 20, keyword: 'EXC' })
|
2026-09-29 17:56:00 +08:00
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/last-leg/exception-orders', { params: { page: 1, size: 20, keyword: 'EXC' } })
|
2026-08-26 15:48:34 +08:00
|
|
|
expect(result.total).toBe(2)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('resolves relation before creating an exception document', async () => {
|
2026-09-29 17:56:00 +08:00
|
|
|
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { inboundOrderId: '11', inboundCode: 'IN-1', lastMileOrderId: '12', lastMileOrderNo: 'LM-1', customerId: '1' } })
|
2026-08-26 15:48:34 +08:00
|
|
|
await resolveExceptionRelation({ inboundCode: 'IN-1', lastMileOrderNo: 'LM-1' })
|
2026-09-29 17:56:00 +08:00
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/last-leg/exception-orders/resolve', { params: { inboundCode: 'IN-1', lastMileOrderNo: 'LM-1' } })
|
2026-08-26 15:48:34 +08:00
|
|
|
|
2026-09-29 17:56:00 +08:00
|
|
|
vi.mocked(http.post).mockResolvedValue({ code: '200', data: { id: '99', exceptionNo: 'EXC-1', status: 'PENDING' } })
|
2026-08-26 15:48:34 +08:00
|
|
|
await createExceptionOrder({ inboundCode: 'IN-1', lastMileOrderNo: 'LM-1', exceptionType: 'RETURN', reason: '拒收' })
|
2026-09-29 17:56:00 +08:00
|
|
|
expect(http.post).toHaveBeenCalledWith('/platform/v1/last-leg/exception-orders', expect.objectContaining({ inboundCode: 'IN-1', lastMileOrderNo: 'LM-1' }))
|
2026-08-26 15:48:34 +08:00
|
|
|
})
|
|
|
|
|
})
|