test(url): run tests for merged calendar url extention
This commit is contained in:
parent
eb0f2f145c
commit
f7b72efd06
2 changed files with 60 additions and 1 deletions
|
@ -64,7 +64,8 @@ router.get('/calendar/:name', async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const icsFilePath = path.join(MERGED_CALENDARS_DIR, `${calendarName}.ics`);
|
const icsFilePath = path.join(MERGED_CALENDARS_DIR, `${calendarName}.ics`);
|
||||||
|
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if the .ics file exists
|
// Check if the .ics file exists
|
||||||
console.log(`Serving calendar for: ${calendarName}`);
|
console.log(`Serving calendar for: ${calendarName}`);
|
||||||
|
@ -78,7 +79,11 @@ router.get('/calendar/:name', async (req, res) => {
|
||||||
}
|
}
|
||||||
res.setHeader('Content-Type', 'text/calendar');
|
res.setHeader('Content-Type', 'text/calendar');
|
||||||
res.sendFile(icsFilePath);
|
res.sendFile(icsFilePath);
|
||||||
|
|
||||||
|
// Log the successful request with URL format and status code
|
||||||
|
console.log(`Serving calendar ${calendarName} for ${fullUrl}: 200`);
|
||||||
} else {
|
} else {
|
||||||
|
console.log(`Calendar not found: ${calendarName} for ${fullUrl}: 404`);
|
||||||
res.status(404).json({ error: 'Calendar not found.' });
|
res.status(404).json({ error: 'Calendar not found.' });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -280,4 +280,58 @@ describe('Calendar Merging API', () => {
|
||||||
expect(actualOutput).toBe(expectedOutput);
|
expect(actualOutput).toBe(expectedOutput);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test accessing calendar with and without .ics extension
|
||||||
|
test('Access calendar with and without .ics extension', async () => {
|
||||||
|
// Create a test calendar
|
||||||
|
const response = await request(server)
|
||||||
|
.post('/merge')
|
||||||
|
.send({
|
||||||
|
linkGroupName: 'Extension Test Calendar',
|
||||||
|
calendars: [
|
||||||
|
{
|
||||||
|
url: getTestCalendarFilename('sf_public_holidays.ics'),
|
||||||
|
prefix: 'Test',
|
||||||
|
override: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
// Check if the file was created
|
||||||
|
const filePath = path.join(CALENDARS_DIR, 'Extension_Test_Calendar.ics');
|
||||||
|
expect(fs.existsSync(filePath)).toBe(true);
|
||||||
|
|
||||||
|
// Test accessing without .ics extension
|
||||||
|
const responseWithoutExtension = await request(server)
|
||||||
|
.get('/calendar/Extension_Test_Calendar');
|
||||||
|
|
||||||
|
expect(responseWithoutExtension.status).toBe(200);
|
||||||
|
expect(responseWithoutExtension.headers['content-type']).toMatch(/text\/calendar/);
|
||||||
|
|
||||||
|
// Test accessing with .ics extension
|
||||||
|
const responseWithExtension = await request(server)
|
||||||
|
.get('/calendar/Extension_Test_Calendar.ics');
|
||||||
|
|
||||||
|
expect(responseWithExtension.status).toBe(200);
|
||||||
|
expect(responseWithExtension.headers['content-type']).toMatch(/text\/calendar/);
|
||||||
|
|
||||||
|
// Verify both responses contain the same content
|
||||||
|
expect(responseWithoutExtension.text).toBe(responseWithExtension.text);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test 404 response for non-existent calendar
|
||||||
|
test('Return 404 for non-existent calendar with and without .ics extension', async () => {
|
||||||
|
// Test accessing non-existent calendar without .ics extension
|
||||||
|
const responseWithoutExtension = await request(server)
|
||||||
|
.get('/calendar/NonExistentCalendar');
|
||||||
|
|
||||||
|
expect(responseWithoutExtension.status).toBe(404);
|
||||||
|
|
||||||
|
// Test accessing non-existent calendar with .ics extension
|
||||||
|
const responseWithExtension = await request(server)
|
||||||
|
.get('/calendar/NonExistentCalendar.ics');
|
||||||
|
|
||||||
|
expect(responseWithExtension.status).toBe(404);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue