44 lines
3.5 KiB
TypeScript
44 lines
3.5 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|||
|
|
import { http } from '@/shared/api/http'
|
||
|
|
import { completeAllBuyContainerCustoms, getContainerCustoms, startContainerCustoms, uploadContainerCustomsCompletion } from './platformContainerCustoms'
|
||
|
|
|
||
|
|
const customs = {
|
||
|
|
aggregateId: 2092438843630391401n, loadingPlanId: 2092438843630391402n, containerBookingId: 2092438843630391403n,
|
||
|
|
planNo: 'LP-1', cabinetNo: 'CB-1', containerNo: 'MSCU-1', status: 'READY_TO_START', version: '3', taxRefundCount: 1, coveredTaxRefundCount: 1,
|
||
|
|
inbounds: [{ inboundId: 2092438843630391404n, orderId: 2092438843630391405n, orderNo: 'O-1', inboundCode: 'RK-1', tenantId: 2092438843630391406n, customerName: '客户一', taxMode: 'TAX_REFUND', covered: true }],
|
||
|
|
documents: [{ documentId: 2092438843630391407n, tenantId: 2092438843630391406n, source: { fileId: '2092438843630391408', fileName: 'source.pdf', fileHash: 'hash', sizeBytes: 1, version: 2, uploadedAt: '2026-08-28T10:00:00' }, inboundIds: ['2092438843630391404'], inboundCodes: ['RK-1'], frozen: true, completion: null }],
|
||
|
|
startedAt: null, completedAt: null,
|
||
|
|
}
|
||
|
|
|
||
|
|
describe('platform container customs API', () => {
|
||
|
|
beforeEach(() => vi.restoreAllMocks())
|
||
|
|
|
||
|
|
it('uses the frozen customs-v1 paths and preserves long ids as strings', async () => {
|
||
|
|
const get = vi.spyOn(http, 'get').mockResolvedValue({ code: '200', message: 'ok', data: customs })
|
||
|
|
const result = await getContainerCustoms('2092438843630391402')
|
||
|
|
expect(get).toHaveBeenCalledWith('/platform/v1/customs/loading-plans/2092438843630391402')
|
||
|
|
expect(result).toMatchObject({ aggregateId: '2092438843630391401', loadingPlanId: '2092438843630391402', containerBookingId: '2092438843630391403' })
|
||
|
|
expect(result.inbounds[0]).toMatchObject({ inboundId: '2092438843630391404', orderId: '2092438843630391405', tenantId: '2092438843630391406' })
|
||
|
|
expect(result.documents[0]?.documentId).toBe('2092438843630391407')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('sends confirmed start and all-buy completion with optimistic version and idempotency', async () => {
|
||
|
|
const post = vi.spyOn(http, 'post').mockResolvedValue({ code: '200', message: 'ok', data: customs })
|
||
|
|
await startContainerCustoms('2092438843630391402', 3)
|
||
|
|
await completeAllBuyContainerCustoms('2092438843630391402', 4)
|
||
|
|
expect(post.mock.calls[0]?.slice(0, 2)).toEqual(['/platform/v1/customs/loading-plans/2092438843630391402/start', { expectedVersion: 3, confirm: true, remark: null }])
|
||
|
|
expect(post.mock.calls[1]?.slice(0, 2)).toEqual(['/platform/v1/customs/loading-plans/2092438843630391402/complete-all-buy', { expectedVersion: 4, confirm: true, remark: null }])
|
||
|
|
expect(post.mock.calls[0]?.[2]).toMatchObject({ headers: { 'Idempotency-Key': expect.any(String) } })
|
||
|
|
})
|
||
|
|
|
||
|
|
it('uploads one completion file with final-confirmation query parameters', async () => {
|
||
|
|
const document = { ...customs.documents[0], documentId: '2092438843630391407', tenantId: '2092438843630391406' }
|
||
|
|
const post = vi.spyOn(http, 'post').mockResolvedValue({ code: '200', message: 'ok', data: document })
|
||
|
|
const completion = new File(['done'], 'done.pdf')
|
||
|
|
await uploadContainerCustomsCompletion('2092438843630391407', completion, 0, true)
|
||
|
|
expect(post.mock.calls[0]?.[0]).toBe('/platform/v1/customs/loading-plans/documents/2092438843630391407/completion/upload')
|
||
|
|
expect((post.mock.calls[0]?.[1] as FormData).get('file')).toBe(completion)
|
||
|
|
expect(post.mock.calls[0]?.[2]).toMatchObject({ params: { expectedVersion: 0, finalConfirmation: true }, headers: { 'Content-Type': 'multipart/form-data', 'Idempotency-Key': expect.any(String) } })
|
||
|
|
})
|
||
|
|
})
|