|
| 1 | +import { |
| 2 | + businessMorningAfter, |
| 3 | + isCampaignSendWindow, |
| 4 | +} from './campaign-schedule.ts'; |
| 5 | + |
| 6 | +describe('Pacific campaign calendar', () => { |
| 7 | + it.each([ |
| 8 | + ['2026-09-07T12:00:00Z', 1, '2026-09-08T14:00:00.000Z'], |
| 9 | + ['2026-09-11T18:00:00Z', 1, '2026-09-14T14:00:00.000Z'], |
| 10 | + ['2026-09-12T18:00:00Z', 1, '2026-09-14T14:00:00.000Z'], |
| 11 | + ['2026-09-13T18:00:00Z', 1, '2026-09-14T14:00:00.000Z'], |
| 12 | + ['2026-09-08T14:01:00Z', 3, '2026-09-11T14:00:00.000Z'], |
| 13 | + ['2026-09-11T14:01:00Z', 5, '2026-09-18T14:00:00.000Z'], |
| 14 | + ['2026-03-06T15:01:00Z', 1, '2026-03-09T14:00:00.000Z'], |
| 15 | + ['2026-10-30T14:01:00Z', 1, '2026-11-02T15:00:00.000Z'], |
| 16 | + ['2026-12-31T15:01:00Z', 1, '2027-01-01T15:00:00.000Z'], |
| 17 | + ['2026-09-08T01:00:00Z', 1, '2026-09-08T14:00:00.000Z'], |
| 18 | + ])('schedules %s plus %s weekdays', (input, days, expected) => { |
| 19 | + expect(businessMorningAfter(new Date(input), days).toISOString()).toBe( |
| 20 | + expected |
| 21 | + ); |
| 22 | + }); |
| 23 | + it.each([ |
| 24 | + ['2026-09-08T13:59:59Z', false], |
| 25 | + ['2026-09-08T14:00:00Z', true], |
| 26 | + ['2026-09-08T14:59:59Z', true], |
| 27 | + ['2026-09-08T15:00:00Z', false], |
| 28 | + ['2026-09-12T14:00:00Z', false], |
| 29 | + ['2026-11-02T15:00:00Z', true], |
| 30 | + ])('checks the weekday morning send window %s', (input, expected) => { |
| 31 | + expect(isCampaignSendWindow(new Date(input))).toBe(expected); |
| 32 | + }); |
| 33 | + it('rejects invalid dates and business-day offsets', () => { |
| 34 | + expect(() => businessMorningAfter(new Date('invalid'), 1)).toThrow(); |
| 35 | + for (const offset of [0, -1, 1.5, Infinity]) |
| 36 | + expect(() => businessMorningAfter(new Date(), offset)).toThrow(); |
| 37 | + expect(() => isCampaignSendWindow(new Date('invalid'))).toThrow(); |
| 38 | + }); |
| 39 | +}); |
0 commit comments