Files
admin-web/src/modules/overseas-master-data/api/tripBookings.test.ts
T

22 lines
2.3 KiB
TypeScript

import { beforeEach, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import { listTripBookingQuoteCandidates, normalizeBooking, type WireBooking } from './tripBookings'
vi.mock('@/shared/api/http', async original => ({ ...(await original<typeof import('@/shared/api/http')>()), http: { get: vi.fn() } }))
const source = { quoteNo: 'FQ-1', recordVersion: '9007199254740993', priceItem: 'LOOSE_DELIVERY' as const, customerId: '9', customerName: '客户', originCity: 'LA', destinationCode: 'ONT8', distanceMiles: '30', currency: 'USD' as const, priceBasis: 'PALLET' as const, quotedUnitPrice: '0.00', validFrom: '2026-10-01', validTo: '2026-10-31', effectiveOn: '2026-10-03' }
beforeEach(() => vi.clearAllMocks())
it('uses trip-scoped candidate criteria without accepting browser-computed city or date', async () => {
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [source], page: '1', size: '20', total: '1', pages: '1' } })
const criteria = { customerId: '9', destinationKey: 'FBA:ONT8', currency: 'USD' as const, priceBasis: 'PALLET' as const }
const value = await listTripBookingQuoteCandidates('TR-1', criteria)
expect(http.get).toHaveBeenCalledExactlyOnceWith('/platform/v1/last-leg/fleet/trips/TR-1/bookings/quote-candidates', { params: criteria })
expect(value.records[0]).toMatchObject({ recordVersion: source.recordVersion, quotedUnitPrice: 0 })
})
it('normalizes quote source without overwriting negotiated price and handles manual absence', () => {
const row: WireBooking = { bookingNo: 'FB-1', tripNo: 'TR-1', customerId: '9', customerCode: '00009', customerName: '客户', status: 'DRAFT', destinationLabel: 'ONT8', agreedAmount: '25.00', recordVersion: '1', updatedAt: '', incomingNo: null, dispatchNo: null, receipt: null, quoteSource: source,
cargo: { destinationKey: 'FBA:ONT8', cargoName: null, packageCount: '1', palletSpaces: '2', weightKg: null, volumeCbm: null, priceBasis: 'PALLET', unitPrice: '12.50', currency: 'USD', contactName: null, contactPhone: null, remark: null } }
const value = normalizeBooking(row)
expect(value.quoteSource).toMatchObject({ quotedUnitPrice: 0, recordVersion: source.recordVersion })
expect(value.cargo.unitPrice).toBe(12.5); expect(value.agreedAmount).toBe(25)
expect(normalizeBooking({ ...row, quoteSource: undefined }).quoteSource).toBeNull()
})