2026-08-20 09:10:36 +08:00
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
import { overseasHttp } from '@/shared/api/overseasHttp'
|
2026-08-21 11:20:09 +08:00
|
|
|
import { changeRelabelOrderStatus, createRelabelOrder, getRelabelOrder, listRelabelOrders } from './relabelOrders'
|
2026-08-20 09:10:36 +08:00
|
|
|
|
2026-08-21 11:20:09 +08:00
|
|
|
vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn(), post: vi.fn(), put: vi.fn() } }))
|
2026-08-20 09:10:36 +08:00
|
|
|
|
|
|
|
|
describe('relabel overseas API', () => {
|
|
|
|
|
beforeEach(() => vi.mocked(overseasHttp.get).mockReset())
|
|
|
|
|
|
2026-08-21 11:20:09 +08:00
|
|
|
it('uses the platform page endpoint without customer scope', async () => {
|
2026-08-20 09:10:36 +08:00
|
|
|
vi.mocked(overseasHttp.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 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' } })
|
2026-08-20 09:10:36 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
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: [] } })
|
2026-08-21 11:20:09 +08:00
|
|
|
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', idempotencyKey: 'k', items: [{ skuCode: 'SKU', productNameZh: 'P', totalPackageCount: 1, notifiedPackageCount: 1, shipmentNo: 'S', newSkuCode: 'SKU-2' }] }
|
|
|
|
|
await createRelabelOrder(payload)
|
|
|
|
|
await changeRelabelOrderStatus('RL-1', 'PROCESSING', 'ok')
|
|
|
|
|
expect(overseasHttp.post).toHaveBeenCalledWith('/platform/v1/last-leg/relabel-applications', payload)
|
|
|
|
|
expect(overseasHttp.put).toHaveBeenCalledWith('/platform/v1/last-leg/relabel-applications/RL-1/status', { status: 'PROCESSING', remark: 'ok' })
|
2026-08-20 09:10:36 +08:00
|
|
|
})
|
|
|
|
|
})
|