From 4b247640a87e78bdfd438fc6a76ad4dceaa93042 Mon Sep 17 00:00:00 2001 From: Muhammad Usman <146759960+muhammadusman586@users.noreply.github.com> Date: Thu, 19 Mar 2026 03:31:42 +0500 Subject: [PATCH] fix: Filter invalid keys and handle disabled states during booking limit transformation, with added tests (#28035) Co-authored-by: Sahitya Chandra --- .../api-to-internal/api-to-internal.spec.ts | 27 ++++++++++++++++++- .../api-to-internal/interval-limits.ts | 7 +++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/api-to-internal/api-to-internal.spec.ts b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/api-to-internal/api-to-internal.spec.ts index 7383079a4b..2235e1281e 100644 --- a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/api-to-internal/api-to-internal.spec.ts +++ b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/api-to-internal/api-to-internal.spec.ts @@ -22,7 +22,6 @@ import type { SeatOptionsDisabledSchema, SeatOptionsTransformedSchema, } from "@calcom/platform-types"; - import { type CustomField, type SystemField, @@ -689,6 +688,32 @@ describe("transformIntervalLimitsApiToInternal", () => { expect(result).toEqual(expectedOutput); }); + + it("should handle bookingLimitsCount with disabled: false and valid counts", () => { + const input: BookingLimitsCount_2024_06_14 = { + day: 5, + disabled: false, + }; + + const expectedOutput = { + PER_DAY: 5, + }; + const result = transformIntervalLimitsApiToInternal(input); + + expect(result).toEqual(expectedOutput); + expect(result).not.toHaveProperty("undefined"); + }); + + it("should handle bookingLimitsCount with disabled: true", () => { + const input: BookingLimitsCount_2024_06_14 = { + disabled: true, + }; + + const expectedOutput = {}; + const result = transformIntervalLimitsApiToInternal(input); + + expect(result).toEqual(expectedOutput); + }); }); describe("transformFutureBookingLimitsApiToInternal", () => { diff --git a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/api-to-internal/interval-limits.ts b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/api-to-internal/interval-limits.ts index e7686b30ff..d3c11b96f9 100644 --- a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/api-to-internal/interval-limits.ts +++ b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/api-to-internal/interval-limits.ts @@ -1,7 +1,7 @@ import { BookingLimitsEnum_2024_06_14 } from "@calcom/platform-enums"; import { - type CreateEventTypeInput_2024_06_14, type BookingLimitsKeyOutputType_2024_06_14, + type CreateEventTypeInput_2024_06_14, type TransformBookingLimitsSchema_2024_06_14, } from "@calcom/platform-types"; @@ -13,7 +13,10 @@ export function transformIntervalLimitsApiToInternal( return res; } inputBookingLimits && - Object.entries(inputBookingLimits).map(([key, value]) => { + Object.entries(inputBookingLimits).forEach(([key, value]) => { + if (!(key in BookingLimitsEnum_2024_06_14)) { + return; + } const outputKey: BookingLimitsKeyOutputType_2024_06_14 = BookingLimitsEnum_2024_06_14[ key as keyof typeof BookingLimitsEnum_2024_06_14 ] satisfies BookingLimitsKeyOutputType_2024_06_14;