Files
admin-web/src/modules/loading-lists/api/containerFees.test.ts
T

72 lines
6.4 KiB
TypeScript
Raw Normal View History

2026-08-12 16:31:46 +08:00
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
2026-08-20 18:02:24 +08:00
import { adjustContainerFee, approveContainerFee, createContainerFee, listContainerCostDetails, listContainerFeeSupplierOptions, listContainerFees, rejectContainerFee, uploadContainerFeePaymentVoucher, voidContainerFee } from './containerFees'
2026-08-19 09:14:35 +08:00
import { listSuppliers } from '@/modules/suppliers'
vi.mock('@/modules/suppliers', () => ({ listSuppliers: vi.fn() }))
2026-08-12 16:31:46 +08:00
describe('container fee API', () => {
beforeEach(() => vi.restoreAllMocks())
it('passes accountId and exact controller DTOs', async () => {
const get = vi.spyOn(http, 'get').mockResolvedValue({ code: '200', data: [] })
2026-08-20 18:02:24 +08:00
const post = vi.spyOn(http, 'post').mockResolvedValue({ code: '200', data: { id: 3, loadingPlanId: 9, containerBookingId: 99, feeItemId: 7, feeItemNameSnapshot: '操作费', direction: 'PAYABLE', supplierId: 41, supplierName: '承运商A', supplierCategory: 'TRUCKING', settlementMode: 'DIRECT_PAID', paidAt: '2026-08-12T10:30:00', paymentMethod: 'BANK_TRANSFER', paymentReferenceNo: 'BANK-7', paymentVoucherFileIds: [9001], businessDate: '2026-08-12', amount: 100, currency: 'CNY', reviewStatus: 'PENDING', sourceStatus: 'ACTIVE', sourceVersion: 1 } })
const values = { feeItemId: '7', direction: 'PAYABLE' as const, supplierId: '41', settlementMode: 'DIRECT_PAID' as const, paidAt: '2026-08-12T10:30:00', paymentMethod: 'BANK_TRANSFER' as const, paymentReferenceNo: 'BANK-7', paymentVoucherFileIds: ['9001'], businessDate: '2026-08-12', amount: 100, currency: 'CNY' as const, remark: null }
2026-08-12 17:29:35 +08:00
await listContainerFees('9', '11'); const created = await createContainerFee('9', '11', values)
2026-08-12 16:31:46 +08:00
await approveContainerFee('9', '11', '3'); await rejectContainerFee('9', '11', '3', '资料不全')
2026-08-18 17:40:40 +08:00
await adjustContainerFee('9', '11', '3', { expectedSourceVersion: 2, businessDate: '2026-08-13', amount: 120 }); await voidContainerFee('9', '11', '3', 3)
2026-08-12 16:31:46 +08:00
expect(get).toHaveBeenCalledWith('/platform/v1/loading-plans/9/fee-details', { params: { accountId: '11' } })
expect(post).toHaveBeenCalledWith('/platform/v1/loading-plans/9/fee-details', values, { params: { accountId: '11' } })
2026-08-18 17:40:40 +08:00
expect(post).toHaveBeenCalledWith('/platform/v1/loading-plans/9/fee-details/3/adjust', { expectedSourceVersion: 2, businessDate: '2026-08-13', amount: 120 }, { params: { accountId: '11' } })
2026-08-12 16:31:46 +08:00
expect(post).toHaveBeenCalledWith('/platform/v1/loading-plans/9/fee-details/3/void', { expectedSourceVersion: 3 }, { params: { accountId: '11' } })
2026-08-20 18:02:24 +08:00
expect(created).toMatchObject({ id: '3', loadingPlanId: '9', containerBookingId: '99', direction: 'PAYABLE', supplierId: '41', supplierName: '承运商A', supplierCategory: 'TRUCKING', settlementMode: 'DIRECT_PAID', paymentVoucherFileIds: ['9001'] })
})
it('uploads a payment voucher in the current customer scope and rejects a mismatched echo', async () => {
const post = vi.spyOn(http, 'post').mockResolvedValueOnce({ code: '200', data: { fileId: 9001, tenantId: 11, fileName: '付款凭证.png' } })
await expect(uploadContainerFeePaymentVoucher('11', new File(['x'], '付款凭证.png'))).resolves.toEqual({ fileId: '9001', fileName: '付款凭证.png' })
expect(post).toHaveBeenCalledWith('/platform/finance/v1/vouchers', expect.any(FormData), { params: { customerId: '11' }, headers: { 'Content-Type': 'multipart/form-data' } })
post.mockResolvedValueOnce({ code: '200', data: { fileId: 9002, tenantId: 12, fileName: '错客户.png' } })
await expect(uploadContainerFeePaymentVoucher('11', new File(['x'], '错客户.png'))).rejects.toThrow('付款凭证与当前客户不匹配')
2026-08-12 16:31:46 +08:00
})
2026-08-19 09:14:35 +08:00
it('loads only ACTIVE suppliers in the requested category', async () => {
vi.mocked(listSuppliers).mockResolvedValue({ records: [
{ id: '41', name: '承运商A', status: 'ACTIVE', category: 'TRUCKING' },
{ id: '42', name: '停用承运商', status: 'INACTIVE', category: 'TRUCKING' },
{ id: '43', name: '报关行', status: 'ACTIVE', category: 'CUSTOMS' },
], page: 1, size: 200, total: 3, pages: 1 } as never)
await expect(listContainerFeeSupplierOptions('TRUCKING')).resolves.toEqual([{ id: '41', supplierName: '承运商A', category: 'TRUCKING' }])
expect(listSuppliers).toHaveBeenCalledWith({ status: 'ACTIVE', category: 'TRUCKING', page: 1, size: 200 })
2026-08-12 16:58:52 +08:00
})
2026-08-19 09:42:12 +08:00
it('loads every ACTIVE supplier without a category filter when the fee item category is empty', async () => {
vi.mocked(listSuppliers).mockResolvedValue({ records: [
{ id: '41', name: '承运商A', status: 'ACTIVE', category: 'TRUCKING' },
{ id: '42', name: '停用承运商', status: 'INACTIVE', category: 'TRUCKING' },
{ id: '43', name: '报关行', status: 'ACTIVE', category: 'CUSTOMS' },
], page: 1, size: 200, total: 3, pages: 1 } as never)
await expect(listContainerFeeSupplierOptions(null)).resolves.toEqual([
{ id: '41', supplierName: '承运商A', category: 'TRUCKING' },
{ id: '43', supplierName: '报关行', category: 'CUSTOMS' },
])
expect(listSuppliers).toHaveBeenCalledWith({ status: 'ACTIVE', category: undefined, page: 1, size: 200 })
})
2026-08-12 16:31:46 +08:00
it('reads allocation rows from Finance and never calculates them', async () => {
const get = vi.spyOn(http, 'get')
2026-08-12 17:29:35 +08:00
.mockResolvedValueOnce({ code: '200', data: [{ id: 81, customerId: 11, containerId: 99 }, { id: 82, customerId: 11, containerId: 100 }] })
.mockResolvedValueOnce({ code: '200', data: { cost: { id: 81, customerId: 11, containerId: 99, supplierName: '承运商A', feeItemName: '拖车费', payableAmount: 300 }, allocations: [{ id: 1, orderId: 8, volumeCbm: 2, totalVolumeCbm: 5, allocationRate: 0.4, allocatedAmount: 120 }] } })
2026-08-12 16:31:46 +08:00
const result = await listContainerCostDetails('11', '99')
expect(result[0]).toMatchObject({ supplierName: '承运商A', allocations: [{ orderId: '8', allocatedAmount: 120 }] })
expect(get).toHaveBeenNthCalledWith(2, '/platform/finance/v1/cost-entries/81', { params: { customerId: '11' } })
2026-08-12 17:29:35 +08:00
expect(get).toHaveBeenCalledTimes(2)
})
it('fails closed when Finance detail does not echo the selected customer and container', async () => {
vi.spyOn(http, 'get')
.mockResolvedValueOnce({ code: '200', data: [{ id: 81, customerId: 11, containerId: 99 }] })
.mockResolvedValueOnce({ code: '200', data: { cost: { id: 81, customerId: 12, containerId: 99 }, allocations: [] } })
await expect(listContainerCostDetails('11', '99')).rejects.toThrow('Finance 成本详情与柜次或客户上下文不一致')
2026-08-12 16:31:46 +08:00
})
})