Files
admin-web/src/modules/unified-orders/workflows/api.test.ts
T

79 lines
3.7 KiB
TypeScript
Raw Normal View History

2026-08-06 13:56:04 +08:00
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import {
completeLoading,
confirmingPreload,
getPicking,
getPreload,
smartSplit,
uploadEvidenceFile,
voidEvidence,
2026-08-06 13:56:04 +08:00
} from './api'
vi.mock('@/shared/api/http', () => ({
http: { get: vi.fn(), post: vi.fn() },
unwrapApiResponse: <T>(response: { data: T }) => response.data,
}))
describe('unified order workflow API contract', () => {
beforeEach(() => {
vi.mocked(http.get).mockReset()
vi.mocked(http.post).mockReset()
})
it('uses the C03 preload endpoints and expected version', async () => {
vi.mocked(http.get).mockResolvedValue({ data: { id: 1, inboundId: 8, tenantId: 2, status: 'PENDING', version: 3, items: [] } })
vi.mocked(http.post).mockResolvedValue({ data: { mainStatus: 'WAIT_SPLIT', preloadPlan: null } })
await getPreload('2', '8')
await smartSplit('2', '8', { expectedVersion: 3, items: [] })
expect(http.get).toHaveBeenCalledWith('/platform/v1/inbounds/8/preload', { params: { tenantId: '2' } })
expect(http.post).toHaveBeenCalledWith(
'/platform/v1/inbounds/8/split/smart', { expectedVersion: 3, items: [] },
expect.objectContaining({ params: { tenantId: '2' }, headers: { 'Idempotency-Key': expect.any(String) } }),
)
})
it('uses C04 picking and loading paths without a generic action endpoint', async () => {
vi.mocked(http.get).mockResolvedValue({ data: { id: 1, inboundId: 8, status: 'PICKING', version: 4 } })
vi.mocked(http.post).mockResolvedValue({ data: { mainStatus: 'LOADED', evidences: null } })
await getPicking('2', '8')
await completeLoading('2', '8', { expectedVersion: 7 })
expect(http.get).toHaveBeenCalledWith('/platform/v1/inbounds/8/loading/picking', { params: { tenantId: '2' } })
expect(http.post).toHaveBeenCalledWith(
'/platform/v1/inbounds/8/loading/complete', { expectedVersion: 7 },
expect.objectContaining({ params: { tenantId: '2' }, headers: { 'Idempotency-Key': expect.any(String) } }),
)
expect(vi.mocked(http.post).mock.calls.some(([url]) => String(url).includes('/actions/'))).toBe(false)
})
it('does not swallow non-success responses', async () => {
vi.mocked(http.get).mockRejectedValue(new Error('无权限'))
await expect(getPreload('2', '8')).rejects.toThrow('无权限')
})
it('supports the intermediate confirming preload action', async () => {
vi.mocked(http.post).mockResolvedValue({ data: { mainStatus: 'WAIT_SPLIT', preloadPlan: null } })
await confirmingPreload('2', '8', { expectedVersion: 1 })
expect(http.post).toHaveBeenCalledWith(
'/platform/v1/inbounds/8/preload/confirming', { expectedVersion: 1 },
expect.objectContaining({ params: { tenantId: '2' } }),
)
})
it('uploads a real evidence file and voids evidence through audited endpoints', async () => {
vi.mocked(http.post)
.mockResolvedValueOnce({ data: { fileId: '88', fileName: 'empty.jpg' } })
.mockResolvedValueOnce({ data: { mainStatus: 'LOADING', evidences: { inboundId: '8', evidences: [] } } })
await uploadEvidenceFile('2', '8', 'PHOTO_STEP_1', new File(['photo'], 'empty.jpg', { type: 'image/jpeg' }))
await voidEvidence('2', '8', '33', { expectedVersion: 2, reason: '照片错误' })
expect(http.post).toHaveBeenNthCalledWith(1,
'/platform/v1/files/loading-evidence/2/8', expect.any(FormData),
{ headers: { 'Content-Type': 'multipart/form-data' } },
)
expect(http.post).toHaveBeenNthCalledWith(2,
'/platform/v1/inbounds/8/loading/evidence/33/void', { expectedVersion: 2, reason: '照片错误' },
expect.objectContaining({ params: { tenantId: '2' }, headers: { 'Idempotency-Key': expect.any(String) } }),
)
})
2026-08-06 13:56:04 +08:00
})