fix: Add location to ics file (#13646)

* Add location to ics file

* Add tests

* fix: type err

---------

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: Udit Takkar <udit222001@gmail.com>
This commit is contained in:
Joe Au-Yeung
2024-02-13 16:35:04 +05:30
committed by GitHub
co-authored by Peer Richelsen Udit Takkar Udit Takkar
parent d4f41e803a
commit bb3b262bd7
3 changed files with 140 additions and 76 deletions
+4
View File
@@ -6,6 +6,7 @@ import { RRule } from "rrule";
import dayjs from "@calcom/dayjs";
import { getRichDescription } from "@calcom/lib/CalEventParser";
import { getWhen } from "@calcom/lib/CalEventParser";
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
export enum BookingAction {
@@ -33,6 +34,8 @@ const generateIcsString = ({
isRequestReschedule?: boolean;
t?: TFunction;
}) => {
const location = getVideoCallUrlFromCalEvent(event) || event.location;
// Taking care of recurrence rule
let recurrenceRule: string | undefined = undefined;
const partstat: ParticipationStatus = "ACCEPTED";
@@ -93,6 +96,7 @@ const generateIcsString = ({
}))
: []),
],
location: location ?? undefined,
method: "REQUEST",
status,
});
@@ -5,6 +5,7 @@ import type { CalendarEvent } from "@calcom/types/Calendar";
import { test } from "@calcom/web/test/fixtures/fixtures";
import { buildCalendarEvent, buildPerson } from "../../../lib/test/builder";
import { buildVideoCallData } from "../../../lib/test/builder";
import generateIcsString from "../generateIcsString";
const assertHasIcsString = (icsString: string | undefined) => {
@@ -49,89 +50,145 @@ const testIcsStringContains = ({
};
describe("generateIcsString", () => {
test("when bookingAction is Create", () => {
const event = buildCalendarEvent({
iCalSequence: 0,
attendees: [buildPerson()],
describe("booking actions", () => {
test("when bookingAction is Create", () => {
const event = buildCalendarEvent({
iCalSequence: 0,
attendees: [buildPerson()],
});
const title = "new_event_scheduled_recurring";
const subtitle = "emailed_you_and_any_other_attendees";
const status = "CONFIRMED";
const icsString = generateIcsString({
event: event,
title,
subtitle,
role: "organizer",
status,
});
const assertedIcsString = assertHasIcsString(icsString);
testIcsStringContains({ icsString: assertedIcsString, event, status });
});
test("when bookingAction is Cancel", () => {
const event = buildCalendarEvent({
iCalSequence: 0,
attendees: [buildPerson()],
});
const title = "event_request_cancelled";
const subtitle = "emailed_you_and_any_other_attendees";
const status = "CANCELLED";
const title = "new_event_scheduled_recurring";
const subtitle = "emailed_you_and_any_other_attendees";
const status = "CONFIRMED";
const icsString = generateIcsString({
event: event,
title,
subtitle,
role: "organizer",
status,
});
const icsString = generateIcsString({
event: event,
title,
subtitle,
role: "organizer",
status,
const assertedIcsString = assertHasIcsString(icsString);
testIcsStringContains({ icsString: assertedIcsString, event, status });
});
test("when bookingAction is Reschedule", () => {
const event = buildCalendarEvent({
iCalSequence: 0,
attendees: [buildPerson()],
});
const title = "event_type_has_been_rescheduled";
const subtitle = "emailed_you_and_any_other_attendees";
const status = "CONFIRMED";
const assertedIcsString = assertHasIcsString(icsString);
const icsString = generateIcsString({
event: event,
title,
subtitle,
role: "organizer",
status,
});
testIcsStringContains({ icsString: assertedIcsString, event, status });
const assertedIcsString = assertHasIcsString(icsString);
testIcsStringContains({ icsString: assertedIcsString, event, status });
});
test("when bookingAction is RequestReschedule", () => {
const event = buildCalendarEvent({
iCalSequence: 0,
attendees: [buildPerson()],
});
const title = "request_reschedule_title_organizer";
const subtitle = "request_reschedule_subtitle_organizer";
const status = "CANCELLED";
const icsString = generateIcsString({
event: event,
title,
subtitle,
role: "organizer",
status,
});
const assertedIcsString = assertHasIcsString(icsString);
testIcsStringContains({ icsString: assertedIcsString, event, status });
});
});
test("when bookingAction is Cancel", () => {
const event = buildCalendarEvent({
iCalSequence: 0,
attendees: [buildPerson()],
describe("set location", () => {
test("Location is a video link", () => {
const videoCallData = buildVideoCallData();
const event = buildCalendarEvent(
{
iCalSequence: 0,
attendees: [buildPerson()],
videoCallData,
},
true
);
const title = "request_reschedule_title_organizer";
const subtitle = "request_reschedule_subtitle_organizer";
const status = "CANCELLED";
const icsString = generateIcsString({
event: event,
title,
subtitle,
role: "organizer",
status,
});
const assertedIcsString = assertHasIcsString(icsString);
expect(icsString).toEqual(expect.stringContaining(`LOCATION:${videoCallData.url}`));
});
const title = "event_request_cancelled";
const subtitle = "emailed_you_and_any_other_attendees";
const status = "CANCELLED";
// Could be custom link, address, or phone number
test("Location is a string", () => {
const event = buildCalendarEvent(
{
iCalSequence: 0,
attendees: [buildPerson()],
location: "+1234567890",
},
true
);
const title = "request_reschedule_title_organizer";
const subtitle = "request_reschedule_subtitle_organizer";
const status = "CANCELLED";
const icsString = generateIcsString({
event: event,
title,
subtitle,
role: "organizer",
status,
const icsString = generateIcsString({
event: event,
title,
subtitle,
role: "organizer",
status,
});
const assertedIcsString = assertHasIcsString(icsString);
expect(icsString).toEqual(expect.stringContaining(`LOCATION:${event.location}`));
});
const assertedIcsString = assertHasIcsString(icsString);
testIcsStringContains({ icsString: assertedIcsString, event, status });
});
test("when bookingAction is Reschedule", () => {
const event = buildCalendarEvent({
iCalSequence: 0,
attendees: [buildPerson()],
});
const title = "event_type_has_been_rescheduled";
const subtitle = "emailed_you_and_any_other_attendees";
const status = "CONFIRMED";
const icsString = generateIcsString({
event: event,
title,
subtitle,
role: "organizer",
status,
});
const assertedIcsString = assertHasIcsString(icsString);
testIcsStringContains({ icsString: assertedIcsString, event, status });
});
test("when bookingAction is RequestReschedule", () => {
const event = buildCalendarEvent({
iCalSequence: 0,
attendees: [buildPerson()],
});
const title = "request_reschedule_title_organizer";
const subtitle = "request_reschedule_subtitle_organizer";
const status = "CANCELLED";
const icsString = generateIcsString({
event: event,
title,
subtitle,
role: "organizer",
status,
});
const assertedIcsString = assertHasIcsString(icsString);
testIcsStringContains({ icsString: assertedIcsString, event, status });
});
});
+5 -2
View File
@@ -161,7 +161,10 @@ export const buildSubscriberEvent = (booking?: Partial<Booking>) => {
};
};
export const buildCalendarEvent = (event?: Partial<CalendarEvent>): CalendarEvent => {
export const buildCalendarEvent = (
event?: Partial<CalendarEvent>,
omitVideoCallData?: boolean
): CalendarEvent => {
const uid = faker.datatype.uuid();
return {
uid,
@@ -176,7 +179,7 @@ export const buildCalendarEvent = (event?: Partial<CalendarEvent>): CalendarEven
customInputs: {},
additionalNotes: faker.lorem.paragraph(),
organizer: buildPerson(),
videoCallData: buildVideoCallData(),
...(!omitVideoCallData && { videoCallData: buildVideoCallData() }),
...event,
};
};