Scheduling infrastructure for absolutely everyone.
test: In Team Event type when location is Organizer Default App and U… (#12939)
Udit Takkar13a765e50a0b
diff --git a/apps/web/test/utils/bookingScenario/bookingScenario.ts b/apps/web/test/utils/bookingScenario/bookingScenario.tsindex 40e3d176629..02f863a91e3 100644--- a/apps/web/test/utils/bookingScenario/bookingScenario.ts+++ b/apps/web/test/utils/bookingScenario/bookingScenario.ts@@ -19,6 +19,7 @@ import { safeStringify } from "@calcom/lib/safeStringify";import type { WorkflowActions, WorkflowTemplates, WorkflowTriggerEvents } from "@calcom/prisma/client";import type { SchedulingType } from "@calcom/prisma/enums";import type { BookingStatus } from "@calcom/prisma/enums";+import type { userMetadataType } from "@calcom/prisma/zod-utils";import type { AppMeta } from "@calcom/types/App";import type { NewCalendarEventType } from "@calcom/types/Calendar";import type { EventBusyDate, IntervalLimit } from "@calcom/types/Calendar";@@ -887,6 +888,7 @@ export function getOrganizer({weekStart = "Sunday",teams,organizationId,+ metadata,}: {name: string;email: string;@@ -899,6 +901,7 @@ export function getOrganizer({destinationCalendar?: Prisma.DestinationCalendarCreateInput;weekStart?: WeekDays;teams?: InputUser["teams"];+ metadata?: userMetadataType;}) {return {...TestData.users.example,@@ -913,6 +916,7 @@ export function getOrganizer({weekStart,teams,organizationId,+ metadata,};}diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.tsindex 055460cd07e..b84bd918387 100644--- a/packages/features/bookings/lib/handleNewBooking.ts+++ b/packages/features/bookings/lib/handleNewBooking.ts@@ -1325,7 +1325,7 @@ async function handler(organizerOrFirstDynamicGroupMemberDefaultLocationUrl =organizerMetadata?.defaultConferencingApp?.appLink;} else {- locationBodyString = "";+ locationBodyString = "integrations:daily";}}diff --git a/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts b/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.tsindex c556b04bbed..a7a444df586 100644--- a/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts+++ b/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts@@ -3,7 +3,10 @@ import type { NextApiRequest, NextApiResponse } from "next";import { describe, expect } from "vitest";import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";++import { OrganizerDefaultConferencingAppType } from "@calcom/app-store/locations";import { CAL_URL, WEBAPP_URL } from "@calcom/lib/constants";+import { ErrorCode } from "@calcom/lib/errorCodes";import { SchedulingType } from "@calcom/prisma/enums";import { BookingStatus } from "@calcom/prisma/enums";@@ -1087,6 +1090,212 @@ describe("handleNewBooking", () => {timeout);+ test(+ `When event type location is Organizer Default App and user metadata is empty, default to Cal Video`,+ async ({ emails }) => {+ const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;+ const booker = getBooker({+ email: "[email protected]",+ name: "Booker",+ });++ const otherTeamMembers = [+ {+ name: "Other Team Member 1",+ username: "other-team-member-1",+ timeZone: Timezones["+5:30"],+ defaultScheduleId: 1001,+ email: "[email protected]",+ id: 102,+ schedules: [+ {+ ...TestData.schedules.IstWorkHours,+ // Specify an ID directly here because we want to be able to use that ID in defaultScheduleId above.+ id: 1001,+ },+ ],+ credentials: [getGoogleCalendarCredential()],+ selectedCalendars: [TestData.selectedCalendars.google],+ destinationCalendar: {+ integration: TestData.apps["google-calendar"].type,+ externalId: "[email protected]",+ },+ },+ ];++ const organizer = getOrganizer({+ name: "Organizer",+ email: "[email protected]",+ id: 101,+ schedules: [TestData.schedules.IstWorkHours],+ credentials: [+ {+ id: 2,+ ...getGoogleCalendarCredential(),+ },+ {+ id: 1,+ ...getZoomAppCredential(),+ },+ ],+ metadata: {},+ selectedCalendars: [TestData.selectedCalendars.google],+ destinationCalendar: {+ integration: TestData.apps["google-calendar"].type,+ externalId: "[email protected]",+ },+ });++ const { eventTypes } = await createBookingScenario(+ getScenarioData({+ webhooks: [+ {+ userId: organizer.id,+ eventTriggers: ["BOOKING_CREATED"],+ subscriberUrl: "http://my-webhook.example.com",+ active: true,+ eventTypeId: 1,+ appId: null,+ },+ ],+ eventTypes: [+ {+ id: 1,+ slotInterval: 45,+ schedulingType: SchedulingType.COLLECTIVE,+ length: 45,+ users: [+ {+ id: 101,+ },+ {+ id: 102,+ },+ ],+ locations: [+ {+ type: "conferencing",+ },+ ],+ destinationCalendar: {+ integration: TestData.apps["google-calendar"].type,+ externalId: "[email protected]",+ },+ },+ ],+ organizer,+ usersApartFromOrganizer: otherTeamMembers,+ apps: [+ TestData.apps["google-calendar"],+ TestData.apps["daily-video"],+ TestData.apps["zoomvideo"],+ ],+ })+ );++ mockSuccessfulVideoMeetingCreation({+ metadataLookupKey: appStoreMetadata.dailyvideo.dirName,+ videoMeetingData: {+ id: "MOCK_ID",+ password: "MOCK_PASS",+ url: `http://mock-dailyvideo.example.com/meeting-1`,+ },+ });++ const calendarMock = mockCalendarToHaveNoBusySlots("googlecalendar", {+ create: {+ id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",+ iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",+ },+ });++ const mockBookingData = getMockRequestDataForBooking({+ data: {+ start: `${getDate({ dateIncrement: 1 }).dateString}T05:00:00.000Z`,+ end: `${getDate({ dateIncrement: 1 }).dateString}T05:30:00.000Z`,+ eventTypeId: 1,+ responses: {+ email: booker.email,+ name: booker.name,+ location: { optionValue: "", value: OrganizerDefaultConferencingAppType },+ },+ },+ });++ const { req } = createMockNextJsRequest({+ method: "POST",+ body: mockBookingData,+ });++ const createdBooking = await handleNewBooking(req);++ await expectBookingToBeInDatabase({+ description: "",+ location: BookingLocations.CalVideo,+ responses: expect.objectContaining({+ email: booker.email,+ name: booker.name,+ }),+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion+ uid: createdBooking.uid!,+ eventTypeId: mockBookingData.eventTypeId,+ status: BookingStatus.ACCEPTED,+ references: [+ {+ type: appStoreMetadata.dailyvideo.type,+ uid: "MOCK_ID",+ meetingId: "MOCK_ID",+ meetingPassword: "MOCK_PASS",+ meetingUrl: "http://mock-dailyvideo.example.com/meeting-1",+ },+ {+ type: TestData.apps["google-calendar"].type,+ uid: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",+ meetingId: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",+ meetingPassword: "MOCK_PASSWORD",+ meetingUrl: "https://UNUSED_URL",+ },+ ],+ });++ // expectWorkflowToBeTriggered();++ expectSuccessfulCalendarEventCreationInCalendar(calendarMock, {+ destinationCalendars: [+ {+ integration: TestData.apps["google-calendar"].type,+ externalId: "[email protected]",+ },+ {+ integration: TestData.apps["google-calendar"].type,+ externalId: "[email protected]",+ },+ ],+ videoCallUrl: "http://mock-dailyvideo.example.com/meeting-1",+ });++ expectSuccessfulBookingCreationEmails({+ booking: {+ uid: createdBooking.uid!,+ },+ booker,+ organizer,+ otherTeamMembers,+ emails,+ iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",+ });++ expectBookingCreatedWebhookToHaveBeenFired({+ booker,+ organizer,+ location: OrganizerDefaultConferencingAppType,+ subscriberUrl: "http://my-webhook.example.com",+ videoCallUrl: `${WEBAPP_URL}/video/${createdBooking.uid}`,+ });+ },+ timeout+ );+describe("Team(T1) not part of any org but the organizer is part of an organization(O1)", () => {test(`succesfully creates a booking when all the hosts are free as per their schedulesdiff --git a/packages/prisma/zod-utils.ts b/packages/prisma/zod-utils.tsindex 48647c8bbfa..d81f43ccb20 100644--- a/packages/prisma/zod-utils.ts+++ b/packages/prisma/zod-utils.ts@@ -324,6 +324,8 @@ export const userMetadata = z}).nullable();+export type userMetadataType = z.infer<typeof userMetadata>;+export const teamMetadataSchema = z.object({requestedSlug: z.string(),