import { materialContribution } from '../src/costing/contribution-math'; import { contributionQuerySchema } from '../src/costing/profitability.schemas'; it('uses exact signed money, ceiling break-even and zero-denominator handling', () => { expect(materialContribution('0.19', 2, '0.09')).toMatchObject({ materialContribution: '-0.01', breakEvenUnitNetPrice: '0.10', contributionRateBps: '-556', }); expect(materialContribution('0.19', 2, '0.10')).toMatchObject({ materialContribution: '0.01', contributionRateBps: '500', }); expect(materialContribution('61.00', 20, '0.00')).toMatchObject({ comparisonNetValue: '0.00', materialContribution: '-61.00', contributionRateBps: null, }); expect(materialContribution('21.00', 0, '5.00')).toMatchObject({ comparisonState: 'NO_GOOD_OUTPUT', breakEvenUnitNetPrice: null, contributionRateBps: null, }); expect( materialContribution('0.01', 1000000, '9999999999.99').comparisonNetValue, ).toBe('9999999999990000.00'); expect(() => materialContribution('1.00', -1, '1.00')).toThrow(); expect(() => materialContribution('1.00', 1.5, '1.00')).toThrow(); }); it('validates supported currencies and explicit bounded net-price strings', () => { expect( contributionQuerySchema.safeParse({ currency: 'INR', unitNetPrice: '0.00' }) .success, ).toBe(true); for (const price of ['-1.00', '1', '01.00', '0.001', '10000000000.00']) expect( contributionQuerySchema.safeParse({ currency: 'INR', unitNetPrice: price, }).success, ).toBe(false); });