15 lines
1.2 KiB
TypeScript
15 lines
1.2 KiB
TypeScript
import { expect, it } from 'vitest'
|
|
import { fleetQuoteCsvHeader, parseFleetQuoteCsv } from './fleetQuoteCsv'
|
|
const csv = (row: string) => '\uFEFF' + fleetQuoteCsvHeader.join(',') + '\r\n' + row
|
|
it('preserves zero, missing prices, quoted cities and multiline notes', () => {
|
|
const rows = parseFleetQuoteCsv(csv('"Los Angeles, CA",ONT8,10.5,USD,0,,20,2026-01-01,2026-12-31,"first\nsecond"'), 'SALE', '90071992547409931')
|
|
expect(rows[0]).toMatchObject({ kind: 'SALE', partyId: '90071992547409931', originCity: 'Los Angeles, CA', selfPickupPrice: 0, fullDeliveryPrice: null, looseDeliveryPrice: 20, remark: 'first\nsecond' })
|
|
})
|
|
it.each(['LA,ONT8,10,USD,,,,2026-01-01,2026-12-31,', 'LA,ONT8,10,USD,1,,,2026-02-30,2026-12-31,', 'LA,ONT8,10,USD,1,,,2026-12-31,2026-01-01,', 'LA,ONT8,10,USD,-1,,,2026-01-01,2026-12-31,'])('rejects invalid data before submission: %s', row => {
|
|
expect(() => parseFleetQuoteCsv(csv(row), 'PURCHASE', '1')).toThrow('第2行')
|
|
})
|
|
it('rejects truncated CSV and oversized batch', () => {
|
|
expect(() => parseFleetQuoteCsv(csv('"LA'), 'SALE', '1')).toThrow('引号')
|
|
expect(() => parseFleetQuoteCsv(csv(Array(201).fill('LA,ONT8,10,USD,1,,,2026-01-01,2026-12-31,').join('\n')), 'SALE', '1')).toThrow('200')
|
|
})
|