Skip to content

Commit 4b24764

Browse files
fix: Filter invalid keys and handle disabled states during booking limit transformation, with added tests (calcom#28035)
Co-authored-by: Sahitya Chandra <sahityajb@gmail.com>
1 parent 8caa062 commit 4b24764

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/api-to-internal/api-to-internal.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import type {
2222
SeatOptionsDisabledSchema,
2323
SeatOptionsTransformedSchema,
2424
} from "@calcom/platform-types";
25-
2625
import {
2726
type CustomField,
2827
type SystemField,
@@ -689,6 +688,32 @@ describe("transformIntervalLimitsApiToInternal", () => {
689688

690689
expect(result).toEqual(expectedOutput);
691690
});
691+
692+
it("should handle bookingLimitsCount with disabled: false and valid counts", () => {
693+
const input: BookingLimitsCount_2024_06_14 = {
694+
day: 5,
695+
disabled: false,
696+
};
697+
698+
const expectedOutput = {
699+
PER_DAY: 5,
700+
};
701+
const result = transformIntervalLimitsApiToInternal(input);
702+
703+
expect(result).toEqual(expectedOutput);
704+
expect(result).not.toHaveProperty("undefined");
705+
});
706+
707+
it("should handle bookingLimitsCount with disabled: true", () => {
708+
const input: BookingLimitsCount_2024_06_14 = {
709+
disabled: true,
710+
};
711+
712+
const expectedOutput = {};
713+
const result = transformIntervalLimitsApiToInternal(input);
714+
715+
expect(result).toEqual(expectedOutput);
716+
});
692717
});
693718

694719
describe("transformFutureBookingLimitsApiToInternal", () => {

apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/api-to-internal/interval-limits.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BookingLimitsEnum_2024_06_14 } from "@calcom/platform-enums";
22
import {
3-
type CreateEventTypeInput_2024_06_14,
43
type BookingLimitsKeyOutputType_2024_06_14,
4+
type CreateEventTypeInput_2024_06_14,
55
type TransformBookingLimitsSchema_2024_06_14,
66
} from "@calcom/platform-types";
77

@@ -13,7 +13,10 @@ export function transformIntervalLimitsApiToInternal(
1313
return res;
1414
}
1515
inputBookingLimits &&
16-
Object.entries(inputBookingLimits).map(([key, value]) => {
16+
Object.entries(inputBookingLimits).forEach(([key, value]) => {
17+
if (!(key in BookingLimitsEnum_2024_06_14)) {
18+
return;
19+
}
1720
const outputKey: BookingLimitsKeyOutputType_2024_06_14 = BookingLimitsEnum_2024_06_14[
1821
key as keyof typeof BookingLimitsEnum_2024_06_14
1922
] satisfies BookingLimitsKeyOutputType_2024_06_14;

0 commit comments

Comments
 (0)