优化
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { http } from './http'
|
||||
import { overseasHttp } from './overseasHttp'
|
||||
import { getLoadingAssociationSummary, getOverseasInboundCodeRelationship, getPlatformInboundCodeAssociation } from './inboundCodeRelations'
|
||||
|
||||
vi.mock('./http', async (original) => ({ ...(await original<typeof import('./http')>()), http: { get: vi.fn() } }))
|
||||
vi.mock('./overseasHttp', () => ({ overseasHttp: { get: vi.fn() } }))
|
||||
|
||||
describe('inbound-code relationship APIs', () => {
|
||||
beforeEach(() => vi.clearAllMocks())
|
||||
|
||||
it('uses the frozen domestic and overseas read models and encodes the business code', async () => {
|
||||
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { inboundCode: 'IN/01', orderNo: 'ORD-1' } })
|
||||
vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', data: { inboundCode: 'IN/01', found: false, taillegOrders: [], inboundPlans: [], palletCodes: [], inventory: [] } })
|
||||
await getPlatformInboundCodeAssociation('IN/01')
|
||||
await getLoadingAssociationSummary('IN/01')
|
||||
await getOverseasInboundCodeRelationship('IN/01')
|
||||
expect(http.get).toHaveBeenCalledWith('/platform/v1/orders/first-leg/inbound-code-associations/IN%2F01')
|
||||
expect(http.get).toHaveBeenCalledWith('/platform/v1/first-leg/loading-associations/summary', { params: { inboundCode: 'IN/01' } })
|
||||
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/inventory/inbound-code-relationships/IN%2F01')
|
||||
})
|
||||
|
||||
it('does not accept customer or internal ids as lookup parameters', () => {
|
||||
const source = `${getPlatformInboundCodeAssociation}${getLoadingAssociationSummary}${getOverseasInboundCodeRelationship}`
|
||||
expect(source).not.toMatch(/customerId|inboundId|orderId|warehouseId/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,67 @@
|
||||
import { http, unwrapApiResponse, type ApiEnvelope } from './http'
|
||||
import { overseasHttp } from './overseasHttp'
|
||||
|
||||
export interface PlatformInboundCodeAssociation {
|
||||
inboundCode: string
|
||||
orderNo: string
|
||||
orderStatus?: string | null
|
||||
orderId: string
|
||||
customerId: string
|
||||
customerName: string
|
||||
destinationType?: string | null
|
||||
destinationCountryCode?: string | null
|
||||
destinationWarehouseId?: string | null
|
||||
destinationWarehouseCode?: string | null
|
||||
destinationWarehouseName?: string | null
|
||||
}
|
||||
|
||||
export interface OverseasInboundCodeRelationship {
|
||||
inboundCode: string
|
||||
found: boolean
|
||||
customer: { customerId: string; customerName: string } | null
|
||||
overseasWarehouse: { warehouseId: string; warehouseCode: string; warehouseName: string } | null
|
||||
overseasReceivingStatus?: string | null
|
||||
taillegOrders: Array<{ orderNo: string; orderStatus?: string | null }>
|
||||
inboundPlans: Array<{ planNo: string; planStatus?: string | null; receivingStatus?: string | null }>
|
||||
palletCodes: string[]
|
||||
inventory: Array<{ skuCode: string; productNameZh?: string | null; productNameEn?: string | null; packageCount: number }>
|
||||
}
|
||||
|
||||
export interface LoadingAssociationSummary {
|
||||
inboundId: string
|
||||
inboundCode: string
|
||||
orderNo?: string | null
|
||||
loadingPlanId?: string | null
|
||||
loadingPlanNo?: string | null
|
||||
containerBookingId?: string | null
|
||||
cabinetNo?: string | null
|
||||
containerNo?: string | null
|
||||
loadingStatus?: string | null
|
||||
taskId?: string | null
|
||||
pdaTaskStatus?: string | null
|
||||
coLoadGroupId?: string | null
|
||||
coLoadGroupNo?: string | null
|
||||
items: Array<{ itemId: string }>
|
||||
}
|
||||
|
||||
export async function getPlatformInboundCodeAssociation(inboundCode: string) {
|
||||
const response = await http.get<ApiEnvelope<PlatformInboundCodeAssociation>, ApiEnvelope<PlatformInboundCodeAssociation>>(
|
||||
`/platform/v1/orders/first-leg/inbound-code-associations/${encodeURIComponent(inboundCode)}`,
|
||||
)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
export async function getLoadingAssociationSummary(inboundCode: string) {
|
||||
const response = await http.get<ApiEnvelope<LoadingAssociationSummary>, ApiEnvelope<LoadingAssociationSummary>>(
|
||||
'/platform/v1/first-leg/loading-associations/summary',
|
||||
{ params: { inboundCode } },
|
||||
)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
export async function getOverseasInboundCodeRelationship(inboundCode: string) {
|
||||
const response = await overseasHttp.get<ApiEnvelope<OverseasInboundCodeRelationship>, ApiEnvelope<OverseasInboundCodeRelationship>>(
|
||||
`/platform/v1/last-leg/inventory/inbound-code-relationships/${encodeURIComponent(inboundCode)}`,
|
||||
)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
Reference in New Issue
Block a user