From 390ee791346a2bdf2b9b54323271f80095df6127 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Wed, 7 May 2025 08:46:07 +0530 Subject: [PATCH] Reduce payload size (#21093) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Omar López --- .../features/bookings/lib/handleNewBooking.ts | 24 ++--- .../test/buildDryRunBooking.test.ts | 100 ++++++++++++++++++ 2 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 packages/features/bookings/lib/handleNewBooking/test/buildDryRunBooking.test.ts diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 92e860b2e1..feadb27ae7 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -164,8 +164,8 @@ type BookingDataSchemaGetter = | typeof import("@calcom/features/bookings/lib/getBookingDataSchemaForApi").default; type CreatedBooking = Booking & { appsStatus?: AppsStatus[]; paymentUid?: string; paymentId?: number }; - -const buildDryRunBooking = ({ +type ReturnTypeCreateBooking = Awaited>; +export const buildDryRunBooking = ({ eventTypeId, organizerUser, eventName, @@ -193,8 +193,11 @@ const buildDryRunBooking = ({ isManagedEventType: boolean; }) => { const sanitizedOrganizerUser = { - ...organizerUser, - credentials: undefined, + id: organizerUser.id, + name: organizerUser.name, + username: organizerUser.username, + email: organizerUser.email, + timeZone: organizerUser.timeZone, }; const booking = { id: -101, @@ -210,8 +213,6 @@ const buildDryRunBooking = ({ createdAt: new Date(), updatedAt: new Date(), attendees: [], - references: [], - payment: [], oneTimePassword: null, smsReminderNumber: null, metadata: {}, @@ -222,25 +223,18 @@ const buildDryRunBooking = ({ responses: null, location: null, paid: false, - destinationCalendar: null, cancellationReason: null, rejectionReason: null, dynamicEventSlugRef: null, dynamicGroupSlugRef: null, - rescheduledFrom: null, fromReschedule: null, recurringEventId: null, - seatsReferences: [], - workflowReminders: [], scheduledJobs: [], - rescheduledTo: null, rescheduledBy: null, destinationCalendarId: null, reassignReason: null, reassignById: null, rescheduled: false, - confirmed: false, - isRecurringEvent: false, isRecorded: false, iCalSequence: 0, rating: null, @@ -248,7 +242,9 @@ const buildDryRunBooking = ({ noShowHost: null, cancelledBy: null, creationSource: CreationSource.WEBAPP, - } as CreatedBooking; + references: [], + payment: [], + } satisfies ReturnTypeCreateBooking; /** * Troubleshooting data diff --git a/packages/features/bookings/lib/handleNewBooking/test/buildDryRunBooking.test.ts b/packages/features/bookings/lib/handleNewBooking/test/buildDryRunBooking.test.ts new file mode 100644 index 0000000000..bb9269e97f --- /dev/null +++ b/packages/features/bookings/lib/handleNewBooking/test/buildDryRunBooking.test.ts @@ -0,0 +1,100 @@ +import { describe, it, expect } from "vitest"; + +import { BookingStatus, CreationSource } from "@calcom/prisma/enums"; + +import { buildDryRunBooking } from "../../handleNewBooking"; + +describe("buildDryRunBooking", () => { + const baseOrganizerUser = { + id: 1, + name: "Test User", + username: "testuser", + email: "testuser@example.com", + timeZone: "America/New_York", + credentials: [ + { + abc: "xyz", + }, + ], + }; + + const baseInputs = { + eventTypeId: 10, + organizerUser: baseOrganizerUser, + eventName: "Test Event", + startTime: "2024-01-01T10:00:00.000Z", + endTime: "2024-01-01T11:00:00.000Z", + contactOwnerFromReq: "owner@example.com", + contactOwnerEmail: "owner@example.com", + allHostUsers: [{ id: 1 }, { id: 2 }], + isManagedEventType: false, + }; + + it("should build a dry run booking with all provided details and nothing more than that", () => { + const { booking, troubleshooterData } = buildDryRunBooking(baseInputs); + + const { user, ...bookingExceptUser } = booking; + expect(user).toEqual({ + id: baseOrganizerUser.id, + name: baseOrganizerUser.name, + username: baseOrganizerUser.username, + email: baseOrganizerUser.email, + timeZone: baseOrganizerUser.timeZone, + }); + + expect(bookingExceptUser).toEqual({ + id: -101, + uid: "DRY_RUN_UID", + iCalUID: "DRY_RUN_ICAL_UID", + status: BookingStatus.ACCEPTED, + eventTypeId: baseInputs.eventTypeId, + userId: baseOrganizerUser.id, + title: baseInputs.eventName, + startTime: new Date(baseInputs.startTime), + endTime: new Date(baseInputs.endTime), + createdAt: expect.any(Date), + updatedAt: expect.any(Date), + attendees: [], + oneTimePassword: null, + smsReminderNumber: null, + metadata: {}, + idempotencyKey: null, + userPrimaryEmail: null, + description: null, + customInputs: null, + responses: null, + location: null, + paid: false, + cancellationReason: null, + rejectionReason: null, + dynamicEventSlugRef: null, + dynamicGroupSlugRef: null, + fromReschedule: null, + recurringEventId: null, + scheduledJobs: [], + rescheduledBy: null, + destinationCalendarId: null, + reassignReason: null, + reassignById: null, + rescheduled: false, + isRecorded: false, + iCalSequence: 0, + rating: null, + ratingFeedback: null, + noShowHost: null, + cancelledBy: null, + creationSource: CreationSource.WEBAPP, + references: [], + payment: [], + }); + + expect(troubleshooterData).toEqual({ + organizerUserId: baseOrganizerUser.id, + eventTypeId: baseInputs.eventTypeId, + askedContactOwnerEmail: baseInputs.contactOwnerFromReq, + usedContactOwnerEmail: baseInputs.contactOwnerEmail, + allHostUsers: [1, 2], + isManagedEventType: baseInputs.isManagedEventType, + }); + }); +});