Skip to content

Commit 44b45a0

Browse files
committed
feat:add tests for calendar exports
1 parent 7733798 commit 44b45a0

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

flow/api/calendar/calendar_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package calendar
2+
3+
import (
4+
"bytes"
5+
"strings"
6+
"testing"
7+
"time"
8+
)
9+
10+
func TestWriteCalendar(t *testing.T) {
11+
startTime := time.Date(2023, 10, 25, 14, 30, 0, 0, time.UTC)
12+
events := []*webcalEvent{
13+
{
14+
GroupId: 123,
15+
Summary: "CS 135 - LEC 001",
16+
StartTime: startTime,
17+
EndTime: startTime.Add(1 * time.Hour),
18+
Location: "MC 4045",
19+
},
20+
}
21+
22+
var output bytes.Buffer
23+
writeCalendar(&output, "test_secret_id", events)
24+
result := output.String()
25+
26+
expectedTimestamp := "20231025T143000Z"
27+
if !strings.Contains(result, "DTSTART:"+expectedTimestamp) {
28+
t.Errorf("Expected output to contain start time %q, but got:\n%s", expectedTimestamp, result)
29+
}
30+
}

script/test_calendar_export.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
set -e
3+
4+
DB_CONTAINER="postgres"
5+
DB_NAME="flow"
6+
API_URL="http://localhost:8081"
7+
SECRET_ID="0123456789abcdef"
8+
9+
echo "=== 1. Setting up Test Data in DB '$DB_NAME' ==="
10+
11+
# Adding the location column if missing
12+
docker exec -i $DB_CONTAINER psql -U postgres -d $DB_NAME -c "
13+
DO \$\$
14+
BEGIN
15+
BEGIN
16+
ALTER TABLE user_schedule ADD COLUMN location text;
17+
EXCEPTION
18+
WHEN duplicate_column THEN RAISE NOTICE 'column location already exists in user_schedule';
19+
END;
20+
END \$\$;"
21+
22+
# Insert test data
23+
docker exec -i $DB_CONTAINER psql -U postgres -d $DB_NAME <<EOF
24+
-- Create Test User
25+
INSERT INTO "user" (secret_id, first_name, last_name, join_source)
26+
VALUES ('$SECRET_ID', 'Test', 'User', 'email')
27+
ON CONFLICT (secret_id) DO NOTHING;
28+
29+
DELETE FROM section_meeting WHERE section_id = 1;
30+
31+
INSERT INTO section_meeting (
32+
section_id, location, start_date, end_date, start_seconds, end_seconds, days,
33+
is_cancelled, is_closed, is_tba
34+
)
35+
VALUES (
36+
1, 'RCH 301', '2025-09-01', '2025-12-20', 36000, 39600, '{"M", "W", "F"}',
37+
false, false, false
38+
);
39+
40+
41+
INSERT INTO user_schedule (user_id, section_id)
42+
SELECT id, 1 FROM "user" WHERE secret_id = '$SECRET_ID'
43+
ON CONFLICT DO NOTHING;
44+
EOF
45+
46+
echo "=== 2. Downloading Calendar ==="
47+
curl -f "$API_URL/calendar/$SECRET_ID.ics" -o test_output.ics
48+
49+
echo ""
50+
echo "=== DONE ==="
51+
echo "Check the test_output.ics file generated."

0 commit comments

Comments
 (0)