test: validate fetchCalendarData reads and parses files accurately

This commit is contained in:
Ryan Mwangi 2024-11-18 14:04:51 +03:00
parent d4498cd0d8
commit 9468e58132
1 changed files with 14 additions and 6 deletions

View File

@ -33,12 +33,20 @@ describe('Calendar Utility Functions', () => {
});
// Test case: reading data from a file
it('reads data from a file', async () => {
const testCalendar = { url: './test_calendars/eat_time_zone_event.ics' };
// Call the fetchCalendarData function with the test calendar object
it('reads and parses data from a file', async () => {
const testCalendar = { url: './test/test_calendars/eat_time_zone_event.ics' };
// Call the fetchCalendarData function
const result = await fetchCalendarData(testCalendar);
// Assert that the fetched result's data matches the expected file data
expect(ICAL.parse(result.data)).toBe('file data');
});
// Expected parsed output
const expectedParsedData = ICAL.parse(
fs.readFileSync(testCalendar.url, 'utf-8')
);
// Assert that the fetched and parsed data matches
expect(ICAL.parse(result.data)).toEqual(expectedParsedData);
});
});
});