/** * The settings screen's price example must match the checkout * (CheckoutQuoteService::round_price in PHP, tests/CheckoutQuoteServiceTest.php). */ import { markedUpPrice, roundPrice, } from '../features/settings/utils/checkoutRatesPrice'; describe('checkout rates price example', () => { it('marks up the ticket example: £4.20 + 10% + 50p = £5.12', () => { expect(markedUpPrice(4.2, 10, 0.5, 'none')).toBe(5.12); }); it('marks up the gross price the same way', () => { expect(markedUpPrice(5.04, 10, 0.5, 'none')).toBe(6.04); }); it('takes a reduction off: £10 - 10% - 50p = £8.50, never below zero', () => { expect(markedUpPrice(10, -10, -0.5, 'none')).toBe(8.5); expect(markedUpPrice(10, -10, -0.5, 'end_99')).toBe(8.99); expect(markedUpPrice(3, -50, -5, 'none')).toBe(0); }); it('rounds like the checkout', () => { expect(roundPrice(5.12, 'up_10p')).toBe(5.2); expect(roundPrice(5.1, 'up_10p')).toBe(5.1); expect(roundPrice(5.12, 'up_pound')).toBe(6); expect(roundPrice(5, 'up_pound')).toBe(5); expect(roundPrice(5.12, 'end_99')).toBe(5.99); expect(roundPrice(5.99, 'end_99')).toBe(5.99); expect(roundPrice(6, 'end_99')).toBe(6.99); }); it('does not let float noise push a price up a step', () => { expect(roundPrice(5.1000000001, 'up_10p')).toBe(5.1); }); });