import { withdrawalSpanOf } from './withdrawal-span'; const treatment = (overrides: Record = {}) => ({ id: 't1', colonyId: 'c1', product: 'Oxuvar', date: new Date('2026-07-31T00:00:00.000Z'), startDate: null, endDate: null, withdrawalPeriodDays: 20, ...overrides, }); describe('withdrawalSpanOf', () => { it('is the withdrawal window of a treatment with withdrawal days', () => { expect(withdrawalSpanOf(treatment())).toEqual({ treatmentId: 't1', colonyId: 'c1', product: 'Oxuvar', fromDay: '2026-07-31', untilDay: '2026-08-20', }); }); it('is null without withdrawal days', () => { expect( withdrawalSpanOf(treatment({ withdrawalPeriodDays: null })), ).toBeNull(); }); it('is null for a window of zero days, which covers no day to show', () => { expect(withdrawalSpanOf(treatment({ withdrawalPeriodDays: 0 }))).toBeNull(); }); it('is a span of one day for one withdrawal day', () => { expect(withdrawalSpanOf(treatment({ withdrawalPeriodDays: 1 }))).toEqual( expect.objectContaining({ fromDay: '2026-07-31', untilDay: '2026-08-01', }), ); }); });