24 lines
2.4 KiB
TypeScript
24 lines
2.4 KiB
TypeScript
import { beforeEach, expect, it, vi } from 'vitest'
|
|
import { http } from '@/shared/api/http'
|
|
import { listFleetSaleQuoteCandidates, fleetQuoteReference, type FleetSaleQuoteCriteria } from './fleetQuoteCandidates'
|
|
vi.mock('@/shared/api/http', async original => ({ ...(await original<typeof import('@/shared/api/http')>()), http: { get: vi.fn() } }))
|
|
const criteria: FleetSaleQuoteCriteria = { customerId: '90071992547409931', originCity: 'LA', destinationCode: 'ONT8', currency: 'USD', effectiveOn: '2026-10-03', priceBasis: 'PALLET', page: 1, size: 20 }
|
|
const snapshot = { quoteNo: 'FQ-SOURCE', recordVersion: '90071992547409932', priceItem: 'LOOSE_DELIVERY', customerId: criteria.customerId, customerName: '委托客户', originCity: 'LA', destinationCode: 'ONT8', distanceMiles: '10', currency: 'USD', priceBasis: 'PALLET', quotedUnitPrice: '0.00', validFrom: '2026-10-01', validTo: '2026-10-31', effectiveOn: criteria.effectiveOn }
|
|
beforeEach(() => vi.clearAllMocks())
|
|
it('keeps source identity/version and explicit zero, without constructing a booking write or total', async () => {
|
|
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [snapshot], page: '1', size: '20', total: '1', pages: '1' } })
|
|
const result = await listFleetSaleQuoteCandidates(criteria)
|
|
expect(result.records[0]).toMatchObject({ recordVersion: snapshot.recordVersion, customerId: criteria.customerId, quotedUnitPrice: 0, distanceMiles: 10 })
|
|
expect(fleetQuoteReference(result.records[0]!)).toEqual({ quoteNo: snapshot.quoteNo, recordVersion: snapshot.recordVersion, priceItem: 'LOOSE_DELIVERY' })
|
|
expect(http.get).toHaveBeenCalledExactlyOnceWith('/platform/v1/last-leg/fleet/quotes/sale-candidates', { params: criteria })
|
|
expect(result.records[0]).not.toHaveProperty('agreedAmount')
|
|
})
|
|
it('does not turn an unknown price into an eligible zero-price candidate', async () => {
|
|
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [{ ...snapshot, quotedUnitPrice: null }], page: 1, size: 20, total: 1, pages: 1 } })
|
|
await expect(listFleetSaleQuoteCandidates(criteria)).rejects.toThrow('金额格式无效')
|
|
})
|
|
it('surfaces permission errors instead of returning an empty successful list', async () => {
|
|
vi.mocked(http.get).mockResolvedValue({ code: 'A0403', message: '无报价读取权限', requestId: 'candidate-test-request' })
|
|
await expect(listFleetSaleQuoteCandidates(criteria)).rejects.toMatchObject({ code: 'A0403', requestId: 'candidate-test-request' })
|
|
})
|