89 lines
6.5 KiB
TypeScript
89 lines
6.5 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { http } from '@/shared/api/http'
|
|
import {
|
|
adjustInboundFeeDetail, createInboundFeeDetail, deleteInboundFeeDetail, listInboundFeeDetails,
|
|
listInboundFeeItemOptions, listInboundFeeSupplierOptions, reviewInboundFeeDetail,
|
|
updateInboundFeeDetail, uploadInboundFeePaymentVoucher, voidInboundFeeDetail, type SaveInboundFeeDetailRequest,
|
|
} from './inboundFeeDetails'
|
|
|
|
vi.mock('@/shared/api/http', async () => {
|
|
const actual = await vi.importActual<typeof import('@/shared/api/http')>('@/shared/api/http')
|
|
return { ...actual, http: { get: vi.fn(), post: vi.fn(), put: vi.fn(), delete: vi.fn() } }
|
|
})
|
|
|
|
describe('inbound fee-detail API', () => {
|
|
beforeEach(() => vi.clearAllMocks())
|
|
it.each(['', ' ', 'null', 'undefined'])('rejects invalid inboundId %j without issuing HTTP', async (inboundId) => {
|
|
await expect(listInboundFeeDetails('100', inboundId)).rejects.toThrow('inboundId is required')
|
|
expect(http.get).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('maps the complete write contract and optimistic version', async () => {
|
|
const payload: SaveInboundFeeDetailRequest = { feeItemId: '31', direction: 'PAYABLE', businessDate: '2026-08-12', unitPrice: 12.5, currency: 'CNY', amount: 125, supplierId: '41', settlementMode: 'DIRECT_PAID', paidAt: '2026-08-12T10:30:00', paymentMethod: 'BANK_TRANSFER', paymentReferenceNo: 'BANK-31', paymentVoucherFileIds: ['9001'], remark: '验收' }
|
|
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: [] })
|
|
vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: null })
|
|
vi.mocked(http.put).mockResolvedValue({ code: '200', message: 'success', data: payload })
|
|
vi.mocked(http.delete).mockResolvedValue({ code: '200', message: 'success', data: null })
|
|
await listInboundFeeDetails('100', '88'); await createInboundFeeDetail('100', '88', payload)
|
|
await updateInboundFeeDetail('100', '88', '11', payload); await reviewInboundFeeDetail('100', '88', '11', 'approve')
|
|
await reviewInboundFeeDetail('100', '88', '11', 'reject', '金额有误'); await adjustInboundFeeDetail('100', '88', '11', 3, payload)
|
|
await voidInboundFeeDetail('100', '88', '11', 3); await deleteInboundFeeDetail('100', '88', '11')
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details', { params: { accountId: '100' } })
|
|
expect(http.post).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details/11/adjust', payload, { params: { accountId: '100', expectedSourceVersion: 3 } })
|
|
expect(http.post).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details/11/void', { expectedSourceVersion: 3 }, { params: { accountId: '100' } })
|
|
expect(http.delete).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details/11', { params: { accountId: '100' } })
|
|
})
|
|
|
|
it('reuses the scoped FINANCE_VOUCHER upload and fails closed on customer mismatch', async () => {
|
|
vi.mocked(http.post).mockResolvedValueOnce({ code: '200', data: { fileId: 9001, tenantId: 100, fileName: '付款凭证.pdf' } })
|
|
await expect(uploadInboundFeePaymentVoucher('100', new File(['x'], '付款凭证.pdf'))).resolves.toEqual({ fileId: '9001', fileName: '付款凭证.pdf' })
|
|
expect(http.post).toHaveBeenCalledWith('/platform/finance/v1/vouchers', expect.any(FormData), { params: { customerId: '100' }, headers: { 'Content-Type': 'multipart/form-data' } })
|
|
vi.mocked(http.post).mockResolvedValueOnce({ code: '200', data: { fileId: 9002, tenantId: 101, fileName: '错客户.pdf' } })
|
|
await expect(uploadInboundFeePaymentVoucher('100', new File(['x'], '错客户.pdf'))).rejects.toThrow('付款凭证与当前客户不匹配')
|
|
})
|
|
|
|
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', defaultPrice: '60.25', supplierCategory: 'TRUCKING', warehousePayable: true },
|
|
{ id: 33, feeTypeName: '缺少类别', feeCode: 'MISSING', warehousePayable: true },
|
|
] } })
|
|
await expect(listInboundFeeItemOptions()).resolves.toMatchObject([
|
|
{ id: 31, feeCode: 'TRUCKING', defaultPrice: 60.25, supplierCategory: 'TRUCKING' },
|
|
{ id: 33, feeCode: 'MISSING', defaultPrice: null, 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 () => {
|
|
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('TRUCKING')).resolves.toEqual([
|
|
{ id: '41', supplierName: '承运商A', category: 'TRUCKING' },
|
|
])
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/suppliers', { params: {
|
|
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,
|
|
} })
|
|
})
|
|
})
|