diff --git a/packages/emails/lib/generateIcsString.ts b/packages/emails/lib/generateIcsString.ts index c70b8ba818..e369f55a45 100644 --- a/packages/emails/lib/generateIcsString.ts +++ b/packages/emails/lib/generateIcsString.ts @@ -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, }); diff --git a/packages/emails/lib/test/generateIcsString.test.ts b/packages/emails/lib/test/generateIcsString.test.ts index 12f18956d1..3cfeedbffe 100644 --- a/packages/emails/lib/test/generateIcsString.test.ts +++ b/packages/emails/lib/test/generateIcsString.test.ts @@ -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 }); }); }); diff --git a/packages/lib/test/builder.ts b/packages/lib/test/builder.ts index 106547540a..bc1b23431b 100644 --- a/packages/lib/test/builder.ts +++ b/packages/lib/test/builder.ts @@ -161,7 +161,10 @@ export const buildSubscriberEvent = (booking?: Partial) => { }; }; -export const buildCalendarEvent = (event?: Partial): CalendarEvent => { +export const buildCalendarEvent = ( + event?: Partial, + omitVideoCallData?: boolean +): CalendarEvent => { const uid = faker.datatype.uuid(); return { uid, @@ -176,7 +179,7 @@ export const buildCalendarEvent = (event?: Partial): CalendarEven customInputs: {}, additionalNotes: faker.lorem.paragraph(), organizer: buildPerson(), - videoCallData: buildVideoCallData(), + ...(!omitVideoCallData && { videoCallData: buildVideoCallData() }), ...event, }; };