Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
|||||||
import { TIMEZONES } from "../../../src/utils/timezone-data";
|
import { TIMEZONES } from "../../../src/utils/timezone-data";
|
||||||
|
|
||||||
describe("parseCalendarEvent", () => {
|
describe("parseCalendarEvent", () => {
|
||||||
const baseColor = "#00FF00";
|
const baseColor = { light: "#00FF00" };
|
||||||
const calendarId = "calendar-123";
|
const calendarId = "calendar-123";
|
||||||
|
|
||||||
it("parses a full event with MAILTO in caps correctly", () => {
|
it("parses a full event with MAILTO in caps correctly", () => {
|
||||||
@@ -215,12 +215,12 @@ describe("parseCalendarEvent", () => {
|
|||||||
);
|
);
|
||||||
expect(result.end).toBeDefined();
|
expect(result.end).toBeDefined();
|
||||||
expect(result.timezone).toBeDefined();
|
expect(result.timezone).toBeDefined();
|
||||||
const endDate = new Date(result.end);
|
const endDate = new Date(result.end ?? "");
|
||||||
const startDate = new Date(result.start);
|
const startDate = new Date(result.start);
|
||||||
expect(endDate.getTime() - startDate.getTime()).toBe(60 * 60 * 1000);
|
expect(endDate.getTime() - startDate.getTime()).toBe(60 * 60 * 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns error if end and duration is missing", () => {
|
it("returns 30 minutes event if end and duration are missing", () => {
|
||||||
const rawDataMissing: any = [
|
const rawDataMissing: any = [
|
||||||
["UID", {}, "text", "event-1"],
|
["UID", {}, "text", "event-1"],
|
||||||
["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"],
|
["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"],
|
||||||
@@ -232,7 +232,11 @@ describe("parseCalendarEvent", () => {
|
|||||||
calendarId,
|
calendarId,
|
||||||
"/calendars/test.ics"
|
"/calendars/test.ics"
|
||||||
);
|
);
|
||||||
expect(result.error).toMatch(/missing crucial event param/);
|
expect(result.end).toBeDefined();
|
||||||
|
expect(result.timezone).toBeDefined();
|
||||||
|
const endDate = new Date(result.end ?? "");
|
||||||
|
const startDate = new Date(result.start);
|
||||||
|
expect(endDate.getTime() - startDate.getTime()).toBe(30 * 60 * 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("parses alarm block correctly", () => {
|
it("parses alarm block correctly", () => {
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ export function parseCalendarEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
event.URL = eventURL;
|
event.URL = eventURL;
|
||||||
if (!event.uid || !event.start || (!event.end && !duration)) {
|
if (!event.uid || !event.start) {
|
||||||
console.error(
|
console.error(
|
||||||
`missing crucial event param in calendar ${calendarid} `,
|
`missing crucial event param in calendar ${calendarid} `,
|
||||||
data
|
data
|
||||||
@@ -201,7 +201,9 @@ export function parseCalendarEvent(
|
|||||||
|
|
||||||
if (!event.end) {
|
if (!event.end) {
|
||||||
const start = event.start ? new Date(event.start) : new Date();
|
const start = event.start ? new Date(event.start) : new Date();
|
||||||
const timeToAdd = moment.duration(duration).asMilliseconds();
|
const timeToAdd = duration
|
||||||
|
? moment.duration(duration).asMilliseconds()
|
||||||
|
: moment.duration(30, "minutes").asMilliseconds();
|
||||||
const artificialEnd = new Date(start.getTime() + timeToAdd);
|
const artificialEnd = new Date(start.getTime() + timeToAdd);
|
||||||
event.end = formatDateToICal(artificialEnd, false, eventTimezone);
|
event.end = formatDateToICal(artificialEnd, false, eventTimezone);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user