manicanldes-backend/test/campaign-discount-policy.sp...

42 lines
1.4 KiB
TypeScript

import { campaignEligibleSubtotal } from '../src/coupons/campaign-coupon-policy';
import { discountFor } from '../src/checkout/money';
describe('campaign collection discount base', () => {
const lines = [
{ variantId: 'eligible', lineTotal: '10.10' },
{ variantId: 'outside', lineTotal: '89.90' },
{ variantId: 'eligible-second', lineTotal: '0.01' },
];
it('counts only collection merchandise with exact minor-unit precision', () => {
expect(
campaignEligibleSubtotal(lines, new Set(['eligible', 'eligible-second'])),
).toBe(1011n);
});
it('rounds a percentage on the eligible subtotal rather than the whole cart', () => {
const subtotal = campaignEligibleSubtotal(
lines,
new Set(['eligible', 'eligible-second']),
);
expect(
discountFor(subtotal, {
kind: 'PERCENT',
amount: null,
percentBps: 5000,
}),
).toBe(506n);
});
it('caps a fixed discount at the eligible merchandise value', () => {
const subtotal = campaignEligibleSubtotal(lines, new Set(['eligible']));
expect(
discountFor(subtotal, {
kind: 'FIXED',
amount: '20.00',
percentBps: null,
}),
).toBe(1010n);
});
it('returns zero when the cart contains no campaign collection variants', () => {
expect(campaignEligibleSubtotal(lines, new Set())).toBe(0n);
});
});