-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test calendar feed extraction including recurring events
- Loading branch information
Showing
4 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
BEGIN:VCALENDAR | ||
VERSION:2.0 | ||
CALSCALE:GREGORIAN | ||
PRODID:-//SabreDAV//SabreDAV//EN | ||
REFRESH-INTERVAL;VALUE=DURATION:PT4H | ||
X-PUBLISHED-TTL:PT4H | ||
BEGIN:VTIMEZONE | ||
TZID:Europe/Berlin | ||
BEGIN:DAYLIGHT | ||
TZOFFSETFROM:+0100 | ||
TZOFFSETTO:+0200 | ||
TZNAME:CEST | ||
DTSTART:19700329T020000 | ||
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU | ||
END:DAYLIGHT | ||
BEGIN:STANDARD | ||
TZOFFSETFROM:+0200 | ||
TZOFFSETTO:+0100 | ||
TZNAME:CET | ||
DTSTART:19701025T030000 | ||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU | ||
END:STANDARD | ||
END:VTIMEZONE | ||
BEGIN:VEVENT | ||
CREATED:20240808T201535Z | ||
DTSTAMP:20240808T201636Z | ||
LAST-MODIFIED:20240808T201636Z | ||
SEQUENCE:2 | ||
UID:2748ddf3-886e-430a-8392-79d565b952aa | ||
DTSTART;TZID=Europe/Berlin:20240815T160000 | ||
DTEND;TZID=Europe/Berlin:20240815T170000 | ||
STATUS:CONFIRMED | ||
SUMMARY:Recurring event weekly only twice | ||
RRULE:FREQ=WEEKLY;COUNT=2;BYDAY=TH | ||
END:VEVENT | ||
BEGIN:VEVENT | ||
CREATED:20240808T201642Z | ||
DTSTAMP:20240808T201649Z | ||
LAST-MODIFIED:20240808T201649Z | ||
SEQUENCE:2 | ||
UID:bc541fc4-fbdd-4186-b102-c04f387c8dc9 | ||
DTSTART;VALUE=DATE:20240816 | ||
DTEND;VALUE=DATE:20240817 | ||
STATUS:CONFIRMED | ||
SUMMARY:Whole day | ||
END:VEVENT | ||
BEGIN:VEVENT | ||
CREATED:20240808T204507Z | ||
DTSTAMP:20240808T204518Z | ||
LAST-MODIFIED:20240808T204518Z | ||
SEQUENCE:2 | ||
UID:7388dbc8-03ed-4ecb-b43b-3349361d3942 | ||
DTSTART;TZID=Europe/Berlin:20240811T180000 | ||
DTEND;TZID=Europe/Berlin:20240811T190000 | ||
STATUS:CONFIRMED | ||
SUMMARY:Future Event | ||
END:VEVENT | ||
BEGIN:VEVENT | ||
CREATED:20240808T201404Z | ||
DTSTAMP:20240808T201529Z | ||
LAST-MODIFIED:20240808T201529Z | ||
SEQUENCE:2 | ||
UID:6099e8c0-b233-4dc8-83da-7ad56191ddb0 | ||
DTSTART;TZID=Europe/Berlin:20240730T130000 | ||
DTEND;TZID=Europe/Berlin:20240730T140000 | ||
STATUS:CONFIRMED | ||
SUMMARY:Recurring event weekly | ||
RRULE:FREQ=WEEKLY;BYDAY=TU | ||
END:VEVENT | ||
BEGIN:VEVENT | ||
CREATED:20240808T201232Z | ||
DTSTAMP:20240808T204505Z | ||
LAST-MODIFIED:20240808T204505Z | ||
SEQUENCE:3 | ||
UID:881a3000-eae7-4ebf-8eb4-d1bef216957d | ||
DTSTART;TZID=Europe/Berlin:20240808T100000 | ||
DTEND;TZID=Europe/Berlin:20240808T110000 | ||
STATUS:CONFIRMED | ||
SUMMARY:Past Event | ||
END:VEVENT | ||
END:VCALENDAR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,44 @@ | ||
import { expect, jest, it } from '@jest/globals'; | ||
import app from '../../src/app'; | ||
import axios from 'axios'; | ||
import { CalendarItemData } from '../../src/services/calendar-items/calendar-items.class'; | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
|
||
jest.mock('axios'); | ||
|
||
describe('\'Calendar Items\' service', () => { | ||
beforeAll(done => { | ||
app.setup(); | ||
(app.get('databaseReady') as Promise<void>).then(done); | ||
}); | ||
|
||
it('registered the service', () => { | ||
const service = app.service('calendar-items'); | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should fetch a calendar feed', async () => { | ||
const testFeed = await fs.readFile(path.resolve(__dirname, '../feed.ics'), { encoding: 'utf-8' }); | ||
axios.get.mockResolvedValue({ data: testFeed }); | ||
|
||
jest.useFakeTimers(); | ||
jest.setSystemTime(1723149778415); // simulate Thu Aug 08 2024 20:42:58 GMT+0000 | ||
|
||
const calendarFeedsService = app.service('calendar-feeds'); | ||
await calendarFeedsService.create({ name: 'Test', url: 'https://example.org/testfeed.ics' }); | ||
|
||
const service = app.service('calendar-items'); | ||
const items = await service.find({ paginate: false }) as CalendarItemData[]; | ||
|
||
expect(axios.get).toHaveBeenCalledWith('https://example.org/testfeed.ics'); | ||
expect(items.length).toBe(9); | ||
expect(items.filter(item => item.summary === 'Recurring event weekly').length).toBe(5); | ||
expect(items.filter(item => item.summary === 'Recurring event weekly only twice').length).toBe(2); | ||
expect(items.filter(item => item.summary === 'Future Event').length).toBe(1); | ||
expect(items.filter(item => item.summary === 'Past Event').length).toBe(0); | ||
expect(items.filter(item => item.summary === 'Whole day').length).toBe(1); | ||
|
||
jest.useRealTimers(); | ||
}); | ||
}); |