优化
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { http } from '@/shared/api/http'
|
||||
import { createDomesticContainerOutbound, listDomesticContainerInventories } from './domesticContainers'
|
||||
vi.mock('@/shared/api/http', async (original) => ({ ...(await original<typeof import('@/shared/api/http')>()), http: { get: vi.fn(), post: vi.fn() } }))
|
||||
const envelope = <T>(data: T) => ({ code: '200', message: 'ok', data })
|
||||
describe('domestic container api', () => {
|
||||
beforeEach(() => vi.clearAllMocks())
|
||||
it('normalizes inventory pagination and summary from the real endpoint', async () => { vi.mocked(http.get).mockResolvedValue(envelope({ records: [], page: '1', size: '20', total: '0', pages: '0', summary: { inboundBoxes: 2, outboundBoxes: 1, availableBoxes: 1, inboundVolumeCbm: 3.25 } })); const result = await listDomesticContainerInventories({ page: 1, size: 20 }); expect(http.get).toHaveBeenCalledWith('/platform/v1/domestic-containers/inventories', { params: { page: 1, size: 20 } }); expect(result).toMatchObject({ page: 1, total: 0, summary: { availableBoxes: 1 } }) })
|
||||
it('passes idempotency key and inventory version without local deduction', async () => { vi.mocked(http.post).mockResolvedValue(envelope({ id: 1, orderNo: 'ZGCK1', replayed: false })); await createDomesticContainerOutbound({ warehouseId: '2', containerNo: 'MSCU1', boxCount: 3, outboundTime: '2026-08-13T10:00:00', status: 'COMPLETED', idempotencyKey: 'stable-key', inventoryVersion: 7 }); expect(http.post).toHaveBeenCalledWith('/platform/v1/domestic-containers/outbounds', expect.objectContaining({ idempotencyKey: 'stable-key', inventoryVersion: 7 })) })
|
||||
})
|
||||
@@ -0,0 +1,34 @@
|
||||
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
||||
import type { ContainerOrder, CreateInboundRequest, CreateOutboundRequest, CreateResponse, DomesticContainerFilters, InventoryDetail, InventoryPage, PageResult } from '../types'
|
||||
|
||||
const basePath = '/platform/v1/domestic-containers'
|
||||
type PagePayload<T> = Omit<PageResult<T>, 'page' | 'size' | 'total' | 'pages'> & { page: number | string; size: number | string; total: number | string; pages: number | string }
|
||||
type InventoryPayload = Omit<InventoryPage, 'page' | 'size' | 'total' | 'pages'> & { page: number | string; size: number | string; total: number | string; pages: number | string; summary?: Partial<InventoryPage['summary']> }
|
||||
|
||||
function pageResult<T>(value: PagePayload<T>): PageResult<T> { return { ...value, page: Number(value.page), size: Number(value.size), total: Number(value.total), pages: Number(value.pages) } }
|
||||
|
||||
export async function listDomesticContainerInbounds(query: DomesticContainerFilters) {
|
||||
const response = await http.get<ApiEnvelope<PagePayload<ContainerOrder>>, ApiEnvelope<PagePayload<ContainerOrder>>>(`${basePath}/inbounds`, { params: query })
|
||||
return pageResult(unwrapApiResponse(response))
|
||||
}
|
||||
export async function listDomesticContainerOutbounds(query: DomesticContainerFilters) {
|
||||
const response = await http.get<ApiEnvelope<PagePayload<ContainerOrder>>, ApiEnvelope<PagePayload<ContainerOrder>>>(`${basePath}/outbounds`, { params: query })
|
||||
return pageResult(unwrapApiResponse(response))
|
||||
}
|
||||
export async function listDomesticContainerInventories(query: DomesticContainerFilters) {
|
||||
const response = await http.get<ApiEnvelope<InventoryPayload>, ApiEnvelope<InventoryPayload>>(`${basePath}/inventories`, { params: query })
|
||||
const result = unwrapApiResponse(response)
|
||||
return { ...pageResult(result), summary: { inboundBoxes: Number(result.summary?.inboundBoxes ?? 0), outboundBoxes: Number(result.summary?.outboundBoxes ?? 0), availableBoxes: Number(result.summary?.availableBoxes ?? 0), inboundVolumeCbm: Number(result.summary?.inboundVolumeCbm ?? 0) } }
|
||||
}
|
||||
export async function getDomesticContainerInventory(inventoryId: number | string) {
|
||||
const response = await http.get<ApiEnvelope<InventoryDetail>, ApiEnvelope<InventoryDetail>>(`${basePath}/inventories/${inventoryId}`)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
export async function createDomesticContainerInbound(payload: CreateInboundRequest) {
|
||||
const response = await http.post<ApiEnvelope<CreateResponse>, ApiEnvelope<CreateResponse>>(`${basePath}/inbounds`, payload)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
export async function createDomesticContainerOutbound(payload: CreateOutboundRequest) {
|
||||
const response = await http.post<ApiEnvelope<CreateResponse>, ApiEnvelope<CreateResponse>>(`${basePath}/outbounds`, payload)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
Reference in New Issue
Block a user