fix: Fix 'Book a new time' link in request-reschedule for Team Event (#12261)
Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
19 files changed
+510
-48
No files matched your search
@@ -5,12 +5,15 @@ import { v5 as uuidv5 } from "uuid";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { CalendarEventClass } from "./class";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["builders", "CalendarEvent", "builder"] });
|
||||
const translator = short();
|
||||
const userSelect = Prisma.validator<Prisma.UserArgs>()({
|
||||
select: {
|
||||
@@ -149,6 +152,7 @@ export class CalendarEventBuilder implements ICalendarEventBuilder {
|
||||
} catch (error) {
|
||||
throw new Error("Error while getting eventType");
|
||||
}
|
||||
log.debug("getEventFromEventId.resultEventType", safeStringify(resultEventType));
|
||||
return resultEventType;
|
||||
}
|
||||
|
||||
@@ -244,7 +248,7 @@ export class CalendarEventBuilder implements ICalendarEventBuilder {
|
||||
|
||||
let slug = "";
|
||||
if (isTeam && eventType?.team?.slug) {
|
||||
slug = `/team/${eventType.team?.slug}`;
|
||||
slug = `team/${eventType.team?.slug}/${eventType.slug}`;
|
||||
} else if (isDynamic) {
|
||||
const dynamicSlug = isDynamic ? `${booking.dynamicGroupSlugRef}/${booking.dynamicEventSlugRef}` : "";
|
||||
slug = dynamicSlug;
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { Booking } from "@prisma/client";
|
||||
import type { Booking } from "@prisma/client";
|
||||
|
||||
import { CalendarEventBuilder } from "./builder";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
|
||||
import type { CalendarEventBuilder } from "./builder";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["builders", "CalendarEvent", "director"] });
|
||||
export class CalendarEventDirector {
|
||||
private builder!: CalendarEventBuilder;
|
||||
private existingBooking!: Partial<Booking>;
|
||||
@@ -44,6 +48,10 @@ export class CalendarEventDirector {
|
||||
this.builder.setDescription(this.builder.eventType.description);
|
||||
this.builder.setNotes(this.existingBooking.description);
|
||||
this.builder.buildRescheduleLink(this.existingBooking, this.builder.eventType);
|
||||
log.debug(
|
||||
"buildForRescheduleEmail",
|
||||
safeStringify({ existingBooking: this.existingBooking, builder: this.builder })
|
||||
);
|
||||
} else {
|
||||
throw new Error("buildForRescheduleEmail.missing.params.required");
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { describe } from "vitest";
|
||||
|
||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
import { setupAndTeardown } from "./lib/setupAndTeardown";
|
||||
import { setupAndTeardown } from "@calcom/web/test/utils/bookingScenario/setupAndTeardown";
|
||||
|
||||
describe("handleNewBooking", () => {
|
||||
setupAndTeardown();
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
mockVideoAppToCrashOnCreateMeeting,
|
||||
BookingLocations,
|
||||
} from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
||||
import { createMockNextJsRequest } from "@calcom/web/test/utils/bookingScenario/createMockNextJsRequest";
|
||||
import {
|
||||
expectWorkflowToBeTriggered,
|
||||
expectSuccessfulBookingCreationEmails,
|
||||
@@ -49,11 +50,9 @@ import {
|
||||
expectBrokenIntegrationEmails,
|
||||
expectSuccessfulCalendarEventCreationInCalendar,
|
||||
} from "@calcom/web/test/utils/bookingScenario/expects";
|
||||
|
||||
import { createMockNextJsRequest } from "./lib/createMockNextJsRequest";
|
||||
import { getMockRequestDataForBooking } from "./lib/getMockRequestDataForBooking";
|
||||
import { setupAndTeardown } from "./lib/setupAndTeardown";
|
||||
import { testWithAndWithoutOrg } from "./lib/test";
|
||||
import { getMockRequestDataForBooking } from "@calcom/web/test/utils/bookingScenario/getMockRequestDataForBooking";
|
||||
import { setupAndTeardown } from "@calcom/web/test/utils/bookingScenario/setupAndTeardown";
|
||||
import { testWithAndWithoutOrg } from "@calcom/web/test/utils/bookingScenario/test";
|
||||
|
||||
export type CustomNextApiRequest = NextApiRequest & Request;
|
||||
|
||||
@@ -940,7 +939,7 @@ describe("handleNewBooking", () => {
|
||||
});
|
||||
await handleNewBooking(req);
|
||||
|
||||
expectBrokenIntegrationEmails({ booker, organizer, emails });
|
||||
expectBrokenIntegrationEmails({ organizer, emails });
|
||||
|
||||
expectBookingCreatedWebhookToHaveBeenFired({
|
||||
booker,
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import { createMocks } from "node-mocks-http";
|
||||
|
||||
import type { CustomNextApiRequest, CustomNextApiResponse } from "../fresh-booking.test";
|
||||
|
||||
export function createMockNextJsRequest(...args: Parameters<typeof createMocks>) {
|
||||
return createMocks<CustomNextApiRequest, CustomNextApiResponse>(...args);
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
import { getDate } from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
||||
|
||||
export const DEFAULT_TIMEZONE_BOOKER = "Asia/Kolkata";
|
||||
export function getBasicMockRequestDataForBooking() {
|
||||
return {
|
||||
start: `${getDate({ dateIncrement: 1 }).dateString}T04:00:00.000Z`,
|
||||
end: `${getDate({ dateIncrement: 1 }).dateString}T04:30:00.000Z`,
|
||||
eventTypeSlug: "no-confirmation",
|
||||
timeZone: DEFAULT_TIMEZONE_BOOKER,
|
||||
language: "en",
|
||||
user: "teampro",
|
||||
metadata: {},
|
||||
hasHashedBookingLink: false,
|
||||
hashedLink: null,
|
||||
};
|
||||
}
|
||||
export function getMockRequestDataForBooking({
|
||||
data,
|
||||
}: {
|
||||
data: Partial<ReturnType<typeof getBasicMockRequestDataForBooking>> & {
|
||||
eventTypeId: number;
|
||||
rescheduleUid?: string;
|
||||
bookingUid?: string;
|
||||
recurringEventId?: string;
|
||||
recurringCount?: number;
|
||||
responses: {
|
||||
email: string;
|
||||
name: string;
|
||||
location: { optionValue: ""; value: string };
|
||||
};
|
||||
};
|
||||
}) {
|
||||
return {
|
||||
...getBasicMockRequestDataForBooking(),
|
||||
...data,
|
||||
};
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { beforeEach, afterEach } from "vitest";
|
||||
|
||||
import {
|
||||
enableEmailFeature,
|
||||
mockNoTranslations,
|
||||
} from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
||||
|
||||
export function setupAndTeardown() {
|
||||
beforeEach(() => {
|
||||
// Required to able to generate token in email in some cases
|
||||
process.env.CALENDSO_ENCRYPTION_KEY = "abcdefghjnmkljhjklmnhjklkmnbhjui";
|
||||
process.env.STRIPE_WEBHOOK_SECRET = "MOCK_STRIPE_WEBHOOK_SECRET";
|
||||
// We are setting it in vitest.config.ts because otherwise it's too late to set it.
|
||||
// process.env.DAILY_API_KEY = "MOCK_DAILY_API_KEY";
|
||||
mockNoTranslations();
|
||||
// mockEnableEmailFeature();
|
||||
enableEmailFeature();
|
||||
globalThis.testEmails = [];
|
||||
fetchMock.resetMocks();
|
||||
});
|
||||
afterEach(() => {
|
||||
delete process.env.CALENDSO_ENCRYPTION_KEY;
|
||||
delete process.env.STRIPE_WEBHOOK_SECRET;
|
||||
delete process.env.DAILY_API_KEY;
|
||||
globalThis.testEmails = [];
|
||||
fetchMock.resetMocks();
|
||||
// process.env.DAILY_API_KEY = "MOCK_DAILY_API_KEY";
|
||||
});
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
import type { TestFunction } from "vitest";
|
||||
|
||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
import type { Fixtures } from "@calcom/web/test/fixtures/fixtures";
|
||||
import { createOrganization } from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
||||
|
||||
const _testWithAndWithoutOrg = (
|
||||
description: Parameters<typeof testWithAndWithoutOrg>[0],
|
||||
fn: Parameters<typeof testWithAndWithoutOrg>[1],
|
||||
timeout: Parameters<typeof testWithAndWithoutOrg>[2],
|
||||
mode: "only" | "skip" | "run" = "run"
|
||||
) => {
|
||||
const t = mode === "only" ? test.only : mode === "skip" ? test.skip : test;
|
||||
t(
|
||||
`${description} - With org`,
|
||||
async ({ emails, meta, task, onTestFailed, expect, skip }) => {
|
||||
const org = await createOrganization({
|
||||
name: "Test Org",
|
||||
slug: "testorg",
|
||||
});
|
||||
|
||||
await fn({
|
||||
meta,
|
||||
task,
|
||||
onTestFailed,
|
||||
expect,
|
||||
emails,
|
||||
skip,
|
||||
org: {
|
||||
organization: org,
|
||||
urlOrigin: `http://${org.slug}.cal.local:3000`,
|
||||
},
|
||||
});
|
||||
},
|
||||
timeout
|
||||
);
|
||||
|
||||
t(
|
||||
`${description}`,
|
||||
async ({ emails, meta, task, onTestFailed, expect, skip }) => {
|
||||
await fn({
|
||||
emails,
|
||||
meta,
|
||||
task,
|
||||
onTestFailed,
|
||||
expect,
|
||||
skip,
|
||||
org: null,
|
||||
});
|
||||
},
|
||||
timeout
|
||||
);
|
||||
};
|
||||
|
||||
export const testWithAndWithoutOrg = (
|
||||
description: string,
|
||||
fn: TestFunction<
|
||||
Fixtures & {
|
||||
org: {
|
||||
organization: { id: number | null };
|
||||
urlOrigin?: string;
|
||||
} | null;
|
||||
}
|
||||
>,
|
||||
timeout?: number
|
||||
) => {
|
||||
_testWithAndWithoutOrg(description, fn, timeout, "run");
|
||||
};
|
||||
|
||||
testWithAndWithoutOrg.only = ((description, fn) => {
|
||||
_testWithAndWithoutOrg(description, fn, "only");
|
||||
}) as typeof _testWithAndWithoutOrg;
|
||||
|
||||
testWithAndWithoutOrg.skip = ((description, fn) => {
|
||||
_testWithAndWithoutOrg(description, fn, "skip");
|
||||
}) as typeof _testWithAndWithoutOrg;
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
import { describe } from "vitest";
|
||||
|
||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
import { setupAndTeardown } from "./lib/setupAndTeardown";
|
||||
import { setupAndTeardown } from "@calcom/web/test/utils/bookingScenario/setupAndTeardown";
|
||||
|
||||
describe("handleNewBooking", () => {
|
||||
setupAndTeardown();
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
mockCalendarToHaveNoBusySlots,
|
||||
getDate,
|
||||
} from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
||||
import { createMockNextJsRequest } from "@calcom/web/test/utils/bookingScenario/createMockNextJsRequest";
|
||||
import {
|
||||
expectWorkflowToBeTriggered,
|
||||
expectSuccessfulBookingCreationEmails,
|
||||
@@ -23,10 +24,8 @@ import {
|
||||
expectBookingCreatedWebhookToHaveBeenFired,
|
||||
expectSuccessfulCalendarEventCreationInCalendar,
|
||||
} from "@calcom/web/test/utils/bookingScenario/expects";
|
||||
|
||||
import { createMockNextJsRequest } from "./lib/createMockNextJsRequest";
|
||||
import { getMockRequestDataForBooking } from "./lib/getMockRequestDataForBooking";
|
||||
import { setupAndTeardown } from "./lib/setupAndTeardown";
|
||||
import { getMockRequestDataForBooking } from "@calcom/web/test/utils/bookingScenario/getMockRequestDataForBooking";
|
||||
import { setupAndTeardown } from "@calcom/web/test/utils/bookingScenario/setupAndTeardown";
|
||||
|
||||
const DAY_IN_MS = 1000 * 60 * 60 * 24;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
getMockFailingAppStatus,
|
||||
getMockPassingAppStatus,
|
||||
} from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
||||
import { createMockNextJsRequest } from "@calcom/web/test/utils/bookingScenario/createMockNextJsRequest";
|
||||
import {
|
||||
expectWorkflowToBeTriggered,
|
||||
expectBookingToBeInDatabase,
|
||||
@@ -37,10 +38,8 @@ import {
|
||||
expectSuccessfulCalendarEventDeletionInCalendar,
|
||||
expectSuccessfulVideoMeetingDeletionInCalendar,
|
||||
} from "@calcom/web/test/utils/bookingScenario/expects";
|
||||
|
||||
import { createMockNextJsRequest } from "./lib/createMockNextJsRequest";
|
||||
import { getMockRequestDataForBooking } from "./lib/getMockRequestDataForBooking";
|
||||
import { setupAndTeardown } from "./lib/setupAndTeardown";
|
||||
import { getMockRequestDataForBooking } from "@calcom/web/test/utils/bookingScenario/getMockRequestDataForBooking";
|
||||
import { setupAndTeardown } from "@calcom/web/test/utils/bookingScenario/setupAndTeardown";
|
||||
|
||||
// Local test runs sometime gets too slow
|
||||
const timeout = process.env.CI ? 5000 : 20000;
|
||||
|
||||
+3
-4
@@ -22,6 +22,7 @@ import {
|
||||
BookingLocations,
|
||||
getZoomAppCredential,
|
||||
} from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
||||
import { createMockNextJsRequest } from "@calcom/web/test/utils/bookingScenario/createMockNextJsRequest";
|
||||
import {
|
||||
expectWorkflowToBeTriggered,
|
||||
expectSuccessfulBookingCreationEmails,
|
||||
@@ -30,10 +31,8 @@ import {
|
||||
expectSuccessfulCalendarEventCreationInCalendar,
|
||||
expectSuccessfulVideoMeetingCreation,
|
||||
} from "@calcom/web/test/utils/bookingScenario/expects";
|
||||
|
||||
import { createMockNextJsRequest } from "../lib/createMockNextJsRequest";
|
||||
import { getMockRequestDataForBooking } from "../lib/getMockRequestDataForBooking";
|
||||
import { setupAndTeardown } from "../lib/setupAndTeardown";
|
||||
import { getMockRequestDataForBooking } from "@calcom/web/test/utils/bookingScenario/getMockRequestDataForBooking";
|
||||
import { setupAndTeardown } from "@calcom/web/test/utils/bookingScenario/setupAndTeardown";
|
||||
|
||||
export type CustomNextApiRequest = NextApiRequest & Request;
|
||||
|
||||
|
||||
@@ -17,8 +17,11 @@ export const getBrand = async (orgId: number | null) => {
|
||||
metadata: true,
|
||||
},
|
||||
});
|
||||
const metadata = teamMetadataSchema.parse(org?.metadata);
|
||||
const slug = (org?.slug || metadata?.requestedSlug) as string;
|
||||
if (!org) {
|
||||
return null;
|
||||
}
|
||||
const metadata = teamMetadataSchema.parse(org.metadata);
|
||||
const slug = (org.slug || metadata?.requestedSlug) as string;
|
||||
const fullDomain = getOrgFullOrigin(slug);
|
||||
const domainSuffix = subdomainSuffix();
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ import { cancelScheduledJobs } from "@calcom/features/webhooks/lib/scheduleTrigg
|
||||
import sendPayload from "@calcom/features/webhooks/lib/sendPayload";
|
||||
import { isPrismaObjOrUndefined } from "@calcom/lib";
|
||||
import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { getTranslation } from "@calcom/lib/server";
|
||||
import { getBookerUrl } from "@calcom/lib/server/getBookerUrl";
|
||||
import { getUsersCredentials } from "@calcom/lib/server/getUsersCredentials";
|
||||
@@ -36,11 +38,11 @@ type RequestRescheduleOptions = {
|
||||
};
|
||||
input: TRequestRescheduleInputSchema;
|
||||
};
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["requestRescheduleHandler"] });
|
||||
export const requestRescheduleHandler = async ({ ctx, input }: RequestRescheduleOptions) => {
|
||||
const { user } = ctx;
|
||||
const { bookingId, rescheduleReason: cancellationReason } = input;
|
||||
|
||||
log.debug("Started", safeStringify({ bookingId, cancellationReason, user }));
|
||||
const bookingToReschedule = await prisma.booking.findFirstOrThrow({
|
||||
select: {
|
||||
id: true,
|
||||
@@ -98,6 +100,12 @@ export const requestRescheduleHandler = async ({ ctx, input }: RequestReschedule
|
||||
if (userTeamIds.indexOf(bookingToReschedule?.eventType?.teamId) === -1) {
|
||||
throw new TRPCError({ code: "FORBIDDEN", message: "User isn't a member on the team" });
|
||||
}
|
||||
log.debug(
|
||||
"Request reschedule for team booking",
|
||||
safeStringify({
|
||||
teamId: bookingToReschedule.eventType?.teamId,
|
||||
})
|
||||
);
|
||||
}
|
||||
if (!bookingBelongsToTeam && bookingToReschedule.userId !== user.id) {
|
||||
throw new TRPCError({ code: "FORBIDDEN", message: "User isn't owner of the current booking" });
|
||||
@@ -220,6 +228,7 @@ export const requestRescheduleHandler = async ({ ctx, input }: RequestReschedule
|
||||
})
|
||||
);
|
||||
|
||||
log.debug("builder.calendarEvent", safeStringify(builder.calendarEvent));
|
||||
// Send emails
|
||||
await sendRequestRescheduleEmail(builder.calendarEvent, {
|
||||
rescheduleLink: builder.rescheduleLink,
|
||||
|
||||
Reference in new issue
Block a user