import { beforeEach, describe, expect, it, vi } from 'vitest' import { listSharedReceivingOverseasWarehouseOptions } from '@/modules/iam' import { overseasHttp } from '@/shared/api/overseasHttp' import { changeRelabelOrderStatus, createRelabelOrder, getRelabelOrder, listRelabelOrders, listRelabelWarehouseOptions } from './relabelOrders' vi.mock('@/modules/iam', () => ({ listSharedReceivingOverseasWarehouseOptions: vi.fn() })) vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn(), post: vi.fn(), put: vi.fn() } })) describe('relabel overseas API', () => { beforeEach(() => { vi.mocked(overseasHttp.get).mockReset() vi.mocked(overseasHttp.post).mockReset() vi.mocked(overseasHttp.put).mockReset() vi.mocked(listSharedReceivingOverseasWarehouseOptions).mockReset() }) it('uses the platform page endpoint without customer scope', async () => { vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: { records: [], page: 1, size: 20, total: 0, pages: 0 } }) await listRelabelOrders({ page: 1, size: 20, skuCode: 'SKU-1' }) expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/relabel-applications', { params: { page: 1, size: 20, skuCode: 'SKU-1' } }) }) it('encodes the relabel number and does not call a mutation endpoint', async () => { vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: { application: { id: '1', relabelNo: 'RL/1' }, items: [], history: [] } }) await getRelabelOrder('RL/1') expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/relabel-applications/RL%2F1') }) it('uses the real create and status endpoints', async () => { vi.mocked(overseasHttp.post).mockResolvedValue({ code: '200', data: {} }) vi.mocked(overseasHttp.put).mockResolvedValue({ code: '200', data: {} }) const payload = { customerOrderNo: 'CO-1', overseasWarehouseId: '9', labelDeadline: '2026-08-20T10:00:00', contactName: 'A', contactPhone: '1', chargeAmount: 20, idempotencyKey: 'k', items: [{ skuCode: 'SKU', productNameZh: 'P', totalPackageCount: 1, notifiedPackageCount: 1, shipmentNo: 'S', newSkuCode: 'SKU-2' }] } await createRelabelOrder('10001', payload) await changeRelabelOrderStatus('RL/1', 'PROCESSING', 'ok') expect(overseasHttp.post).toHaveBeenCalledWith('/platform/v1/last-leg/relabel-applications', payload, { params: { customerId: '10001' } }) expect(overseasHttp.put).toHaveBeenCalledWith('/platform/v1/last-leg/relabel-applications/RL%2F1/status', { status: 'PROCESSING', remark: 'ok' }) }) it('loads shared ACTIVE OVERSEAS RECEIVING warehouses from the domestic candidate contract', async () => { vi.mocked(listSharedReceivingOverseasWarehouseOptions).mockResolvedValue([{ id: '200', warehouseCode: 'LAX', warehouseName: '洛杉矶仓', countryCode: 'US' }]) await expect(listRelabelWarehouseOptions()).resolves.toMatchObject({ records: [{ id: '200', customerId: '0', warehouseType: 'OVERSEAS', status: 'ACTIVE' }] }) expect(listSharedReceivingOverseasWarehouseOptions).toHaveBeenCalledOnce() expect(overseasHttp.get).not.toHaveBeenCalledWith('/platform/v1/warehouse-admin', expect.anything()) }) })