This commit is contained in:
2026-08-06 13:56:04 +08:00
parent 6736893128
commit a813426588
35 changed files with 2822 additions and 489 deletions
@@ -0,0 +1,70 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import {
completeDelivery,
completeLoading,
confirmingPreload,
getPicking,
getPreload,
smartSplit,
} 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('uses the inbound version for delivery completion', async () => {
vi.mocked(http.post).mockResolvedValue({ data: { mainStatus: 'DELIVERED', evidences: null } })
await completeDelivery('2', '8', { expectedVersion: 9, remark: '已确认派送' })
expect(http.post).toHaveBeenCalledWith(
'/platform/v1/inbounds/8/delivery/complete', { expectedVersion: 9, remark: '已确认派送' },
expect.objectContaining({ params: { tenantId: '2' }, headers: { 'Idempotency-Key': expect.any(String) } }),
)
})
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' } }),
)
})
})