Skip to content

Commit ae92a6a

Browse files
committed
add unit tests for excluded dates
1 parent 48d2fe3 commit ae92a6a

File tree

6 files changed

+188
-4
lines changed

6 files changed

+188
-4
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ indent_size = 2
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

11+
[*.ics]
12+
insert_final_newline = false
13+
1114
[*.md]
1215
max_line_length = off
1316
trim_trailing_whitespace = false

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"lint": "yarn workspaces run lint",
2222
"prepare": "node .husky/install.mjs || true",
2323
"typecheck": "yarn workspaces run typecheck",
24-
"test:unit": "cross-env RunEnvironment='dev' concurrently --names 'api,ui' 'vitest run --coverage --config tests/unit/vitest.config.ts tests/unit' 'yarn workspace infra-core-ui run test:unit'",
24+
"test:unit": "cross-env RunEnvironment='dev' concurrently --names 'api,ui' 'yarn run test:unit-api' 'yarn workspace infra-core-ui run test:unit'",
25+
"test:unit-api": "cross-env RunEnvironment='dev' vitest run --coverage --config tests/unit/vitest.config.ts tests/unit",
2526
"test:unit-ui": "yarn test:unit --ui",
2627
"test:unit-watch": "vitest tests/unit",
2728
"test:live": "vitest tests/live",

src/api/routes/ics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ const icalPlugin: FastifyPluginAsync = async (fastify, _options) => {
171171
event = event.repeating({
172172
...repeatingIcalMap[rawEvent.repeats as EventRepeatOptions],
173173
until: moment.tz(rawEvent.repeatEnds, "America/Chicago"),
174-
exclude: exclusions,
174+
...(exclusions.length > 0 && { exclude: exclusions }),
175175
});
176176
} else {
177177
event.repeating({
178178
...repeatingIcalMap[rawEvent.repeats as EventRepeatOptions],
179-
exclude: exclusions,
179+
...(exclusions.length > 0 && { exclude: exclusions }),
180180
});
181181
}
182182
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
BEGIN:VCALENDAR
2+
VERSION:2.0
3+
PRODID:-//sebbo.net//ical-generator//EN
4+
METHOD:PUBLISH
5+
NAME:ACM@UIUC - All Events
6+
X-WR-CALNAME:ACM@UIUC - All Events
7+
BEGIN:VTIMEZONE
8+
TZID:America/Chicago
9+
TZURL:http://tzurl.org/zoneinfo-outlook/America/Chicago
10+
X-LIC-LOCATION:America/Chicago
11+
BEGIN:DAYLIGHT
12+
TZOFFSETFROM:-0600
13+
TZOFFSETTO:-0500
14+
TZNAME:CDT
15+
DTSTART:19700308T020000
16+
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
17+
END:DAYLIGHT
18+
BEGIN:STANDARD
19+
TZOFFSETFROM:-0500
20+
TZOFFSETTO:-0600
21+
TZNAME:CST
22+
DTSTART:19701101T020000
23+
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
24+
END:STANDARD
25+
END:VTIMEZONE
26+
TIMEZONE-ID:America/Chicago
27+
X-WR-TIMEZONE:America/Chicago
28+
BEGIN:VEVENT
29+
UID:3138bead-b2c5-4bfe-bce4-4b478658cb78
30+
SEQUENCE:0
31+
DTSTAMP:20240822T155148
32+
DTSTART;TZID=America/Chicago:20240825T120000
33+
DTEND;TZID=America/Chicago:20240825T160000
34+
SUMMARY:Quad Day
35+
LOCATION:Main Quad
36+
DESCRIPTION:Host: ACM\nGoogle Maps Link: https://maps.app.goo.gl/2ZRYibtE7
37+
Yem5TrP6\n\nJoin us on Quad Day to learn more about ACM and CS at Illinois
38+
!
39+
ORGANIZER;CN="ACM@UIUC":mailto:ACM@UIUC
40+
END:VEVENT
41+
BEGIN:VEVENT
42+
UID:5bc69f3b-e958-4c80-b041-ddeae0385db8
43+
SEQUENCE:0
44+
DTSTAMP:20240822T155148
45+
DTSTART;TZID=America/Chicago:20240725T180000
46+
DTEND;TZID=America/Chicago:20240725T190000
47+
RRULE:FREQ=WEEKLY;UNTIL=20240905T190000
48+
SUMMARY:Infra Meeting
49+
LOCATION:ACM Middle Room
50+
DESCRIPTION:Host: Infrastructure Committee\n\nTest event.
51+
ORGANIZER;CN="ACM@UIUC":mailto:ACM@UIUC
52+
END:VEVENT
53+
BEGIN:VEVENT
54+
UID:4d38608d-90bf-4a58-8701-3f1b659a53db
55+
SEQUENCE:0
56+
DTSTAMP:20240822T155148
57+
DTSTART;TZID=America/Chicago:20240925T180000
58+
DTEND;TZID=America/Chicago:20240925T190000
59+
SUMMARY:Testing Paid and Featured Event
60+
LOCATION:ACM Middle Room
61+
DESCRIPTION:Host: Social Committee\n\nTest paid featured event.
62+
ORGANIZER;CN="ACM@UIUC":mailto:ACM@UIUC
63+
END:VEVENT
64+
BEGIN:VEVENT
65+
UID:accd7fe0-50ac-427b-8041-a2b3ddcd328e
66+
SEQUENCE:0
67+
DTSTAMP:20240822T155148
68+
DTSTART;TZID=America/Chicago:20240725T180000
69+
DTEND;TZID=America/Chicago:20240725T190000
70+
SUMMARY:Event in the past.
71+
LOCATION:ACM Middle Room
72+
DESCRIPTION:Host: Infrastructure Committee\n\nTest event in the past.
73+
ORGANIZER;CN="ACM@UIUC":mailto:ACM@UIUC
74+
END:VEVENT
75+
BEGIN:VEVENT
76+
UID:78be8f2b-3d1d-4481-90b6-85bfd84d38b4
77+
SEQUENCE:0
78+
DTSTAMP:20240822T155148
79+
DTSTART;TZID=America/Chicago:20240830T170000
80+
DTEND;TZID=America/Chicago:20240830T170000
81+
RRULE:FREQ=WEEKLY
82+
SUMMARY:Weekly Happy Hour
83+
LOCATION:Legends
84+
DESCRIPTION:Host: ACM\nGoogle Maps Link: https://goo.gl/maps/CXESXd3otbGZN
85+
qFP7\n\nMeet and chat with your peers and fellow ACM members\, with food o
86+
n us!
87+
ORGANIZER;CN="ACM@UIUC":mailto:ACM@UIUC
88+
END:VEVENT
89+
BEGIN:VEVENT
90+
UID:6ac35cf3-3a4d-4d45-957a-6fee8dea50a7
91+
SEQUENCE:0
92+
DTSTAMP:20240822T155148
93+
DTSTART;TZID=America/Chicago:20241220T012100
94+
DTEND;TZID=America/Chicago:20241220T022100
95+
RRULE:FREQ=WEEKLY;UNTIL=20251221T000000
96+
EXDATE;TZID=America/Chicago:20250627T012100
97+
SUMMARY:Test Title
98+
LOCATION:ACM Room (Siebel CS 1104)
99+
DESCRIPTION:Host: ACM\nGoogle Maps Link: https://maps.app.goo.gl/dwbBBBkfj
100+
kgj8gvA8\n\nTest Description with now etag 1?
101+
ORGANIZER;CN="ACM@UIUC":mailto:ACM@UIUC
102+
END:VEVENT
103+
END:VCALENDAR

tests/unit/ical.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { afterAll, expect, test, beforeEach, vi } from "vitest";
22
import { ScanCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb";
33
import { mockClient } from "aws-sdk-client-mock";
44
import init from "../../src/api/index.js";
5-
import { dynamoTableData } from "./mockEventData.testdata.js";
5+
import {
6+
dynamoEventWithRepeatExclusion,
7+
dynamoTableData,
8+
} from "./mockEventData.testdata.js";
69
import { secretObject } from "./secret.testdata.js";
710
import { readFile } from "fs/promises";
811

@@ -30,6 +33,27 @@ test("Test getting ACM-wide iCal calendar", async () => {
3033
);
3134
});
3235

36+
test("Test getting ACM-wide iCal calendar with specific repeat exclusion", async () => {
37+
const date = new Date(2024, 7, 22, 15, 51, 48); // August 22, 2024, at 15:51:48 (3:51:48 PM)
38+
vi.setSystemTime(date);
39+
ddbMock.on(ScanCommand).resolves({
40+
Items: [...dynamoTableData, dynamoEventWithRepeatExclusion] as any,
41+
});
42+
const response = await app.inject({
43+
method: "GET",
44+
url: "/api/v1/ical",
45+
});
46+
expect(response.statusCode).toBe(200);
47+
expect(response.headers["content-disposition"]).toEqual(
48+
'attachment; filename="calendar.ics"',
49+
);
50+
expect(response.body).toEqual(
51+
(
52+
await readFile("./tests/unit/data/acmWideCalendarRepeatExclude.ics")
53+
).toString(),
54+
);
55+
});
56+
3357
test("Test getting non-existent iCal calendar fails", async () => {
3458
const date = new Date(2024, 7, 22, 15, 51, 48); // August 22, 2024, at 15:51:48 (3:51:48 PM)
3559
vi.setSystemTime(date);

tests/unit/mockEventData.testdata.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,63 @@ const dynamoTableDataUnmarshalledUpcomingOnly = dynamoTableData
187187
})
188188
.filter((x: any) => x.title !== "Event in the past.");
189189

190+
const dynamoEventWithRepeatExclusion = {
191+
id: {
192+
S: "6ac35cf3-3a4d-4d45-957a-6fee8dea50a7",
193+
},
194+
createdAt: {
195+
S: "2024-12-20T08:08:40.329Z",
196+
},
197+
description: {
198+
S: "Test Description with now etag 1?",
199+
},
200+
end: {
201+
S: "2024-12-20T02:21:00",
202+
},
203+
featured: {
204+
BOOL: false,
205+
},
206+
host: {
207+
S: "ACM",
208+
},
209+
location: {
210+
S: "ACM Room (Siebel CS 1104)",
211+
},
212+
locationLink: {
213+
S: "https://maps.app.goo.gl/dwbBBBkfjkgj8gvA8",
214+
},
215+
paidEventId: {
216+
S: "asasasasasas",
217+
},
218+
repeatEnds: {
219+
S: "2025-12-21T00:00:00",
220+
},
221+
repeatExcludes: {
222+
L: [
223+
{
224+
S: "2025-06-27",
225+
},
226+
],
227+
},
228+
repeats: {
229+
S: "weekly",
230+
},
231+
start: {
232+
S: "2024-12-20T01:21:00",
233+
},
234+
title: {
235+
S: "Test Title",
236+
},
237+
updatedAt: {
238+
S: "2025-03-21T03:34:50.228Z",
239+
},
240+
};
241+
190242
export {
191243
dynamoTableData,
192244
dynamoTableDataUnmarshalled,
193245
dynamoTableDataUnmarshalledUpcomingOnly,
194246
infraEventsOnly,
195247
infraEventsOnlyUnmarshalled,
248+
dynamoEventWithRepeatExclusion,
196249
};

0 commit comments

Comments
 (0)