manicanldes-backend/test/b2b-quote-command.spec.ts

49 lines
1.5 KiB
TypeScript

import { randomUUID } from 'node:crypto';
import {
assertQuoteLimits,
prepareQuoteCommand,
} from '../src/b2b/quote-command';
describe('B2B quotation command', () => {
const accountId = randomUUID();
const priceListId = randomUUID();
const first = randomUUID();
const second = randomUUID();
const base = {
accountId,
priceListId,
expiresAt: '2026-12-01T10:00:00+05:30',
customerReference: null,
idempotencyKey: randomUUID(),
lines: [
{ variantId: first, quantity: 10 },
{ variantId: second, quantity: 5 },
],
};
it('hashes equivalent expiry offsets and line order identically', () => {
const original = prepareQuoteCommand(base);
const reordered = prepareQuoteCommand({
...base,
expiresAt: '2026-12-01T04:30:00Z',
lines: [...base.lines].reverse(),
});
expect(reordered.requestHash).toBe(original.requestHash);
expect(reordered.lines).toEqual(original.lines);
});
it('rejects expired, distant, and oversized monetary quotes', () => {
expect(() =>
assertQuoteLimits(new Date(Date.now() - 1000), ['1.00']),
).toThrow(expect.objectContaining({ code: 'B2B_QUOTE_EXPIRY_INVALID' }));
expect(() =>
assertQuoteLimits(new Date(Date.now() + 91 * 86400000), ['1.00']),
).toThrow(expect.objectContaining({ code: 'B2B_QUOTE_EXPIRY_INVALID' }));
expect(() =>
assertQuoteLimits(new Date(Date.now() + 86400000), [
'10000000000000000.00',
]),
).toThrow(expect.objectContaining({ code: 'B2B_QUOTE_AMOUNT_LIMIT' }));
});
});