From 92678dc042caf9fb1a3bb67bdc839bad428d34ed Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Wed, 29 Jan 2025 17:00:51 +0400 Subject: [PATCH] fix: eventtype null cant be booked error (#18975) * fix err msg and add more description * improvements * fix cause * add warn logs for when failing to specific limit checks * typefix * safestringify log * improve error * test fix and log min booking notice * adds out of bounds error code * test fix * fix --- apps/web/public/static/locales/en/common.json | 1 + .../test/booking-limits.test.ts | 6 +- .../validateBookingTimeIsNotOutOfBounds.ts | 16 ++--- packages/lib/errorCodes.ts | 1 + packages/lib/isOutOfBounds.tsx | 71 ++++++++++++++----- 5 files changed, 64 insertions(+), 31 deletions(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 83190cb49c..1fcdde96b1 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -83,6 +83,7 @@ "payment_not_created_error": "Payment could not be created", "couldnt_charge_card_error": "Could not charge card for Payment", "no_available_users_found_error": "No available users found. Could you try another time slot?", + "booking_time_out_of_bounds_error": "The event type cannot be booked at this time. Could you try another time slot?", "request_body_end_time_internal_error": "Internal Error. Request body does not contain end time", "create_calendar_event_error": "Unable to create Calendar event in Organizer's calendar", "update_calendar_event_error": "Unable to update Calendar event.", diff --git a/packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts b/packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts index 81044e461f..37342f057c 100644 --- a/packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts +++ b/packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts @@ -772,7 +772,9 @@ describe("handleNewBooking", () => { mockCalendarToHaveNoBusySlots("googlecalendar", {}); await createBookingScenario(scenarioData); - await expect(() => handleNewBooking(req)).rejects.toThrowError("book a meeting in the past"); + await expect(() => handleNewBooking(req)).rejects.toThrowError( + "Attempting to book a meeting in the past." + ); }, timeout ); @@ -865,7 +867,7 @@ describe("handleNewBooking", () => { }, }); - expect(() => handleNewBooking(req)).rejects.toThrowError("cannot be booked at this time"); + expect(() => handleNewBooking(req)).rejects.toThrowError("booking_time_out_of_bounds_error"); }, timeout ); diff --git a/packages/features/bookings/lib/handleNewBooking/validateBookingTimeIsNotOutOfBounds.ts b/packages/features/bookings/lib/handleNewBooking/validateBookingTimeIsNotOutOfBounds.ts index d17f39dd94..10b1777dd8 100644 --- a/packages/features/bookings/lib/handleNewBooking/validateBookingTimeIsNotOutOfBounds.ts +++ b/packages/features/bookings/lib/handleNewBooking/validateBookingTimeIsNotOutOfBounds.ts @@ -1,6 +1,7 @@ import type { Logger } from "tslog"; import { getUTCOffsetByTimezone } from "@calcom/lib/date-fns"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import { HttpError } from "@calcom/lib/http-error"; import isOutOfBounds, { BookingDateInPastError } from "@calcom/lib/isOutOfBounds"; import type { EventType } from "@calcom/prisma/client"; @@ -15,6 +16,7 @@ type ValidateBookingTimeEventType = Pick< | "minimumBookingNotice" | "eventName" | "id" + | "title" >; export const validateBookingTimeIsNotOutOfBounds = async ( @@ -41,22 +43,14 @@ export const validateBookingTimeIsNotOutOfBounds = async