Compare commits

..

No commits in common. "92c6fffe644cb749702c76ef7294bdfe8888c432" and "ff595a9f70ad4ab5bcbf129d1fc9462ec5230924" have entirely different histories.

11 changed files with 281 additions and 192 deletions

View file

@ -37,12 +37,11 @@ export function createCalendarComponent(name) {
} }
// Add events to the calendar component // Add events to the calendar component
export function addEventsToCalendar(newCalendar, calendars) { export function addEventsToCalendar(newCalendar, calendars, overrideFlag = false) {
let defaultTimeZone = null; // To store the first found X-WR-TIMEZONE let defaultTimeZone = null; // To store the first found X-WR-TIMEZONE
calendars.forEach((calendarRaw) => { calendars.forEach((calendarRaw) => {
try { try {
const { data, prefix, override } = calendarRaw; // Extract prefix and override
const calendar = new ICAL.Component(ICAL.parse(calendarRaw.data)); const calendar = new ICAL.Component(ICAL.parse(calendarRaw.data));
// Extract METHOD from the parsed data (if available) // Extract METHOD from the parsed data (if available)
@ -88,13 +87,13 @@ export function addEventsToCalendar(newCalendar, calendars) {
const dtstamp = vevent.getFirstPropertyValue('dtstamp'); const dtstamp = vevent.getFirstPropertyValue('dtstamp');
if (dtstamp) newEvent.component.updatePropertyWithValue('dtstamp', dtstamp); if (dtstamp) newEvent.component.updatePropertyWithValue('dtstamp', dtstamp);
if (override) { if (overrideFlag) {
newEvent.summary = prefix || 'Busy'; newEvent.summary = 'Busy'
} else { } else {
newEvent.summary = prefix ? `${prefix} ${event.summary}` : event.summary; newEvent.summary = event.summary;
if (event.location) newEvent.location = event.location; if (event.location) newEvent.location = event.location;
} }
const rrule = vevent.getFirstPropertyValue('rrule'); const rrule = vevent.getFirstPropertyValue('rrule');
if (rrule) newEvent.component.updatePropertyWithValue('rrule', rrule); if (rrule) newEvent.component.updatePropertyWithValue('rrule', rrule);

View file

@ -119,159 +119,209 @@ describe('Calendar Merging API', () => {
expect(actualOutput).toBe(expectedOutput); expect(actualOutput).toBe(expectedOutput);
}); });
test('Merge date-based calendar', async () => { // test('Merge date-based calendar', async () => {
const response = await request(server) // const response = await request(server)
.post('/merge') // .post('/merge')
.send({ // .send({
linkGroupName: 'Date Based Calendar', // linkGroupName: 'Date Based Calendar',
calendars: [ // calendars: [
{ // {
url: getTestCalendarFilename('holiday_calendar_2023.ics'), // url: getTestCalendarFilename('holiday_calendar_2023.ics'),
prefix: 'holiday_calendar_2023', // prefix: 'holiday_calendar_2023',
override: false, // override: false,
}, // },
{ // {
url: getTestCalendarFilename('US_Holidays.ics'), // url: getTestCalendarFilename('US_Holidays.ics'),
prefix: 'US_holidays', // prefix: 'US_holidays',
override: false, // override: false,
}, // },
], // ],
}); // });
expect(response.status).toBe(200); // expect(response.status).toBe(200);
expect(response.body.url).toMatch(new RegExp(`calendar/Date_Based_Calendar`)); // expect(response.body.url).toMatch(new RegExp(`calendar/Date_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, 'Date_Based_Calendar.ics'); // const filePath = path.join(CALENDARS_DIR, 'Date_Based_Calendar.ics');
console.log('Checking if file exists at:', filePath); // console.log('Checking if file exists at:', filePath);
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('Date_Based_Calendar.ics'); // const expectedOutput = loadExpectedOutput('Date_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 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); // test('Merge time-based calendar', async () => {
expect(response.body.url).toMatch(/calendar\/Time_Based_Calendar/); // 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 // // Check if the file was created in the test directory
const filePath = path.join(CALENDARS_DIR, 'Time_Based_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('Time_Based_Calendar.ics'); // const expectedOutput = fs.readFileSync(input, 'utf8');
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,
},
],
});
expect(response.status).toBe(200); // test('EAT Event', async () => {
expect(response.body.url).toMatch(/calendar\/No_Prefix_Calendar/); // 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 // // Check if the file was created in the test directory
const filePath = path.join(CALENDARS_DIR, 'No_Prefix_Calendar.ics'); // const filePath = path.join(CALENDARS_DIR, 'EAT_Event.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('No_Prefix_Calendar.ics'); // const expectedOutput = fs.readFileSync(input, 'utf8');
const actualOutput = fs.readFileSync(filePath, 'utf8'); // const actualOutput = fs.readFileSync(filePath, 'utf8');
expect(actualOutput).toBe(expectedOutput); // 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,
},
],
});
expect(response.status).toBe(200); // test('Merge calendar without prefix', async () => {
expect(response.body.url).toMatch(/calendar\/Override_Calendar/); // 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 // // 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, 'No_Prefix_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('No_Prefix_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 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 date-based and time-based calendars // expect(response.status).toBe(200);
test('Merge date-based and time-based calendars', async () => { // expect(response.body.url).toMatch(/calendar\/Override_Calendar/);
const response = await request(server)
.post('/merge') // // Check if the file was created in the test directory
.send({ // const filePath = path.join(CALENDARS_DIR, 'Override_Calendar.ics');
linkGroupName: 'Merged Date and Time Based Calendar', // expect(fs.existsSync(filePath)).toBe(true);
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); // // Load expected output and compare
expect(response.body.url).toMatch(new RegExp('calendar/Merged_Date_and_Time_Based_Calendar')); // const expectedOutput = loadExpectedOutput('Override_Calendar.ics');
// const actualOutput = fs.readFileSync(filePath, 'utf8');
// expect(actualOutput).toBe(expectedOutput);
// });
// Check if the file was created in the test directory // test('Merge UTC and EAT time zone calendar', async () => {
const filePath = path.join(CALENDARS_DIR, 'Merged_Date_and_Time_Based_Calendar.ics'); // const response = await request(server)
expect(fs.existsSync(filePath)).toBe(true); // .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`));
// 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, 'UTCEAT_Time_Zone_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('UTCEAT_Time_Zone_Calendar.ics');
// const actualOutput = fs.readFileSync(filePath, 'utf8');
// expect(actualOutput).toBe(expectedOutput);
// });
// 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,
// },
// ],
// });
// expect(response.status).toBe(200);
// expect(response.body.url).toMatch(new RegExp('calendar/Merged_Date_and_Time_Based_Calendar'));
// // 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,21 +1,16 @@
BEGIN:VCALENDAR BEGIN:VCALENDAR
NAME:Date Based Calendar
PRODID:-//CalMerge//Calendar Merger 1.0//EN
VERSION:2.0 VERSION:2.0
CALSCALE:GREGORIAN NAME:Date Based Calendar
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_calendar_2023 Christmas Day SUMMARY:holiday_calendar_2023 Christmas Day
LOCATION:Germany DTSTART:20231225T000000
DTEND:20231226T000000
END:VEVENT END:VEVENT
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:US_holidays Christmas Day SUMMARY:US_holidays Christmas Day
DTSTART:20231225T000000
DTEND:20231226T000000
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR

View file

@ -1,21 +1,17 @@
BEGIN:VCALENDAR BEGIN:VCALENDAR
NAME:Merged Date and Time Based Calendar PRODID:-//Your Product ID//EN
PRODID:-//CalMerge//Calendar Merger 1.0//EN
VERSION:2.0 VERSION:2.0
CALSCALE:GREGORIAN NAME:Merged Date and Time Based Calendar
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
LOCATION:Germany DTSTART:20231225T000000
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,14 +1,11 @@
BEGIN:VCALENDAR BEGIN:VCALENDAR
NAME:No Prefix Calendar PRODID:-//Your Product ID//EN
PRODID:-//CalMerge//Calendar Merger 1.0//EN
VERSION:2.0 VERSION:2.0
CALSCALE:GREGORIAN NAME:No Prefix Calendar
BEGIN:VEVENT BEGIN:VEVENT
UID:20231225T000000-001@example.com UID:20231225T000000-001@example.com
DTSTART;VALUE=DATE:20231225 SUMMARY: Christmas Day
DTEND;VALUE=DATE:20231226 DTSTART:20231225T000000
DTSTAMP:20231225T000000Z DTEND:20231226T000000
SUMMARY:Christmas Day
LOCATION:San Francisco
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR

View file

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

View file

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

View file

@ -0,0 +1,17 @@
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

@ -0,0 +1,15 @@
{
"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

@ -0,0 +1,11 @@
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

@ -0,0 +1,15 @@
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