fix(eventtypes): persist requiresCancellationReason selection (#29282)

Co-authored-by: Bandhan Majumder <[email protected]>
This commit is contained in:
MAHESH KUMAR JENAandBandhan Majumder authored and GitHub committed 2026-06-03 09:51:54 +00:00
1 parent ff184db553
commit d1ad4ea8b2
5 files changed
+34 -1

No files matched your search

@@ -1,5 +1,6 @@
import { prisma } from "@calcom/prisma";
import type { PrismaClient } from "@calcom/prisma";
import { CancellationReasonRequirement } from "@calcom/prisma/enums";
import i18nMock from "@calcom/testing/lib/__mocks__/libServerI18n";
// import { mockNoTranslations } from "@calcom/testing/lib/bookingScenario/bookingScenario";
@@ -46,7 +47,14 @@ describe("getRawEventType", () => {
return user;
};
const createTestEventType = async (userId: number, overrides?: { slug?: string; title?: string }) => {
const createTestEventType = async (
userId: number,
overrides?: {
slug?: string;
title?: string;
requiresCancellationReason?: CancellationReasonRequirement | null;
}
) => {
const timestamp = Date.now() + Math.random();
const eventType = await prisma.eventType.create({
data: {
@@ -54,6 +62,7 @@ describe("getRawEventType", () => {
slug: overrides?.slug ?? `test-event-${timestamp}`,
length: 30,
userId,
requiresCancellationReason: overrides?.requiresCancellationReason,
users: {
connect: [{ id: userId }],
},
@@ -104,6 +113,25 @@ describe("getRawEventType", () => {
expect(result?.userId).toBe(user.id);
});
test("should fetch requiresCancellationReason when it is configured", async () => {
const user = await createTestUser();
const eventType = await createTestEventType(user.id, {
requiresCancellationReason: CancellationReasonRequirement.MANDATORY_ATTENDEE_ONLY,
});
const result = await getRawEventType({
userId: user.id,
eventTypeId: eventType.id,
isUserOrganizationAdmin: false,
currentOrganizationId: null,
prisma: prisma as unknown as PrismaClient,
});
expect(result?.requiresCancellationReason).toBe(
CancellationReasonRequirement.MANDATORY_ATTENDEE_ONLY
);
});
test.skip("should return null when user doesn't have access to event type", async () => {
// note(Lauris): test skipped because somehow when creating event type eventType.users includes otherUser
const owner = await prisma.user.create({
@@ -185,6 +185,7 @@ export type FormValues = {
calVideoSettings?: CalVideoSettings;
maxActiveBookingPerBookerOfferReschedule: boolean;
enablePerHostLocations: boolean;
requiresCancellationReason?: CancellationReasonRequirement | null;
};
export type LocationFormValues = Pick<FormValues, "id" | "locations" | "bookingFields" | "seatsPerTimeSlot">;
@@ -599,6 +599,7 @@ export class EventTypeRepository implements IEventTypesRepository {
disableGuests: true,
disableCancelling: true,
disableRescheduling: true,
requiresCancellationReason: true,
minimumRescheduleNotice: true,
allowReschedulingCancelledBookings: true,
minimumBookingNotice: true,
@@ -878,6 +879,7 @@ export class EventTypeRepository implements IEventTypesRepository {
disableGuests: true,
disableCancelling: true,
disableRescheduling: true,
requiresCancellationReason: true,
minimumRescheduleNotice: true,
allowReschedulingCancelledBookings: true,
minimumBookingNotice: true,
@@ -134,6 +134,7 @@ export const useEventTypeForm = ({
maxActiveBookingPerBookerOfferReschedule: eventType.maxActiveBookingPerBookerOfferReschedule,
showOptimizedSlots: eventType.showOptimizedSlots ?? false,
enablePerHostLocations: eventType.enablePerHostLocations ?? false,
requiresCancellationReason: eventType.requiresCancellationReason || null,
};
}, [eventType, periodDates]);