fix: Filter invalid keys and handle disabled states during booking limit transformation, with added tests (#28035)

Co-authored-by: Sahitya Chandra <sahityajb@gmail.com>
This commit is contained in:
Muhammad Usman
2026-03-18 19:31:42 -03:00
committed by GitHub
co-authored by Sahitya Chandra
parent 8caa062ae1
commit 4b247640a8
2 changed files with 31 additions and 3 deletions
@@ -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", () => {
@@ -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;