46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { randomUUID } from 'node:crypto';
|
|
import { proposeCreditSchema } from '../src/b2b/credit.schemas';
|
|
|
|
describe('B2B credit proposal validation', () => {
|
|
const input = () => ({
|
|
accountId: randomUUID(),
|
|
currency: 'INR',
|
|
creditLimit: '1000.00',
|
|
netDays: 30,
|
|
rationale: 'Approved trade relationship',
|
|
idempotencyKey: randomUUID(),
|
|
});
|
|
|
|
it('accepts positive two-decimal limits and the net-day boundaries', () => {
|
|
expect(
|
|
proposeCreditSchema.safeParse({
|
|
...input(),
|
|
creditLimit: '0.01',
|
|
netDays: 1,
|
|
}).success,
|
|
).toBe(true);
|
|
expect(
|
|
proposeCreditSchema.safeParse({
|
|
...input(),
|
|
creditLimit: '99999999999999.99',
|
|
netDays: 180,
|
|
}).success,
|
|
).toBe(true);
|
|
});
|
|
|
|
it.each(['0.00', '-1.00', '1.001', '01.00', '100000000000000.00'])(
|
|
'rejects invalid credit limit %s',
|
|
(creditLimit) => {
|
|
expect(
|
|
proposeCreditSchema.safeParse({ ...input(), creditLimit }).success,
|
|
).toBe(false);
|
|
},
|
|
);
|
|
|
|
it.each([0, 181, 1.5])('rejects invalid net days %s', (netDays) => {
|
|
expect(proposeCreditSchema.safeParse({ ...input(), netDays }).success).toBe(
|
|
false,
|
|
);
|
|
});
|
|
});
|