@@ -0,0 +1,35 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import vectors from '../Fixtures/requisition-estimates.json';
|
||||
import { requisitionEstimate } from '@/lib/requisition-estimate';
|
||||
|
||||
test.each(vectors)(
|
||||
'preserves exact native line rounding: $minor',
|
||||
({ lines, minor }) => {
|
||||
expect(requisitionEstimate(lines)).toBe(minor);
|
||||
},
|
||||
);
|
||||
|
||||
test.each(['', '-1', '1e2', '0', '1.0001', '1000001', 'x'])(
|
||||
'keeps invalid or incomplete quantity indeterminate: %s',
|
||||
(quantity) => {
|
||||
expect(
|
||||
requisitionEstimate([{ quantity, unit_price: '1', tax_rate: '0' }]),
|
||||
).toBeNull();
|
||||
},
|
||||
);
|
||||
|
||||
test('requires complete valid lines while accepting leading zeros and calculated zero', () => {
|
||||
expect(requisitionEstimate([])).toBeNull();
|
||||
for (const field of ['unit_price', 'tax_rate']) {
|
||||
expect(
|
||||
requisitionEstimate([
|
||||
{ quantity: '1', unit_price: '1', tax_rate: '0', [field]: '' },
|
||||
]),
|
||||
).toBeNull();
|
||||
}
|
||||
expect(
|
||||
requisitionEstimate([
|
||||
{ quantity: '000.001', unit_price: '00.01', tax_rate: '00.00' },
|
||||
]),
|
||||
).toBe('0');
|
||||
});
|
||||
Reference in New Issue
Block a user