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');
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 () => {
// const response = await request(server)
// .post('/merge')
// .send({
// linkGroupName: 'Override Calendar',
// calendars: [
// {
// url: getTestCalendarFilename('sf_public_holidays.ics'),
// prefix: 'Override Event',
// override: true,
// },
// ],
// });
//test Merge time-based calendar
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: 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.body.url).toMatch(/calendar\/Override_Calendar/);
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, 'Override_Calendar.ics');
// expect(fs.existsSync(filePath)).toBe(true);
// 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 = loadExpectedOutput('Override_Calendar.ics');
// const actualOutput = fs.readFileSync(filePath, 'utf8');
// expect(actualOutput).toBe(expectedOutput);
// });
// Load expected output and compare
const expectedOutput = loadExpectedOutput('Time_Based_Calendar.ics');
const actualOutput = fs.readFileSync(filePath, 'utf8');
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 () => {
// const response = await request(server)
// .post('/merge')
// .send({
// linkGroupName: 'UTCEAT Time Zone Calendar',
// calendars: [
// {
// 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`));
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);
// // Check if the file was created in the test directory
// const filePath = path.join(CALENDARS_DIR, 'UTCEAT_Time_Zone_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
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
// const expectedOutput = loadExpectedOutput('UTCEAT_Time_Zone_Calendar.ics');
// const actualOutput = fs.readFileSync(filePath, 'utf8');
// expect(actualOutput).toBe(expectedOutput);
// });
expect(response.status).toBe(200);
expect(response.body.url).toMatch(/calendar\/Override_Calendar/);
// 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 () => {
// 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,
// },
// ],
// });
// Load expected output and compare
const expectedOutput = loadExpectedOutput('Override_Calendar.ics');
const actualOutput = fs.readFileSync(filePath, 'utf8');
expect(actualOutput).toBe(expectedOutput);
});
// expect(response.status).toBe(200);
// expect(response.body.url).toMatch(new RegExp('calendar/Merged_Date_and_Time_Based_Calendar'));
//test Merge date-based and time-based calendars
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
// const filePath = path.join(CALENDARS_DIR, 'Merged_Date_and_Time_Based_Calendar.ics');
// expect(fs.existsSync(filePath)).toBe(true);
expect(response.status).toBe(200);
expect(response.body.url).toMatch(new RegExp('calendar/Merged_Date_and_Time_Based_Calendar'));
// // 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);
// });
// Check if the file was created in the test directory
const filePath = path.join(CALENDARS_DIR, 'Merged_Date_and_Time_Based_Calendar.ics');
expect(fs.existsSync(filePath)).toBe(true);
// 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
PRODID:-//Your Product ID//EN
VERSION:2.0
NAME:Merged Date and Time Based Calendar
PRODID:-//CalMerge//Calendar Merger 1.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
UID:20231225T000000-001@example.com
DTSTART;VALUE=DATE:20231225
DTEND;VALUE=DATE:20231226
DTSTAMP:20231225T000000Z
SUMMARY:Holiday_2023 Christmas Day
DTSTART:20231225T000000
DTEND:20231226T000000
LOCATION:Germany
END:VEVENT
BEGIN:VEVENT
UID:20231108T090000-001@example.com
DTSTART:20231108T090000Z
DTEND:20231108T100000Z
DTSTAMP:20231108T090000Z
SUMMARY:Work_Task Work Task
DTSTART:20231108T120000
DTEND:20231108T130000
END:VEVENT
END:VCALENDAR

View File

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

View File

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

View File

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