test(calendar): run tests for different calendar instances

This commit is contained in:
Ryan Mwangi 2024-11-26 01:50:55 +03:00
parent 51c4f5c31f
commit 92c6fffe64
9 changed files with 148 additions and 243 deletions

View File

@ -150,178 +150,128 @@ describe('Calendar Merging API', () => {
const actualOutput = fs.readFileSync(filePath, 'utf8'); const actualOutput = fs.readFileSync(filePath, 'utf8');
expect(actualOutput).toBe(expectedOutput); expect(actualOutput).toBe(expectedOutput);
}); });
// test('Merge time-based calendar', async () => {
// const input = getTestCalendarFilename('work_task_calendar.ics');
// const response = await request(server)
// .post('/merge')
// .send({
// linkGroupName: 'Time Based Calendar',
// calendars: [
// {
// url: input,
// prefix: 'work_task',
// override: false,
// },
// ],
// });
// expect(response.status).toBe(200);
// expect(response.body.url).toMatch(/calendar\/Time_Based_Calendar/);
// // Check if the file was created in the test directory
// const filePath = path.join(CALENDARS_DIR, 'Time_Based_Calendar.ics');
// expect(fs.existsSync(filePath)).toBe(true);
// // Load expected output and compare
// const expectedOutput = fs.readFileSync(input, 'utf8');
// const actualOutput = fs.readFileSync(filePath, 'utf8');
// expect(actualOutput).toBe(expectedOutput);
// });
// test('EAT Event', async () => {
// const input = getTestCalendarFilename('eat_time_zone_event.ics');
// const response = await request(server)
// .post('/merge')
// .send({
// linkGroupName: 'EAT Event',
// calendars: [
// {
// url: input,
// prefix: 'EAT Event',
// override: false,
// },
// ],
// });
// expect(response.status).toBe(200);
// expect(response.body.url).toMatch(/calendar\/EAT_Event/);
// // Check if the file was created in the test directory
// const filePath = path.join(CALENDARS_DIR, 'EAT_Event.ics');
// expect(fs.existsSync(filePath)).toBe(true);
// // Load expected output and compare
// const expectedOutput = fs.readFileSync(input, 'utf8');
// const actualOutput = fs.readFileSync(filePath, 'utf8');
// expect(actualOutput).toBe(expectedOutput);
// });
// test('Merge calendar without prefix', async () => {
// const response = await request(server)
// .post('/merge')
// .send({
// linkGroupName: 'No Prefix Calendar',
// calendars: [
// {
// url: getTestCalendarFilename('sf_public_holidays.ics'),
// prefix: '',
// override: false,
// },
// ],
// });
// expect(response.status).toBe(200);
// expect(response.body.url).toMatch(/calendar\/No_Prefix_Calendar/);
// // Check if the file was created in the test directory
// const filePath = path.join(CALENDARS_DIR, 'No_Prefix_Calendar.ics');
// expect(fs.existsSync(filePath)).toBe(true);
// // Load expected output and compare
// const expectedOutput = loadExpectedOutput('No_Prefix_Calendar.ics');
// const actualOutput = fs.readFileSync(filePath, 'utf8');
// expect(actualOutput).toBe(expectedOutput);
// });
// test('Merge calendar with override', async () => { //test Merge time-based calendar
// const response = await request(server) test('Merge time-based calendar', async () => {
// .post('/merge') const input = getTestCalendarFilename('work_task_calendar.ics');
// .send({ const response = await request(server)
// linkGroupName: 'Override Calendar', .post('/merge')
// calendars: [ .send({
// { linkGroupName: 'Time Based Calendar',
// url: getTestCalendarFilename('sf_public_holidays.ics'), calendars: [
// prefix: 'Override Event', {
// override: true, url: getTestCalendarFilename('team_meeting_calendar.ics'), // Time-based calendar
// }, prefix: 'team_meeting_calendar',
// ], override: false,
// }); },
{
url: getTestCalendarFilename('work_task_calendar.ics'), // Time-based calendar
prefix: 'Work_Task',
override: false,
},
],
});
// expect(response.status).toBe(200); expect(response.status).toBe(200);
// expect(response.body.url).toMatch(/calendar\/Override_Calendar/); expect(response.body.url).toMatch(/calendar\/Time_Based_Calendar/);
// // Check if the file was created in the test directory // Check if the file was created in the test directory
// const filePath = path.join(CALENDARS_DIR, 'Override_Calendar.ics'); const filePath = path.join(CALENDARS_DIR, 'Time_Based_Calendar.ics');
// expect(fs.existsSync(filePath)).toBe(true); expect(fs.existsSync(filePath)).toBe(true);
// // Load expected output and compare // Load expected output and compare
// const expectedOutput = loadExpectedOutput('Override_Calendar.ics'); const expectedOutput = loadExpectedOutput('Time_Based_Calendar.ics');
// const actualOutput = fs.readFileSync(filePath, 'utf8'); const actualOutput = fs.readFileSync(filePath, 'utf8');
// expect(actualOutput).toBe(expectedOutput); expect(actualOutput).toBe(expectedOutput);
// }); });
//test Merge calendar without prefix
test('Merge calendar without prefix', async () => {
const response = await request(server)
.post('/merge')
.send({
linkGroupName: 'No Prefix Calendar',
calendars: [
{
url: getTestCalendarFilename('sf_public_holidays.ics'),
prefix: '',
override: false,
},
],
});
// test('Merge UTC and EAT time zone calendar', async () => { expect(response.status).toBe(200);
// const response = await request(server) expect(response.body.url).toMatch(/calendar\/No_Prefix_Calendar/);
// .post('/merge')
// .send({ // Check if the file was created in the test directory
// linkGroupName: 'UTCEAT Time Zone Calendar', const filePath = path.join(CALENDARS_DIR, 'No_Prefix_Calendar.ics');
// calendars: [ expect(fs.existsSync(filePath)).toBe(true);
// {
// url: getTestCalendarFilename('utc_time_zone_event.ics'),
// prefix: 'UTC_Event',
// override: false,
// },
// {
// url: getTestCalendarFilename('eat_time_zone_event.ics'),
// prefix: 'EAT_Event',
// override: false,
// },
// ],
// });
// expect(response.status).toBe(200);
// expect(response.body.url).toMatch(new RegExp(`calendar/UTCEAT_Time_Zone_Calendar`));
// // Check if the file was created in the test directory // Load expected output and compare
// const filePath = path.join(CALENDARS_DIR, 'UTCEAT_Time_Zone_Calendar.ics'); const expectedOutput = loadExpectedOutput('No_Prefix_Calendar.ics');
// expect(fs.existsSync(filePath)).toBe(true); const actualOutput = fs.readFileSync(filePath, 'utf8');
expect(actualOutput).toBe(expectedOutput);
});
//test Merge calendar with override
test('Merge calendar with override', async () => {
const response = await request(server)
.post('/merge')
.send({
linkGroupName: 'Override Calendar',
calendars: [
{
url: getTestCalendarFilename('sf_public_holidays.ics'),
prefix: 'Override Event',
override: true,
},
],
});
// // Load expected output and compare expect(response.status).toBe(200);
// const expectedOutput = loadExpectedOutput('UTCEAT_Time_Zone_Calendar.ics'); expect(response.body.url).toMatch(/calendar\/Override_Calendar/);
// const actualOutput = fs.readFileSync(filePath, 'utf8');
// expect(actualOutput).toBe(expectedOutput); // Check if the file was created in the test directory
// }); const filePath = path.join(CALENDARS_DIR, 'Override_Calendar.ics');
expect(fs.existsSync(filePath)).toBe(true);
// test('Merge date-based and time-based calendars', async () => { // Load expected output and compare
// const response = await request(server) const expectedOutput = loadExpectedOutput('Override_Calendar.ics');
// .post('/merge') const actualOutput = fs.readFileSync(filePath, 'utf8');
// .send({ expect(actualOutput).toBe(expectedOutput);
// linkGroupName: 'Merged Date and Time Based Calendar', });
// calendars: [
// {
// url: getTestCalendarFilename('holiday_calendar_2023.ics'), // Date-based calendar
// prefix: 'Holiday_2023',
// override: false,
// },
// {
// url: getTestCalendarFilename('work_task_calendar.ics'), // Time-based calendar
// prefix: 'Work_Task',
// override: false,
// },
// ],
// });
// expect(response.status).toBe(200); //test Merge date-based and time-based calendars
// expect(response.body.url).toMatch(new RegExp('calendar/Merged_Date_and_Time_Based_Calendar')); test('Merge date-based and time-based calendars', async () => {
const response = await request(server)
.post('/merge')
.send({
linkGroupName: 'Merged Date and Time Based Calendar',
calendars: [
{
url: getTestCalendarFilename('holiday_calendar_2023.ics'), // Date-based calendar
prefix: 'Holiday_2023',
override: false,
},
{
url: getTestCalendarFilename('work_task_calendar.ics'), // Time-based calendar
prefix: 'Work_Task',
override: false,
},
],
});
// // Check if the file was created in the test directory expect(response.status).toBe(200);
// const filePath = path.join(CALENDARS_DIR, 'Merged_Date_and_Time_Based_Calendar.ics'); expect(response.body.url).toMatch(new RegExp('calendar/Merged_Date_and_Time_Based_Calendar'));
// expect(fs.existsSync(filePath)).toBe(true);
// // Load expected output and compare // Check if the file was created in the test directory
// const expectedOutput = loadExpectedOutput('Merged_Date_and_Time_Based_Calendar.ics'); const filePath = path.join(CALENDARS_DIR, 'Merged_Date_and_Time_Based_Calendar.ics');
// const actualOutput = fs.readFileSync(filePath, 'utf8'); expect(fs.existsSync(filePath)).toBe(true);
// expect(actualOutput).toBe(expectedOutput);
// }); // Load expected output and compare
const expectedOutput = loadExpectedOutput('Merged_Date_and_Time_Based_Calendar.ics');
const actualOutput = fs.readFileSync(filePath, 'utf8');
expect(actualOutput).toBe(expectedOutput);
});
}); });

View File

@ -1,17 +1,21 @@
BEGIN:VCALENDAR BEGIN:VCALENDAR
PRODID:-//Your Product ID//EN
VERSION:2.0
NAME:Merged Date and Time Based Calendar NAME:Merged Date and Time Based Calendar
PRODID:-//CalMerge//Calendar Merger 1.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT BEGIN:VEVENT
UID:20231225T000000-001@example.com UID:20231225T000000-001@example.com
DTSTART;VALUE=DATE:20231225
DTEND;VALUE=DATE:20231226
DTSTAMP:20231225T000000Z
SUMMARY:Holiday_2023 Christmas Day SUMMARY:Holiday_2023 Christmas Day
DTSTART:20231225T000000 LOCATION:Germany
DTEND:20231226T000000
END:VEVENT END:VEVENT
BEGIN:VEVENT BEGIN:VEVENT
UID:20231108T090000-001@example.com UID:20231108T090000-001@example.com
DTSTART:20231108T090000Z
DTEND:20231108T100000Z
DTSTAMP:20231108T090000Z
SUMMARY:Work_Task Work Task SUMMARY:Work_Task Work Task
DTSTART:20231108T120000
DTEND:20231108T130000
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR

View File

@ -1,11 +1,14 @@
BEGIN:VCALENDAR BEGIN:VCALENDAR
PRODID:-//Your Product ID//EN
VERSION:2.0
NAME:No Prefix Calendar NAME:No Prefix Calendar
PRODID:-//CalMerge//Calendar Merger 1.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT BEGIN:VEVENT
UID:20231225T000000-001@example.com UID:20231225T000000-001@example.com
SUMMARY: Christmas Day DTSTART;VALUE=DATE:20231225
DTSTART:20231225T000000 DTEND;VALUE=DATE:20231226
DTEND:20231226T000000 DTSTAMP:20231225T000000Z
SUMMARY:Christmas Day
LOCATION:San Francisco
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR

View File

@ -1,11 +1,13 @@
BEGIN:VCALENDAR BEGIN:VCALENDAR
PRODID:-//Your Product ID//EN
VERSION:2.0
NAME:Override Calendar NAME:Override Calendar
PRODID:-//CalMerge//Calendar Merger 1.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT BEGIN:VEVENT
UID:20231225T000000-001@example.com UID:20231225T000000-001@example.com
SUMMARY:Override Event Christmas Day DTSTART;VALUE=DATE:20231225
DTSTART:20231225T000000 DTEND;VALUE=DATE:20231226
DTEND:20231226T000000 DTSTAMP:20231225T000000Z
SUMMARY:Override Event
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR

View File

@ -1,17 +1,21 @@
BEGIN:VCALENDAR BEGIN:VCALENDAR
PRODID:-//Your Product ID//EN
VERSION:2.0
NAME:Time Based Calendar NAME:Time Based Calendar
PRODID:-//CalMerge//Calendar Merger 1.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT BEGIN:VEVENT
UID:20231109T110000-001@example.com UID:20231109T110000-001@example.com
DTSTART:20231109T110000Z
DTEND:20231109T120000Z
DTSTAMP:20231109T110000Z
SUMMARY:team_meeting_calendar Team Meeting SUMMARY:team_meeting_calendar Team Meeting
DTSTART:20231109T140000 LOCATION:Virtual
DTEND:20231109T150000
END:VEVENT END:VEVENT
BEGIN:VEVENT BEGIN:VEVENT
UID:20231108T090000-001@example.com UID:20231108T090000-001@example.com
SUMMARY:work_task Work Task DTSTART:20231108T090000Z
DTSTART:20231108T120000 DTEND:20231108T100000Z
DTEND:20231108T130000 DTSTAMP:20231108T090000Z
SUMMARY:Work_Task Work Task
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR

View File

@ -1,17 +0,0 @@
BEGIN:VCALENDAR
PRODID:-//Your Product ID//EN
VERSION:2.0
NAME:UTCEAT Time Zone Calendar
BEGIN:VEVENT
UID:20231108T100000Z-001@example.com
SUMMARY:UTC_Event UTC Event
DTSTART:20231108T130000
DTEND:20231108T140000
END:VEVENT
BEGIN:VEVENT
UID:20231108T090000+0300-001@example.com
SUMMARY:EAT_Event EAT Event
DTSTART:20231108T090000
DTEND:20231108T100000
END:VEVENT
END:VCALENDAR

View File

@ -1,15 +0,0 @@
{
"linkGroupName": "UTCEAT Time Zone Calendar",
"calendars": [
{
"url": "C:\\Users\\user\\OneDrive\\Desktop\\Internship_tasks\\final calmerg\\test\\test_calendars\\utc_time_zone_event.ics",
"prefix": "UTC_Event",
"override": false
},
{
"url": "C:\\Users\\user\\OneDrive\\Desktop\\Internship_tasks\\final calmerg\\test\\test_calendars\\eat_time_zone_event.ics",
"prefix": "EAT_Event",
"override": false
}
]
}

View File

@ -1,11 +0,0 @@
BEGIN:VCALENDAR
NAME:EAT Event
VERSION:2.0
BEGIN:VEVENT
UID:20231108T090000+0300-001@example.com
DTSTAMP:20231101T090000+03:00
DTSTART:20231108T090000+03:00
DTEND:20231108T100000+03:00
SUMMARY:EAT Event
END:VEVENT
END:VCALENDAR

View File

@ -1,15 +0,0 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Example Corp//NONSGML Event//EN
BEGIN:VEVENT
UID:20231108T100000Z-001@example.com
DTSTAMP:20231108T100000Z
DTSTART:20231108T100000Z
DTEND:20231108T110000Z
SUMMARY:UTC Event
DESCRIPTION:This event is scheduled in UTC.
LOCATION:Virtual
STATUS:CONFIRMED
SEQUENCE:0
END:VEVENT
END:VCALENDAR