fix: videoCallUrl not updating when rescheduling with a broken Calendar integration (#11923)
This commit is contained in:
1 parent
7a014761dc
commit
d12a5c5883
9 files changed
+277
-101
No files matched your search
@@ -166,6 +166,7 @@
|
||||
"env-cmd": "^10.1.0",
|
||||
"module-alias": "^2.2.2",
|
||||
"msw": "^0.42.3",
|
||||
"node-html-parser": "^6.1.10",
|
||||
"postcss": "^8.4.18",
|
||||
"tailwindcss": "^3.3.1",
|
||||
"tailwindcss-animate": "^1.0.6",
|
||||
|
||||
@@ -2,7 +2,7 @@ import appStoreMock from "../../../../../tests/libs/__mocks__/app-store";
|
||||
import i18nMock from "../../../../../tests/libs/__mocks__/libServerI18n";
|
||||
import prismock from "../../../../../tests/libs/__mocks__/prisma";
|
||||
|
||||
import type { BookingReference, Attendee } from "@prisma/client";
|
||||
import type { BookingReference, Attendee, Booking } from "@prisma/client";
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import type { WebhookTriggerEvents } from "@prisma/client";
|
||||
import type Stripe from "stripe";
|
||||
@@ -102,7 +102,7 @@ export type InputEventType = {
|
||||
schedule?: InputUser["schedules"][number];
|
||||
} & Partial<Omit<Prisma.EventTypeCreateInput, "users" | "schedule">>;
|
||||
|
||||
type InputBooking = {
|
||||
type WhiteListedBookingProps = {
|
||||
id?: number;
|
||||
uid?: string;
|
||||
userId?: number;
|
||||
@@ -118,6 +118,8 @@ type InputBooking = {
|
||||
})[];
|
||||
};
|
||||
|
||||
type InputBooking = Partial<Omit<Booking, keyof WhiteListedBookingProps>> & WhiteListedBookingProps;
|
||||
|
||||
export const Timezones = {
|
||||
"+5:30": "Asia/Kolkata",
|
||||
"+6:00": "Asia/Dhaka",
|
||||
@@ -1203,3 +1205,35 @@ export const enum BookingLocations {
|
||||
CalVideo = "integrations:daily",
|
||||
ZoomVideo = "integrations:zoom",
|
||||
}
|
||||
|
||||
const getMockAppStatus = ({
|
||||
slug,
|
||||
failures,
|
||||
success,
|
||||
}: {
|
||||
slug: string;
|
||||
failures: number;
|
||||
success: number;
|
||||
}) => {
|
||||
const foundEntry = Object.entries(appStoreMetadata).find(([, app]) => {
|
||||
return app.slug === slug;
|
||||
});
|
||||
if (!foundEntry) {
|
||||
throw new Error("App not found for the slug");
|
||||
}
|
||||
const foundApp = foundEntry[1];
|
||||
return {
|
||||
appName: foundApp.slug,
|
||||
type: foundApp.type,
|
||||
failures,
|
||||
success,
|
||||
errors: [],
|
||||
};
|
||||
};
|
||||
export const getMockFailingAppStatus = ({ slug }: { slug: string }) => {
|
||||
return getMockAppStatus({ slug, failures: 1, success: 0 });
|
||||
};
|
||||
|
||||
export const getMockPassingAppStatus = ({ slug }: { slug: string }) => {
|
||||
return getMockAppStatus({ slug, failures: 0, success: 1 });
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
import prismaMock from "../../../../../tests/libs/__mocks__/prisma";
|
||||
|
||||
import type { WebhookTriggerEvents, Booking, BookingReference, DestinationCalendar } from "@prisma/client";
|
||||
import { parse } from "node-html-parser";
|
||||
import ical from "node-ical";
|
||||
import { expect } from "vitest";
|
||||
import "vitest-fetch-mock";
|
||||
@@ -8,6 +9,7 @@ import "vitest-fetch-mock";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { AppsStatus } from "@calcom/types/Calendar";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { Fixtures } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
@@ -19,14 +21,14 @@ declare global {
|
||||
interface Matchers<R> {
|
||||
toHaveEmail(
|
||||
expectedEmail: {
|
||||
//TODO: Support email HTML parsing to target specific elements
|
||||
htmlToContain?: string;
|
||||
title?: string;
|
||||
to: string;
|
||||
noIcs?: true;
|
||||
ics?: {
|
||||
filename: string;
|
||||
iCalUID: string;
|
||||
};
|
||||
appsStatus?: AppsStatus[];
|
||||
},
|
||||
to: string
|
||||
): R;
|
||||
@@ -38,21 +40,23 @@ expect.extend({
|
||||
toHaveEmail(
|
||||
emails: Fixtures["emails"],
|
||||
expectedEmail: {
|
||||
//TODO: Support email HTML parsing to target specific elements
|
||||
htmlToContain?: string;
|
||||
title?: string;
|
||||
to: string;
|
||||
ics: {
|
||||
filename: string;
|
||||
iCalUID: string;
|
||||
};
|
||||
noIcs: true;
|
||||
appsStatus: AppsStatus[];
|
||||
},
|
||||
to: string
|
||||
) {
|
||||
const { isNot } = this;
|
||||
const testEmail = emails.get().find((email) => email.to.includes(to));
|
||||
const emailsToLog = emails
|
||||
.get()
|
||||
.map((email) => ({ to: email.to, html: email.html, ics: email.icalEvent }));
|
||||
|
||||
if (!testEmail) {
|
||||
logger.silly("All Emails", JSON.stringify({ numEmails: emailsToLog.length, emailsToLog }));
|
||||
return {
|
||||
@@ -63,48 +67,93 @@ expect.extend({
|
||||
const ics = testEmail.icalEvent;
|
||||
const icsObject = ics?.content ? ical.sync.parseICS(ics?.content) : null;
|
||||
|
||||
let isHtmlContained = true;
|
||||
let isToAddressExpected = true;
|
||||
const isIcsFilenameExpected = expectedEmail.ics ? ics?.filename === expectedEmail.ics.filename : true;
|
||||
const isIcsUIDExpected = expectedEmail.ics
|
||||
? !!(icsObject ? icsObject[expectedEmail.ics.iCalUID] : null)
|
||||
: true;
|
||||
const emailDom = parse(testEmail.html);
|
||||
|
||||
if (expectedEmail.htmlToContain) {
|
||||
isHtmlContained = testEmail.html.includes(expectedEmail.htmlToContain);
|
||||
const actualEmailContent = {
|
||||
title: emailDom.querySelector("title")?.innerText,
|
||||
subject: emailDom.querySelector("subject")?.innerText,
|
||||
};
|
||||
|
||||
const expectedEmailContent = {
|
||||
title: expectedEmail.title,
|
||||
};
|
||||
|
||||
const isEmailContentMatched = this.equals(
|
||||
actualEmailContent,
|
||||
expect.objectContaining(expectedEmailContent)
|
||||
);
|
||||
|
||||
if (!isEmailContentMatched) {
|
||||
logger.silly("All Emails", JSON.stringify({ numEmails: emailsToLog.length, emailsToLog }));
|
||||
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `Email content ${isNot ? "is" : "is not"} matching`,
|
||||
actual: actualEmailContent,
|
||||
expected: expectedEmailContent,
|
||||
};
|
||||
}
|
||||
|
||||
isToAddressExpected = expectedEmail.to === testEmail.to;
|
||||
|
||||
if (!isHtmlContained || !isToAddressExpected) {
|
||||
if (!isToAddressExpected) {
|
||||
logger.silly("All Emails", JSON.stringify({ numEmails: emailsToLog.length, emailsToLog }));
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `To address ${isNot ? "is" : "is not"} matching`,
|
||||
actual: testEmail.to,
|
||||
expected: expectedEmail.to,
|
||||
};
|
||||
}
|
||||
|
||||
if (!expectedEmail.noIcs && !isIcsFilenameExpected) {
|
||||
return {
|
||||
pass: false,
|
||||
actual: ics?.filename,
|
||||
expected: expectedEmail.ics.filename,
|
||||
message: () => `ICS Filename ${isNot ? "is" : "is not"} matching`,
|
||||
};
|
||||
}
|
||||
|
||||
if (!expectedEmail.noIcs && !isIcsUIDExpected) {
|
||||
return {
|
||||
pass: false,
|
||||
actual: JSON.stringify(icsObject),
|
||||
expected: expectedEmail.ics.iCalUID,
|
||||
message: () => `Expected ICS UID ${isNot ? "is" : "isn't"} present in actual`,
|
||||
};
|
||||
}
|
||||
|
||||
if (expectedEmail.appsStatus) {
|
||||
const actualAppsStatus = emailDom.querySelectorAll('[data-testid="appsStatus"] li').map((li) => {
|
||||
return li.innerText.trim();
|
||||
});
|
||||
const expectedAppStatus = expectedEmail.appsStatus.map((appStatus) => {
|
||||
if (appStatus.success && !appStatus.failures) {
|
||||
return `${appStatus.appName} ✅`;
|
||||
}
|
||||
return `${appStatus.appName} ❌`;
|
||||
});
|
||||
|
||||
const isAppsStatusCorrect = this.equals(actualAppsStatus, expectedAppStatus);
|
||||
|
||||
if (!isAppsStatusCorrect) {
|
||||
return {
|
||||
pass: false,
|
||||
actual: actualAppsStatus,
|
||||
expected: expectedAppStatus,
|
||||
message: () => `AppsStatus ${isNot ? "is" : "isn't"} matching`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
pass:
|
||||
isHtmlContained &&
|
||||
isToAddressExpected &&
|
||||
(expectedEmail.noIcs ? true : isIcsFilenameExpected && isIcsUIDExpected),
|
||||
message: () => {
|
||||
if (!isHtmlContained) {
|
||||
return `Email HTML is not as expected. Expected:"${expectedEmail.htmlToContain}" isn't contained in "${testEmail.html}"`;
|
||||
}
|
||||
|
||||
if (!isToAddressExpected) {
|
||||
return `Email To address is not as expected. Expected:${expectedEmail.to} isn't equal to ${testEmail.to}`;
|
||||
}
|
||||
|
||||
if (!isIcsFilenameExpected) {
|
||||
return `ICS Filename is not as expected. Expected:${expectedEmail.ics.filename} isn't equal to ${ics?.filename}`;
|
||||
}
|
||||
|
||||
if (!isIcsUIDExpected) {
|
||||
return `ICS UID is not as expected. Expected:${
|
||||
expectedEmail.ics.iCalUID
|
||||
} isn't present in ${JSON.stringify(icsObject)}`;
|
||||
}
|
||||
throw new Error("Unknown error");
|
||||
},
|
||||
pass: true,
|
||||
message: () => `Email ${isNot ? "is" : "isn't"} correct`,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -139,9 +188,10 @@ export function expectWebhookToHaveBeenCalledWith(
|
||||
const parsedBody = JSON.parse((body as string) || "{}");
|
||||
|
||||
expect(parsedBody.triggerEvent).toBe(data.triggerEvent);
|
||||
|
||||
if (parsedBody.payload.metadata?.videoCallUrl) {
|
||||
parsedBody.payload.metadata.videoCallUrl = parsedBody.payload.metadata.videoCallUrl
|
||||
? parsedBody.payload.metadata.videoCallUrl.replace(/\/video\/[a-zA-Z0-9]{22}/, "/video/DYNAMIC_UID")
|
||||
? parsedBody.payload.metadata.videoCallUrl
|
||||
: parsedBody.payload.metadata.videoCallUrl;
|
||||
}
|
||||
if (data.payload) {
|
||||
@@ -195,7 +245,7 @@ export function expectSuccessfulBookingCreationEmails({
|
||||
}) {
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>confirmed_event_type_subject</title>",
|
||||
title: "confirmed_event_type_subject",
|
||||
to: `${organizer.email}`,
|
||||
ics: {
|
||||
filename: "event.ics",
|
||||
@@ -207,7 +257,7 @@ export function expectSuccessfulBookingCreationEmails({
|
||||
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>confirmed_event_type_subject</title>",
|
||||
title: "confirmed_event_type_subject",
|
||||
to: `${booker.name} <${booker.email}>`,
|
||||
ics: {
|
||||
filename: "event.ics",
|
||||
@@ -221,7 +271,7 @@ export function expectSuccessfulBookingCreationEmails({
|
||||
otherTeamMembers.forEach((otherTeamMember) => {
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>confirmed_event_type_subject</title>",
|
||||
title: "confirmed_event_type_subject",
|
||||
// Don't know why but organizer and team members of the eventType don'thave their name here like Booker
|
||||
to: `${otherTeamMember.email}`,
|
||||
ics: {
|
||||
@@ -238,7 +288,7 @@ export function expectSuccessfulBookingCreationEmails({
|
||||
guests.forEach((guest) => {
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>confirmed_event_type_subject</title>",
|
||||
title: "confirmed_event_type_subject",
|
||||
to: `${guest.email}`,
|
||||
ics: {
|
||||
filename: "event.ics",
|
||||
@@ -261,7 +311,7 @@ export function expectBrokenIntegrationEmails({
|
||||
// Broken Integration email is only sent to the Organizer
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>broken_integration</title>",
|
||||
title: "broken_integration",
|
||||
to: `${organizer.email}`,
|
||||
// No ics goes in case of broken integration email it seems
|
||||
// ics: {
|
||||
@@ -274,7 +324,7 @@ export function expectBrokenIntegrationEmails({
|
||||
|
||||
// expect(emails).toHaveEmail(
|
||||
// {
|
||||
// htmlToContain: "<title>confirmed_event_type_subject</title>",
|
||||
// title: "confirmed_event_type_subject",
|
||||
// to: `${booker.name} <${booker.email}>`,
|
||||
// },
|
||||
// `${booker.name} <${booker.email}>`
|
||||
@@ -294,7 +344,7 @@ export function expectCalendarEventCreationFailureEmails({
|
||||
}) {
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>broken_integration</title>",
|
||||
title: "broken_integration",
|
||||
to: `${organizer.email}`,
|
||||
ics: {
|
||||
filename: "event.ics",
|
||||
@@ -306,7 +356,7 @@ export function expectCalendarEventCreationFailureEmails({
|
||||
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>calendar_event_creation_failure_subject</title>",
|
||||
title: "calendar_event_creation_failure_subject",
|
||||
to: `${booker.name} <${booker.email}>`,
|
||||
ics: {
|
||||
filename: "event.ics",
|
||||
@@ -322,27 +372,30 @@ export function expectSuccessfulBookingRescheduledEmails({
|
||||
organizer,
|
||||
booker,
|
||||
iCalUID,
|
||||
appsStatus,
|
||||
}: {
|
||||
emails: Fixtures["emails"];
|
||||
organizer: { email: string; name: string };
|
||||
booker: { email: string; name: string };
|
||||
iCalUID: string;
|
||||
appsStatus: AppsStatus[];
|
||||
}) {
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>event_type_has_been_rescheduled_on_time_date</title>",
|
||||
title: "event_type_has_been_rescheduled_on_time_date",
|
||||
to: `${organizer.email}`,
|
||||
ics: {
|
||||
filename: "event.ics",
|
||||
iCalUID,
|
||||
},
|
||||
appsStatus,
|
||||
},
|
||||
`${organizer.email}`
|
||||
);
|
||||
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>event_type_has_been_rescheduled_on_time_date</title>",
|
||||
title: "event_type_has_been_rescheduled_on_time_date",
|
||||
to: `${booker.name} <${booker.email}>`,
|
||||
ics: {
|
||||
filename: "event.ics",
|
||||
@@ -362,7 +415,7 @@ export function expectAwaitingPaymentEmails({
|
||||
}) {
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>awaiting_payment_subject</title>",
|
||||
title: "awaiting_payment_subject",
|
||||
to: `${booker.name} <${booker.email}>`,
|
||||
noIcs: true,
|
||||
},
|
||||
@@ -381,7 +434,7 @@ export function expectBookingRequestedEmails({
|
||||
}) {
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>event_awaiting_approval_subject</title>",
|
||||
title: "event_awaiting_approval_subject",
|
||||
to: `${organizer.email}`,
|
||||
noIcs: true,
|
||||
},
|
||||
@@ -390,7 +443,7 @@ export function expectBookingRequestedEmails({
|
||||
|
||||
expect(emails).toHaveEmail(
|
||||
{
|
||||
htmlToContain: "<title>booking_submitted_subject</title>",
|
||||
title: "booking_submitted_subject",
|
||||
to: `${booker.email}`,
|
||||
noIcs: true,
|
||||
},
|
||||
@@ -509,6 +562,7 @@ export function expectBookingRescheduledWebhookToHaveBeenFired({
|
||||
location,
|
||||
subscriberUrl,
|
||||
videoCallUrl,
|
||||
payload,
|
||||
}: {
|
||||
organizer: { email: string; name: string };
|
||||
booker: { email: string; name: string };
|
||||
@@ -516,10 +570,12 @@ export function expectBookingRescheduledWebhookToHaveBeenFired({
|
||||
location: string;
|
||||
paidEvent?: boolean;
|
||||
videoCallUrl?: string;
|
||||
payload?: Record<string, unknown>;
|
||||
}) {
|
||||
expectWebhookToHaveBeenCalledWith(subscriberUrl, {
|
||||
triggerEvent: "BOOKING_RESCHEDULED",
|
||||
payload: {
|
||||
...payload,
|
||||
metadata: {
|
||||
...(videoCallUrl ? { videoCallUrl } : null),
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user