[DELEGATION] Edit attendance and events, delete event for someone (#553)

* [#523] added way to manage attendance for delegated calendars

* [DELEGATION] #523 & #524 changed eventURL calculation for delegated events to have the rigth one

* [#524] added drag and drop authorisation to delegated event

* [#524] added tests

* [#524] support for the permission access

* [#524] no edit when delegated event is not public
This commit is contained in:
Camille Moussu
2026-02-19 09:50:29 +01:00
committed by GitHub
parent f520a9b6fe
commit cfb2b59584
52 changed files with 1116 additions and 219 deletions
@@ -30,7 +30,7 @@ describe("Calendar API", () => {
const calendars = await getCalendars(mockUserId);
expect(api.get).toHaveBeenCalledWith(
`dav/calendars/${mockUserId}.json?personal=true&sharedDelegationStatus=accepted&sharedPublicSubscription=true&`,
`dav/calendars/${mockUserId}.json?personal=true&sharedDelegationStatus=accepted&sharedPublicSubscription=true&withRights=true`,
{
headers: { Accept: "application/calendar+json" },
}
@@ -109,8 +109,7 @@ describe("CalendarPopover (editing mode)", () => {
name: "Work Calendar",
description: "Team meetings",
color: { light: "#33B679" },
owner: "alice",
ownerEmails: ["alice@example.com"],
owner: { firstname: "alice", emails: ["alice@example.com"] },
visibility: "public",
events: {},
};
@@ -214,8 +213,7 @@ describe("CalendarPopover - Tabs Scenarios", () => {
name: "Work Calendar",
description: "Team meetings",
color: { light: "#33B679" },
owner: "alice",
ownerEmails: ["alice@example.com"],
owner: { firstname: "alice", emails: ["alice@example.com"] },
visibility: "public",
events: {},
};
@@ -195,9 +195,9 @@ describe("CalendarSlice", () => {
expect(getUserDetailsMock).toHaveBeenCalledWith("u3");
const state = store.getState().calendars;
expect(state.list["u1/cal1"].owner).toContain("Alice");
expect(state.list["u2/cal2"].owner).toContain("Bob");
expect(state.list["u3/cal3"].owner).toContain("Charlie");
expect(state.list["u1/cal1"].owner.firstname).toContain("Alice");
expect(state.list["u2/cal2"].owner.firstname).toContain("Bob");
expect(state.list["u3/cal3"].owner.firstname).toContain("Charlie");
});
it("getCalendarsListAsync deduplicates getUserDetails calls for same ownerId", async () => {
@@ -331,8 +331,8 @@ describe("CalendarSlice", () => {
expect(getUserDetailsMock).toHaveBeenCalledTimes(2);
const state = store.getState().calendars;
expect(state.list["u1/cal1"].owner).toContain("Alice");
expect(state.list["u2/cal2"].owner).toContain("Unknown User");
expect(state.list["u1/cal1"].owner.firstname).toContain("Alice");
expect(state.list["u2/cal2"].owner.lastname).toContain("Unknown User");
expect(result.payload.errors).toBeTruthy();
});
@@ -375,8 +375,7 @@ describe("CalendarSlice", () => {
color: { "apple:color": "#f00" },
name: "Test",
desc: "Desc",
owner: "Owner",
ownerEmails: ["o@example.com"],
owner: { firstname: "Owner", emails: ["o@example.com"] },
};
const state = reducer(
initialState,
@@ -393,8 +392,7 @@ describe("CalendarSlice", () => {
link: "/calendars/u1/c1.json",
name: "Shared",
desc: "Shared Desc",
owner: "O",
ownerEmails: ["o@example.com"],
owner: { firstname: "O", emails: ["o@example.com"] },
};
const mockCal = {
cal: {
@@ -423,8 +421,7 @@ describe("CalendarSlice", () => {
color: { "apple:color": "#aaa" },
events: {},
visibility: "public",
owner: "O",
ownerEmails: ["o@o.com"],
owner: { firstname: "O", emails: ["o@o.com"] },
link: "/calendars/t1.json",
description: "desc",
} as Calendar,
@@ -27,8 +27,7 @@ describe("Calendar - Timezone Integration", () => {
name: "Test Calendar",
description: "",
color: "#33B679",
owner: "user1",
ownerEmails: ["test@test.com"],
owner: { firstname: "user1", emails: ["test@test.com"] },
visibility: "public",
events: {},
},
@@ -174,8 +173,7 @@ describe("EventDisplayPreview - Timezone Display", () => {
id: "user1/cal1",
name: "Test Calendar",
color: "#33B679",
owner: "user1",
ownerEmails: ["test@test.com"],
owner: { firstname: "user1", emails: ["test@test.com"] },
visibility: "public",
events: {
event1: baseEvent,
@@ -17,8 +17,7 @@ describe("refreshCalendarWithSyncToken", () => {
id: "user1/cal1",
name: "Test Calendar",
link: "/calendars/user1/cal1.json",
owner: "Test User",
ownerEmails: ["test@example.com"],
owner: { firstname: "Test User", emails: ["test@example.com"] },
description: "Test calendar description",
delegated: false,
color: { light: "#006BD8", dark: "#FFF" },
@@ -0,0 +1,132 @@
import { Calendar } from "@/features/Calendars/CalendarTypes";
import { AttendanceValidation } from "@/features/Events/AttendanceValidation/AttendanceValidation";
import { ContextualizedEvent } from "@/features/Events/EventsTypes";
import { userAttendee } from "@/features/User/models/attendee";
import { userData } from "@/features/User/userDataTypes";
import { render } from "@testing-library/react";
jest.mock("twake-i18n", () => ({
useI18n: () => ({ t: (key: string) => key }),
}));
jest.mock("@/app/hooks", () => ({
useAppDispatch: () => jest.fn(),
useAppSelector: jest.fn(),
}));
const makeUser = (email: string): userData => ({
email,
given_name: "Alice",
family_name: "User",
name: "Alice User",
sid: "user1",
sub: "user1",
});
const makeContext = (
overrides: Partial<ContextualizedEvent> = {}
): ContextualizedEvent =>
({
event: {
uid: "event-1",
calId: "user1/cal1",
title: "Test",
start: "2024-01-15T10:00:00",
end: "2024-01-15T11:00:00",
organizer: { cal_address: "owner@example.com" },
attendee: [
{ cal_address: "owner@example.com", partstat: "NEEDS-ACTION" },
],
},
calendar: {
id: "user1/cal1",
name: "Test",
delegated: false,
owner: { emails: ["alice@example.com"] },
events: {},
},
currentUserAttendee: {
cal_address: "alice@example.com",
partstat: "NEEDS-ACTION",
},
isOwn: true,
isOrganizer: false,
isRecurring: false,
...overrides,
}) as unknown as ContextualizedEvent;
const noopSetFunc = jest.fn();
describe("AttendanceValidation - delegation", () => {
describe("non-delegated calendar", () => {
it("renders when isOwn and currentUserAttendee exists", () => {
const { container } = render(
<AttendanceValidation
contextualizedEvent={makeContext({ isOwn: true })}
user={makeUser("alice@example.com")}
setAfterChoiceFunc={noopSetFunc}
setOpenEditModePopup={noopSetFunc}
/>
);
expect(container.firstChild).not.toBeNull();
});
it("returns null when not isOwn and not delegated", () => {
const { container } = render(
<AttendanceValidation
contextualizedEvent={makeContext({ isOwn: false })}
user={makeUser("other@example.com")}
setAfterChoiceFunc={noopSetFunc}
setOpenEditModePopup={noopSetFunc}
/>
);
expect(container.firstChild).toBeNull();
});
});
describe("delegated calendar", () => {
const delegatedContext = makeContext({
isOwn: false, // logged-in user is not the owner
calendar: {
id: "user2/cal1",
name: "Delegated Cal",
delegated: true,
owner: { emails: ["owner@example.com"] },
events: {},
} as Calendar,
currentUserAttendee: {
cal_address: "owner@example.com",
partstat: "NEEDS-ACTION",
} as userAttendee,
event: { class: "PUBLIC" },
});
it("renders even when isOwn is false", () => {
const { container } = render(
<AttendanceValidation
contextualizedEvent={delegatedContext}
user={makeUser("alice@example.com")}
setAfterChoiceFunc={noopSetFunc}
setOpenEditModePopup={noopSetFunc}
/>
);
expect(container.firstChild).not.toBeNull();
});
it("renders regardless of currentUserAttendee presence", () => {
const { container } = render(
<AttendanceValidation
contextualizedEvent={{
...delegatedContext,
currentUserAttendee: undefined,
}}
user={makeUser("alice@example.com")}
setAfterChoiceFunc={noopSetFunc}
setOpenEditModePopup={noopSetFunc}
/>
);
// delegated flag alone should keep it visible
expect(container.firstChild).not.toBeNull();
});
});
});
+159 -8
View File
@@ -6,7 +6,7 @@ import {
stringAvatar,
stringToColor,
} from "@/components/Event/utils/eventUtils";
import * as calendarSlice from "@/features/Calendars/CalendarSlice";
import { DelegationAccess } from "@/features/Calendars/CalendarTypes";
import * as eventThunks from "@/features/Calendars/services";
import EventPreviewModal from "@/features/Events/EventDisplayPreview";
import EventUpdateModal from "@/features/Events/EventUpdateModal";
@@ -98,7 +98,7 @@ describe("Event Preview Display", () => {
end: day.toISOString(),
},
},
ownerEmails: ["test@test.com"],
owner: { emails: ["test@test.com"] },
},
"otherCal/cal": {
id: "otherCal/cal",
@@ -659,10 +659,6 @@ describe("Event Preview Display", () => {
fireEvent.click(emailButton);
const event =
preloadedState.calendars.list["667037022b752d0026472254/cal1"].events[
"event1"
];
const expectedUrl = `test/mailto/?uri=mailto:john@test.com&subject=Test%20Event`;
expect(mockOpen).toHaveBeenCalledWith(expectedUrl);
@@ -774,7 +770,7 @@ describe("Event Preview Display", () => {
name: "Calendar 1",
id: "667037022b752d0026472254/cal1",
color: "#FF0000",
ownerEmails: ownerEmails,
owner: { emails: ownerEmails },
events: {
event1: {
uid: "event1",
@@ -988,7 +984,7 @@ describe("Event Preview Display", () => {
attendee: attendees,
},
},
ownerEmails: ["test@test.com"],
owner: { emails: ["test@test.com"] },
},
},
pending: false,
@@ -1555,6 +1551,161 @@ describe("Event Preview Display", () => {
});
});
describe("EventDisplayPreview - delegation", () => {
const delegatedBaseEvent = {
uid: "event-1",
calId: "user2/cal1",
title: "Delegated Event",
start: day.toISOString(),
end: day.toISOString(),
organizer: { cal_address: "owner@example.com" },
attendee: [
{ cal_address: "owner@example.com", partstat: "NEEDS-ACTION" },
],
URL: "/calendars/user2/cal1/event-1.ics",
};
const makeDelegatedState = (
eventOverrides = {},
access: DelegationAccess = {
write: true,
freebusy: false,
read: true,
"write-properties": false,
all: false,
}
) => ({
...preloadedState,
calendars: {
list: {
"user2/cal1": {
id: "user2/cal1",
name: "Delegated Calendar",
delegated: true,
access,
owner: {
id: "user2",
firstname: "Bob",
lastname: "Owner",
emails: ["owner@example.com"],
preferredEmail: "owner@example.com",
},
color: { light: "#FF0000", dark: "#000" },
events: {
"event-1": { ...delegatedBaseEvent, ...eventOverrides },
},
},
},
templist: {},
pending: false,
},
user: {
userData: {
...preloadedState.user.userData,
email: "alice@example.com",
openpaasId: "user1",
},
},
});
describe("edit button visibility", () => {
it("shows edit button when calendar is write-delegated and owner is organizer", () => {
renderWithProviders(
<EventPreviewModal
eventId="event-1"
calId="user2/cal1"
open={true}
onClose={mockOnClose}
/>,
makeDelegatedState()
);
expect(
screen.getByTestId("EditIcon").closest("button")
).toBeInTheDocument();
});
it("does not show edit button when delegated but owner is not organizer", () => {
renderWithProviders(
<EventPreviewModal
eventId="event-1"
calId="user2/cal1"
open={true}
onClose={mockOnClose}
/>,
makeDelegatedState({
organizer: { cal_address: "someone-else@example.com" },
})
);
expect(screen.queryByTestId("EditIcon")).not.toBeInTheDocument();
});
it("does not show edit button when delegated with read-only access", () => {
renderWithProviders(
<EventPreviewModal
eventId="event-1"
calId="user2/cal1"
open={true}
onClose={mockOnClose}
/>,
makeDelegatedState(
{},
{
write: false,
freebusy: false,
read: true,
"write-properties": false,
all: false,
}
)
);
expect(screen.queryByTestId("EditIcon")).not.toBeInTheDocument();
});
});
describe("delete menu item visibility", () => {
it("shows delete option when calendar is write-delegated", () => {
renderWithProviders(
<EventPreviewModal
eventId="event-1"
calId="user2/cal1"
open={true}
onClose={mockOnClose}
/>,
makeDelegatedState()
);
fireEvent.click(screen.getByTestId("MoreVertIcon"));
expect(
screen.getByText("eventPreview.deleteEvent")
).toBeInTheDocument();
});
it("does not show delete option when delegated with read-only access", () => {
renderWithProviders(
<EventPreviewModal
eventId="event-1"
calId="user2/cal1"
open={true}
onClose={mockOnClose}
/>,
makeDelegatedState(
{},
{
write: false,
freebusy: false,
read: true,
"write-properties": false,
all: false,
}
)
);
fireEvent.click(screen.getByTestId("MoreVertIcon"));
expect(
screen.queryByText("eventPreview.deleteEvent")
).not.toBeInTheDocument();
});
});
});
describe("BUGFIX", () => {
it("doesnt render anything next to date of all day preview", () => {
const allDayState = {
@@ -95,7 +95,7 @@ const basePreloadedState = {
],
},
},
ownerEmails: ["test@test.com"],
owner: { emails: ["test@test.com"] },
},
},
pending: false,
@@ -1151,7 +1151,7 @@ describe("Event URL handling for recurring events", () => {
],
},
},
ownerEmails: ["test@test.com"],
owner: { emails: ["test@test.com"] },
},
"667037022b752d0026472254/cal2": {
id: "667037022b752d0026472254/cal2",
@@ -43,7 +43,7 @@ describe("EventUpdateModal - Recurring Event 'Edit All' Handling", () => {
name: "Test Calendar",
color: "#FF0000",
events: {},
ownerEmails: ["test@test.com"],
owner: { emails: ["test@test.com"] },
},
},
pending: false,
+123 -49
View File
@@ -1,3 +1,5 @@
import { Calendar } from "@/features/Calendars/CalendarTypes";
import { VObjectProperty } from "@/features/Calendars/types/CalendarData";
import { CalendarEvent, RepetitionObject } from "@/features/Events/EventsTypes";
import {
calendarEventToJCal,
@@ -10,7 +12,7 @@ import {
describe("parseCalendarEvent", () => {
const baseColor = { light: "#00FF00" };
const calendarId = "calendar-123";
const calendar = { id: "calendar-123" } as Calendar;
it("parses a full event with MAILTO in caps correctly", () => {
const rawData = [
@@ -33,12 +35,12 @@ describe("parseCalendarEvent", () => {
["TRANSP", {}, "text", "OPAQUE"],
["CLASS", {}, "text", "PUBLIC"],
["DTSTAMP", {}, "date-time", "2025-07-18T08:00:00Z"],
] as unknown as [string, Record<string, string>, string, any];
] as VObjectProperty[];
const result = parseCalendarEvent(
rawData,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
@@ -95,12 +97,12 @@ describe("parseCalendarEvent", () => {
["TRANSP", {}, "text", "OPAQUE"],
["CLASS", {}, "text", "PUBLIC"],
["DTSTAMP", {}, "date-time", "2025-07-18T08:00:00Z"],
] as unknown as [string, Record<string, string>, string, any];
] as VObjectProperty[];
const result = parseCalendarEvent(
rawData,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
@@ -137,16 +139,16 @@ describe("parseCalendarEvent", () => {
});
it("marks allday true for DATE format", () => {
const rawData = [
const rawData: VObjectProperty[] = [
["UID", {}, "text", "event-2"],
["DTSTART", {}, "date", "2025-07-20"],
["DTEND", {}, "date", "2025-07-21"],
] as any;
];
const result = parseCalendarEvent(
rawData,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
@@ -154,7 +156,7 @@ describe("parseCalendarEvent", () => {
});
it("appends recurrence-id to UID if present", () => {
const rawData: any = [
const rawData: VObjectProperty[] = [
["UID", {}, "text", "event-2"],
["RECURRENCE-ID", {}, "date-time", "2025-07-18T09:00:00Z"],
["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"],
@@ -163,7 +165,7 @@ describe("parseCalendarEvent", () => {
const result = parseCalendarEvent(
rawData,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
@@ -171,24 +173,26 @@ describe("parseCalendarEvent", () => {
});
it("returns error if UID or start is missing", () => {
const rawDataMissingUid: any = [
const rawDataMissingUid: VObjectProperty[] = [
["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"],
];
const result = parseCalendarEvent(
rawDataMissingUid,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
expect(result.error).toMatch(/missing crucial event param/);
const rawDataMissingStart: any = [["UID", {}, "text", "event-3"]];
const rawDataMissingStart: VObjectProperty[] = [
["UID", {}, "text", "event-3"],
];
const result2 = parseCalendarEvent(
rawDataMissingStart,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
expect(result2.error).toMatch(/missing crucial event param/);
@@ -197,7 +201,7 @@ describe("parseCalendarEvent", () => {
it("returns computed end when there is no end but a duration", () => {
jest.useFakeTimers().setSystemTime(new Date("2025-07-18T00:00:00Z"));
const rawDataMissing: any = [
const rawDataMissing: VObjectProperty[] = [
["UID", {}, "text", "event-1"],
["DTSTART", {}, "date-time", "2025-07-18T09:00:00"],
["duration", {}, "duration", "PT60M"],
@@ -206,7 +210,7 @@ describe("parseCalendarEvent", () => {
const result = parseCalendarEvent(
rawDataMissing,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
expect(result.end).toBeDefined();
@@ -216,7 +220,7 @@ describe("parseCalendarEvent", () => {
});
it("returns 30 minutes event if end and duration are missing", () => {
const rawDataMissing: any = [
const rawDataMissing: VObjectProperty[] = [
["UID", {}, "text", "event-1"],
["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"],
];
@@ -224,7 +228,7 @@ describe("parseCalendarEvent", () => {
const result = parseCalendarEvent(
rawDataMissing,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
expect(result.end).toBeDefined();
@@ -234,23 +238,23 @@ describe("parseCalendarEvent", () => {
});
it("parses alarm block correctly", () => {
const rawData = [
const rawData: VObjectProperty[] = [
["UID", {}, "text", "event-5"],
["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"],
] as any;
];
const valarm: any = [
const valarm = [
"VALARM",
[
["ACTION", {}, "text", "DISPLAY"],
["TRIGGER", {}, "duration", "-PT15M"],
],
];
] as unknown as VObjectProperty[];
const result = parseCalendarEvent(
rawData,
baseColor,
calendarId,
calendar,
"/calendars/test.ics",
valarm
);
@@ -266,12 +270,12 @@ describe("parseCalendarEvent", () => {
["DTEND", {}, "date-time", "2025-07-18T10:00:00Z"],
["ATTENDEE", {}, "cal-address", "john@example.com"],
["ORGANIZER", {}, "cal-address", "jane@example.com"],
] as unknown as [string, Record<string, string>, string, any];
] as VObjectProperty[];
const result = parseCalendarEvent(
rawData,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
@@ -297,12 +301,12 @@ describe("parseCalendarEvent", () => {
["UID", {}, "text", "event-tz"],
["DTSTART", { tzid: "Asia/Bangkok" }, "date-time", "2025-07-18T09:00:00"],
["DTEND", { tzid: "Asia/Bangkok" }, "date-time", "2025-07-18T10:00:00"],
] as unknown as [string, Record<string, string>, string, any];
] as VObjectProperty[];
const result = parseCalendarEvent(
rawData,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
@@ -319,12 +323,12 @@ describe("parseCalendarEvent", () => {
["UID", {}, "text", "event-utc"],
["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"],
["DTEND", {}, "date-time", "2025-07-18T10:00:00Z"],
] as unknown as [string, Record<string, string>, string, any];
] as VObjectProperty[];
const result = parseCalendarEvent(
rawData,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
@@ -337,12 +341,12 @@ describe("parseCalendarEvent", () => {
["UID", {}, "text", "event-allday"],
["DTSTART", {}, "date", "2025-07-18"],
["DTEND", {}, "date", "2025-07-19"],
] as unknown as [string, Record<string, string>, string, any];
] as VObjectProperty[];
const result = parseCalendarEvent(
rawData,
baseColor,
calendarId,
calendar,
"/calendars/test.ics"
);
@@ -391,8 +395,8 @@ describe("calendarEventToJCal", () => {
expect(vevent[0]).toBe("vevent");
const props = vevent[1];
const dtstart = props.find((p: any[]) => p[0] === "dtstart");
const dtend = props.find((p: any[]) => p[0] === "dtend");
const dtstart = props.find((p: VObjectProperty) => p[0] === "dtstart");
const dtend = props.find((p: VObjectProperty) => p[0] === "dtend");
expect(dtstart).toBeDefined();
expect(dtstart[1]).toEqual({ tzid: "Europe/Paris" });
@@ -474,7 +478,7 @@ describe("calendarEventToJCal", () => {
});
it("converts with alarm included", () => {
const mockEvent: any = {
const mockEvent = {
uid: "event-10",
title: "Alarm Event",
start: "2025-07-20T07:00:00.000Z",
@@ -483,7 +487,7 @@ describe("calendarEventToJCal", () => {
allday: false,
alarm: { trigger: "-PT10M", action: "DISPLAY" },
attendee: [],
};
} as unknown as CalendarEvent;
const result = calendarEventToJCal(mockEvent, "owner@example.com");
const vevent = result[2][0];
@@ -498,7 +502,7 @@ describe("calendarEventToJCal", () => {
});
it("converts all-day events", () => {
const mockEvent: any = {
const mockEvent = {
uid: "event-11",
title: "All Day",
start: "2025-07-21T00:00:00.000Z",
@@ -506,7 +510,7 @@ describe("calendarEventToJCal", () => {
timezone: "Europe/Paris",
allday: true,
attendee: [],
};
} as unknown as CalendarEvent;
const result = calendarEventToJCal(mockEvent);
const veventProps = result[2][0][1];
@@ -843,7 +847,9 @@ describe("calendarEventToJCal", () => {
const [vevent] = result[2];
const props = vevent[1];
const sequenceProp = props.find((p: any[]) => p[0] === "sequence");
const sequenceProp = props.find(
(p: VObjectProperty) => p[0] === "sequence"
);
expect(sequenceProp).toBeDefined();
expect(sequenceProp).toEqual(["sequence", {}, "integer", 3]);
});
@@ -864,7 +870,9 @@ describe("calendarEventToJCal", () => {
const [vevent] = result[2];
const props = vevent[1];
const sequenceProp = props.find((p: any[]) => p[0] === "sequence");
const sequenceProp = props.find(
(p: VObjectProperty) => p[0] === "sequence"
);
expect(sequenceProp).toBeDefined();
expect(sequenceProp).toEqual(["sequence", {}, "integer", 1]);
});
@@ -887,7 +895,9 @@ describe("calendarEventToJCal", () => {
const [vevent] = result[2];
const props = vevent[1];
const sequenceProp = props.find((p: any[]) => p[0] === "sequence");
const sequenceProp = props.find(
(p: VObjectProperty) => p[0] === "sequence"
);
expect(sequenceProp).toBeDefined();
expect(sequenceProp).toEqual(["sequence", {}, "integer", 2]);
});
@@ -910,18 +920,22 @@ describe("calendarEventToJCal", () => {
const [vevent] = result[2];
const props = vevent[1];
const sequenceProp = props.find((p: any[]) => p[0] === "sequence");
const sequenceProp = props.find(
(p: VObjectProperty) => p[0] === "sequence"
);
expect(sequenceProp).toBeDefined();
expect(sequenceProp).toEqual(["sequence", {}, "integer", 5]);
// Also verify recurrence-id is present
const recurrenceIdProp = props.find((p: any[]) => p[0] === "recurrence-id");
const recurrenceIdProp = props.find(
(p: VObjectProperty) => p[0] === "recurrence-id"
);
expect(recurrenceIdProp).toBeDefined();
});
});
describe("combineMasterDateWithFormTime", () => {
const mockFormatDateTime = (iso: string, tz: string) => {
const mockFormatDateTime = (iso: string) => {
const date = new Date(iso);
const year = date.getUTCFullYear();
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
@@ -1127,12 +1141,6 @@ describe("normalizeTimezone", () => {
describe("detectRecurringEventChanges", () => {
const mockResolveTimezone = (tz: string) => tz;
const mockFormatDateTime = (iso: string, tz: string) => {
const date = new Date(iso);
const hour = String(date.getUTCHours()).padStart(2, "0");
const minute = String(date.getUTCMinutes()).padStart(2, "0");
return `2025-10-14T${hour}:${minute}`;
};
it("should detect when only time changes", () => {
const oldEvent = {
@@ -1346,3 +1354,69 @@ describe("detectRecurringEventChanges", () => {
expect(result.repetitionRulesChanged).toBe(true);
});
});
describe("parseCalendarEvent - delegated calendar URL handling", () => {
const baseColor = { light: "#00FF00" };
const rawData: VObjectProperty[] = [
["uid", {}, "text", "event-uid-123"],
["dtstart", {}, "date-time", "20240115T100000Z"],
["dtend", {}, "date-time", "20240115T110000Z"],
["summary", {}, "text", "Test Event"],
];
const eventURL = "/calendars/user2/cal1/event-uid-123.ics";
describe("non-delegated calendar", () => {
const calendar = {
id: "user1/cal1",
delegated: false,
link: "/calendars/user1/cal1.json",
} as Calendar;
it("uses the raw eventURL as-is", () => {
const result = parseCalendarEvent(rawData, baseColor, calendar, eventURL);
expect(result.URL).toBe(eventURL);
});
});
describe("delegated calendar", () => {
const calendar = {
id: "user2/cal1",
delegated: true,
link: "/calendars/user2/cal1.json",
owner: { emails: ["owner@example.com"] },
} as unknown as Calendar;
it("rewrites URL using calendar link base path", () => {
const result = parseCalendarEvent(rawData, baseColor, calendar, eventURL);
expect(result.URL).toBe("/calendars/user2/cal1/event-uid-123.ics");
});
it("preserves the event filename from the original URL", () => {
const differentSourceURL = "/calendars/someother/path/event-uid-123.ics";
const result = parseCalendarEvent(
rawData,
baseColor,
calendar,
differentSourceURL
);
// filename is extracted and rebased onto calendar link
expect(result.URL).toMatch(
/\/calendars\/user2\/cal1\/event-uid-123\.ics$/
);
});
it("still sets calId from calendar.id", () => {
const result = parseCalendarEvent(rawData, baseColor, calendar, eventURL);
expect(result.calId).toBe("user2/cal1");
});
});
describe("empty calendar object (used in deleteEventInstance)", () => {
it("does not throw and sets URL to empty string", () => {
const result = parseCalendarEvent(rawData, baseColor, {} as Calendar, "");
expect(result.URL).toBe("");
expect(result.calId).toBeUndefined();
});
});
});
@@ -26,7 +26,7 @@ describe("EventSearchBar", () => {
name: "Calendar personal",
id: "user1/cal1",
color: { light: "#FF0000", dark: "#000" },
ownerEmails: ["alice@example.com"],
owner: { emails: ["alice@example.com"] },
events: {
event1: {
id: "event1",
@@ -58,7 +58,7 @@ describe("EventSearchBar", () => {
delegated: true,
id: "user2/cal1",
color: { light: "#FF0000", dark: "#000" },
ownerEmails: ["alice@example.com"],
owner: { emails: ["alice@example.com"] },
events: {
event1: {
id: "event1",
@@ -89,7 +89,7 @@ describe("EventSearchBar", () => {
name: "Calendar shared",
id: "user3/cal1",
color: { light: "#FF0000", dark: "#000" },
ownerEmails: ["alice@example.com"],
owner: { emails: ["alice@example.com"] },
events: {
event1: {
id: "event1",
@@ -24,7 +24,7 @@ describe("SearchResultsPage", () => {
name: "Calendar personal",
id: "user1/cal1",
color: { light: "#FF0000", dark: "#000" },
ownerEmails: ["alice@example.com"],
owner: { emails: ["alice@example.com"] },
events: {
event1: {
id: "event1",
@@ -56,7 +56,7 @@ describe("SearchResultsPage", () => {
delegated: true,
id: "user2/cal1",
color: { light: "#FF0000", dark: "#000" },
ownerEmails: ["alice@example.com"],
owner: { emails: ["alice@example.com"] },
events: {
event1: {
id: "event1",
@@ -87,7 +87,7 @@ describe("SearchResultsPage", () => {
name: "Calendar shared",
id: "user3/cal1",
color: { light: "#FF0000", dark: "#000" },
ownerEmails: ["alice@example.com"],
owner: { emails: ["alice@example.com"] },
events: {
event1: {
id: "event1",