优化
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { beforeEach, expect, it, vi } from 'vitest'
|
||||
const api = vi.hoisted(() => ({ get: vi.fn(), post: vi.fn() }))
|
||||
vi.mock('@/shared/api/http', async importOriginal => ({ ...await importOriginal<typeof import('@/shared/api/http')>(), http: api }))
|
||||
import { getProcurementWorkflow, submitProcurementWorkflow } from './procurementWorkflow'
|
||||
beforeEach(() => { vi.clearAllMocks(); api.get.mockResolvedValue({ code: '200', data: { orderNo: 'OP/1' } }); api.post.mockResolvedValue({ code: '200', data: { orderNo: 'OP/1' } }) })
|
||||
it('scopes workflow and every batch operation to the exact order and customer', async () => {
|
||||
await getProcurementWorkflow('OP/1', '1001')
|
||||
expect(api.get).toHaveBeenCalledWith('/platform/v1/last-leg/overseas-procurements/OP%2F1/workflow', { params: { customerId: '1001' } })
|
||||
for (const action of ['receipts', 'request-confirmation', 'outbounds', 'outbounds/9007199254740993/dispatch', 'outbounds/9007199254740993/complete']) {
|
||||
const command = { version: 3, idempotencyKey: 'retry-same-key' }
|
||||
await submitProcurementWorkflow('OP/1', '1001', action, command)
|
||||
expect(api.post).toHaveBeenLastCalledWith(`/platform/v1/last-leg/overseas-procurements/OP%2F1/${action}`, command, { params: { customerId: '1001' } })
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
||||
|
||||
export interface ProcurementWorkflowReceipt { id: string; quantity: number; fileIds: string[]; receivedAt: string }
|
||||
export interface ProcurementOutbound { id: string; outboundNo: string; quantity: number; trackingNo: string; status: string; fileIds: string[]; createdAt: string; completedAt: string | null }
|
||||
export interface ProcurementWorkflow {
|
||||
orderNo: string; version: number; status: string; receivedQuantity: number; stockQuantity: number; reservedQuantity: number; availableQuantity: number
|
||||
receipts: ProcurementWorkflowReceipt[]; outbounds: ProcurementOutbound[]
|
||||
}
|
||||
export interface WorkflowCommand { version: number; idempotencyKey: string; quantity?: number; trackingNo?: string; fileIds?: string[] }
|
||||
const base = '/platform/v1/last-leg/overseas-procurements'
|
||||
export async function getProcurementWorkflow(orderNo: string, customerId: string) {
|
||||
return unwrapApiResponse(await http.get<ApiEnvelope<ProcurementWorkflow>, ApiEnvelope<ProcurementWorkflow>>(`${base}/${encodeURIComponent(orderNo)}/workflow`, { params: { customerId } }))
|
||||
}
|
||||
export async function submitProcurementWorkflow(orderNo: string, customerId: string, action: string, payload: WorkflowCommand) {
|
||||
return unwrapApiResponse(await http.post<ApiEnvelope<ProcurementWorkflow>, ApiEnvelope<ProcurementWorkflow>>(`${base}/${encodeURIComponent(orderNo)}/${action}`, payload, { params: { customerId } }))
|
||||
}
|
||||
Reference in New Issue
Block a user