|
|
|
@ -1,8 +1,6 @@
|
|
|
|
|
import request from 'supertest';
|
|
|
|
|
import express from 'express';
|
|
|
|
|
import fs from 'fs';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import { jest } from '@jest/globals';
|
|
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
|
|
|
|
|
|
// ESM equivalent of __dirname
|
|
|
|
@ -15,15 +13,12 @@ const EXPECTED_OUTPUTS_DIR = path.join(__dirname, 'expected_outputs');
|
|
|
|
|
|
|
|
|
|
let server;
|
|
|
|
|
process.chdir(__dirname)
|
|
|
|
|
// console.log(process.cwd());
|
|
|
|
|
import app from '../src/server.js';
|
|
|
|
|
|
|
|
|
|
const normalizeLineEndings = (str) => str.replace(/\r\n/g, '\r\n').trimEnd(); // Normalize to CRLF
|
|
|
|
|
const app = await import('../src/server');
|
|
|
|
|
|
|
|
|
|
describe('Calendar Merging API', () => {
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
|
// Start the server
|
|
|
|
|
server = app.listen(0);
|
|
|
|
|
server = app.default.listen(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
@ -59,19 +54,15 @@ describe('Calendar Merging API', () => {
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
// Check if the file was created in the test directory
|
|
|
|
|
const filePath = path.join(CALENDARS_DIR, 'nextcloud-minimal.ics');
|
|
|
|
|
// console.log('Checking if file exists at:', filePath);
|
|
|
|
|
console.log('Checking if file exists at:', filePath);
|
|
|
|
|
expect(fs.existsSync(filePath)).toBe(true);
|
|
|
|
|
|
|
|
|
|
// Load expected output
|
|
|
|
|
const expectedOutput = fs.readFileSync(input, 'utf8');
|
|
|
|
|
const actualOutput = fs.readFileSync(filePath, 'utf8');
|
|
|
|
|
|
|
|
|
|
// Normalize line endings
|
|
|
|
|
const normalizedActual = normalizeLineEndings(actualOutput);
|
|
|
|
|
const normalizedExpected = normalizeLineEndings(expectedOutput);
|
|
|
|
|
|
|
|
|
|
//compare
|
|
|
|
|
expect(normalizedActual).toBe(normalizedExpected);
|
|
|
|
|
expect(actualOutput).toBe(expectedOutput);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Preserve google calendar', async () => {
|
|
|
|
@ -91,46 +82,42 @@ describe('Calendar Merging API', () => {
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
// Check if the file was created in the test directory
|
|
|
|
|
const filePath = path.join(CALENDARS_DIR, 'google-calendar-minimal.ics');
|
|
|
|
|
// console.log('Checking if file exists at:', filePath);
|
|
|
|
|
console.log('Checking if file exists at:', filePath);
|
|
|
|
|
expect(fs.existsSync(filePath)).toBe(true);
|
|
|
|
|
|
|
|
|
|
// Load expected output
|
|
|
|
|
const expectedOutput = fs.readFileSync(input, 'utf8');
|
|
|
|
|
const actualOutput = fs.readFileSync(filePath, 'utf8');
|
|
|
|
|
|
|
|
|
|
// Normalize line endings
|
|
|
|
|
const normalizedActual = normalizeLineEndings(actualOutput);
|
|
|
|
|
const normalizedExpected = normalizeLineEndings(expectedOutput);
|
|
|
|
|
|
|
|
|
|
//compare
|
|
|
|
|
expect(normalizedActual).toBe(normalizedExpected);
|
|
|
|
|
expect(actualOutput).toBe(expectedOutput);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// test('Preserve date-based calendar', async () => {
|
|
|
|
|
// const input = getTestCalendarFilename('US_Holidays.ics');
|
|
|
|
|
// const response = await request(server)
|
|
|
|
|
// .post('/merge')
|
|
|
|
|
// .send({
|
|
|
|
|
// linkGroupName: 'US Holidays',
|
|
|
|
|
// calendars: [
|
|
|
|
|
// {
|
|
|
|
|
// url: input,
|
|
|
|
|
// prefix: '',
|
|
|
|
|
// override: false,
|
|
|
|
|
// },
|
|
|
|
|
// ],
|
|
|
|
|
// });
|
|
|
|
|
// expect(response.status).toBe(200);
|
|
|
|
|
// // Check if the file was created in the test directory
|
|
|
|
|
// const filePath = path.join(CALENDARS_DIR, 'US_Holidays.ics');
|
|
|
|
|
// console.log('Checking if file exists at:', filePath);
|
|
|
|
|
// 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('Preserve date-based calendar', async () => {
|
|
|
|
|
const input = getTestCalendarFilename('US_Holidays.ics');
|
|
|
|
|
const response = await request(server)
|
|
|
|
|
.post('/merge')
|
|
|
|
|
.send({
|
|
|
|
|
linkGroupName: 'US Holidays',
|
|
|
|
|
calendars: [
|
|
|
|
|
{
|
|
|
|
|
url: input,
|
|
|
|
|
prefix: '',
|
|
|
|
|
override: false,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
// Check if the file was created in the test directory
|
|
|
|
|
const filePath = path.join(CALENDARS_DIR, 'US_Holidays.ics');
|
|
|
|
|
console.log('Checking if file exists at:', filePath);
|
|
|
|
|
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 date-based calendar', async () => {
|
|
|
|
|
// const response = await request(server)
|
|
|
|
|