This commit is contained in:
2026-08-19 09:42:12 +08:00
parent 80cfca5056
commit 0cd13f0b4d
18 changed files with 86 additions and 50 deletions
@@ -34,17 +34,19 @@ describe('inbound fee-detail API', () => {
expect(http.delete).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details/11', { params: { accountId: '100' } })
})
it('fails closed when a fee item has no recognized supplier category', async () => {
it('keeps an empty supplier category as null and rejects an unknown non-empty category', async () => {
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [
{ id: 31, feeTypeName: '拖车费', feeCode: 'TRUCKING', supplierCategory: 'TRUCKING', warehousePayable: true },
{ id: 32, feeTypeName: '未知费用', feeCode: 'UNMAPPED', supplierCategory: 'UNKNOWN', warehousePayable: true },
{ id: 33, feeTypeName: '缺少类别', feeCode: 'MISSING', warehousePayable: true },
] } })
await expect(listInboundFeeItemOptions()).resolves.toMatchObject([
{ id: 31, feeCode: 'TRUCKING', supplierCategory: 'TRUCKING' },
{ id: 32, feeCode: 'UNMAPPED', supplierCategory: null },
{ id: 33, feeCode: 'MISSING', supplierCategory: null },
])
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [
{ id: 32, feeTypeName: '未知费用', feeCode: 'UNMAPPED', supplierCategory: 'UNKNOWN', warehousePayable: true },
] } })
await expect(listInboundFeeItemOptions()).rejects.toThrow('Unsupported supplierCategory: UNKNOWN')
})
it('requests and retains only ACTIVE suppliers in the required category', async () => {
@@ -60,4 +62,19 @@ describe('inbound fee-detail API', () => {
page: 1, size: 200, category: 'TRUCKING', region: undefined, status: 'ACTIVE', keyword: undefined,
} })
})
it('requests all categories and retains every ACTIVE supplier when the category is empty', async () => {
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [
{ id: 41, tenantId: 0, name: '承运商A', category: 'TRUCKING', status: 'ACTIVE', version: 1, deleted: false },
{ id: 42, tenantId: 0, name: '停用承运商', category: 'TRUCKING', status: 'INACTIVE', version: 1, deleted: false },
{ id: 43, tenantId: 0, name: '报关行', category: 'CUSTOMS', status: 'ACTIVE', version: 1, deleted: false },
], page: 1, size: 200, total: 3, pages: 1 } })
await expect(listInboundFeeSupplierOptions(null)).resolves.toEqual([
{ id: '41', supplierName: '承运商A', category: 'TRUCKING' },
{ id: '43', supplierName: '报关行', category: 'CUSTOMS' },
])
expect(http.get).toHaveBeenCalledWith('/platform/v1/suppliers', { params: {
page: 1, size: 200, category: undefined, region: undefined, status: 'ACTIVE', keyword: undefined,
} })
})
})
@@ -54,7 +54,9 @@ export interface InboundFeeSupplierOption { id: string; supplierName: string; ca
const supplierCategories: SupplierCategory[] = ['BOOKING', 'CUSTOMS', 'TRUCKING', 'CERTIFICATE']
function supplierCategory(value: unknown): SupplierCategory | null {
return supplierCategories.includes(value as SupplierCategory) ? value as SupplierCategory : null
if (value == null || value === '') return null
if (supplierCategories.includes(value as SupplierCategory)) return value as SupplierCategory
throw new TypeError(`Unsupported supplierCategory: ${String(value)}`)
}
function basePath(inboundId: string) {
@@ -115,9 +117,9 @@ export async function listInboundFeeItemOptions() {
}))
}
export async function listInboundFeeSupplierOptions(category: SupplierCategory) {
const page = await listSuppliers({ status: 'ACTIVE', category, page: 1, size: 200 })
return page.records.filter((supplier) => supplier.status === 'ACTIVE' && supplier.category === category).map((supplier): InboundFeeSupplierOption => ({
export async function listInboundFeeSupplierOptions(category: SupplierCategory | null) {
const page = await listSuppliers({ status: 'ACTIVE', category: category ?? undefined, page: 1, size: 200 })
return page.records.filter((supplier) => supplier.status === 'ACTIVE' && (!category || supplier.category === category)).map((supplier): InboundFeeSupplierOption => ({
id: supplier.id, supplierName: supplier.name, category: supplier.category,
}))
}