import { beforeEach, describe, expect, it, vi } from 'vitest' import { http } from '@/shared/api/http' import { cancelOutbound, createOneClickDropshipOutbound, getOutbound, listOneClickOutboundCandidates, listOutbounds } from './outbounds' vi.mock('@/shared/api/http', async (importOriginal) => ({ ...(await importOriginal()), http: { get: vi.fn(), post: vi.fn() } })) describe('outbound overseas API', () => { beforeEach(() => { vi.mocked(http.get).mockReset(); vi.mocked(http.post).mockReset() }) it('lists outbound orders with supported filters', async () => { vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [], page: 1, size: 20, total: 0, pages: 0 } }) await listOutbounds({ page: 1, size: 20, documentNo: 'OUT-1', warehouseId: 'WH-1', status: 'PICKED' }) expect(http.get).toHaveBeenCalledWith('/platform/v1/last-leg/outbound-orders', { params: { page: 1, size: 20, documentNo: 'OUT-1', warehouseId: 'WH-1', status: 'PICKED' } }) }) it('loads detail and cancels only by outboundNo without customerId', async () => { vi.mocked(http.get).mockResolvedValue({ code: '200', data: { outbound: { id: '1', outboundNo: 'OUT/1', status: 'PICKED' }, deliveries: [] } }) vi.mocked(http.post).mockResolvedValue({ code: '200', data: null }) await getOutbound('OUT/1') await cancelOutbound('OUT/1', '运营取消') expect(http.get).toHaveBeenCalledWith('/platform/v1/last-leg/outbound-orders/OUT%2F1') expect(http.post).toHaveBeenCalledWith('/platform/v1/last-leg/outbound-orders/OUT%2F1/cancel', { reason: '运营取消' }) }) it('keeps customerId explicit only for one-click dropship creation', async () => { vi.mocked(http.post).mockResolvedValue({ code: '200', data: { id: '1', outboundNo: 'OUT-1' } }) const payload = { recipient: 'John / 555 / LA', items: [{ inventoryPositionId: '99', packages: 2, sku: 'SKU-1' }], idempotencyKey: 'dropship-1' } await createOneClickDropshipOutbound('customer-1', payload) expect(http.post).toHaveBeenCalledWith('/platform/v1/last-leg/outbound-orders/one-click-dropship', payload, { params: { customerId: 'customer-1' } }) }) it('normalizes one-click candidate measurements returned as decimal strings', async () => { vi.mocked(http.get).mockResolvedValue({ code: '200', data: [{ inventoryPositionId: '99', availablePackages: 4, grossWeightKg: '40.000', volumeWeightKg: '80.000', volumeCbm: '4.0000', }] }) const [candidate] = await listOneClickOutboundCandidates(undefined, { warehouseId: 'warehouse-1' }) expect(candidate).toMatchObject({ inventoryPositionId: '99', availablePackages: 4, grossWeightKg: 40, volumeWeightKg: 80, volumeCbm: 4, }) }) })