From 1a2ee080efd4e3df2e216e84929c45952dbc3d1f Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 1 Apr 2026 13:13:48 +0100 Subject: [PATCH] test: add unit test --- test/unit/ics.spec.ts | 84 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/unit/ics.spec.ts b/test/unit/ics.spec.ts index 6d6e04d..4eb69e4 100644 --- a/test/unit/ics.spec.ts +++ b/test/unit/ics.spec.ts @@ -67,6 +67,90 @@ describe('generateCalendar', () => { expect(ics).toContain('RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=WE') }) + it('uses recurrenceRule.start as DTSTART for recurring events', () => { + const event = makeEvent({ + startTime: '2026-04-15T16:15:00.000Z', + recurrenceRule: { + start: '2026-03-18T16:15:00.000Z', + end: null, + frequency: 2, + interval: 2, + by_weekday: [2], + by_n_weekday: null, + by_month: null, + by_month_day: null, + by_year_day: null, + count: null, + }, + }) + + const ics = generateCalendar(makeGuild(), [event]) + // DTSTART should be the series anchor, not the next occurrence + expect(ics).toContain('20260318T161500') + expect(ics).not.toContain('20260415T161500') + }) + + it('emits RECURRENCE-ID exception for modified occurrences', () => { + const event = makeEvent({ + startTime: '2026-04-01T16:15:00.000Z', + recurrenceRule: { + start: '2026-03-18T16:15:00.000Z', + end: null, + frequency: 2, + interval: 2, + by_weekday: [2], + by_n_weekday: null, + by_month: null, + by_month_day: null, + by_year_day: null, + count: null, + }, + exceptions: [ + { + originalStartTime: '2026-04-01T16:15:00.000Z', + startTime: '2026-04-01T14:15:00.000Z', + endTime: null, + isCanceled: false, + }, + ], + }) + + const ics = generateCalendar(makeGuild(), [event]) + const veventCount = (ics.match(/BEGIN:VEVENT/g) || []).length + expect(veventCount).toBe(2) + expect(ics).toContain('RECURRENCE-ID') + }) + + it('emits CANCELLED status for cancelled occurrences', () => { + const event = makeEvent({ + startTime: '2026-04-01T16:15:00.000Z', + recurrenceRule: { + start: '2026-03-18T16:15:00.000Z', + end: null, + frequency: 2, + interval: 2, + by_weekday: [2], + by_n_weekday: null, + by_month: null, + by_month_day: null, + by_year_day: null, + count: null, + }, + exceptions: [ + { + originalStartTime: '2026-04-01T16:15:00.000Z', + startTime: '2026-04-01T16:15:00.000Z', + endTime: null, + isCanceled: true, + }, + ], + }) + + const ics = generateCalendar(makeGuild(), [event]) + expect(ics).toContain('STATUS:CANCELLED') + expect(ics).toContain('RECURRENCE-ID') + }) + it('includes Discord event link in description', () => { const event = makeEvent({ description: 'Come join us!' }) const ics = generateCalendar(makeGuild(), [event]) -- knotmirror 0.0.1