|
1 | 1 | import { prisma } from "@calcom/prisma"; |
2 | 2 | import type { PrismaClient } from "@calcom/prisma"; |
| 3 | +import { CancellationReasonRequirement } from "@calcom/prisma/enums"; |
3 | 4 | import i18nMock from "@calcom/testing/lib/__mocks__/libServerI18n"; |
4 | 5 |
|
5 | 6 | // import { mockNoTranslations } from "@calcom/testing/lib/bookingScenario/bookingScenario"; |
@@ -46,14 +47,22 @@ describe("getRawEventType", () => { |
46 | 47 | return user; |
47 | 48 | }; |
48 | 49 |
|
49 | | - const createTestEventType = async (userId: number, overrides?: { slug?: string; title?: string }) => { |
| 50 | + const createTestEventType = async ( |
| 51 | + userId: number, |
| 52 | + overrides?: { |
| 53 | + slug?: string; |
| 54 | + title?: string; |
| 55 | + requiresCancellationReason?: CancellationReasonRequirement | null; |
| 56 | + } |
| 57 | + ) => { |
50 | 58 | const timestamp = Date.now() + Math.random(); |
51 | 59 | const eventType = await prisma.eventType.create({ |
52 | 60 | data: { |
53 | 61 | title: overrides?.title ?? "Test Event Type", |
54 | 62 | slug: overrides?.slug ?? `test-event-${timestamp}`, |
55 | 63 | length: 30, |
56 | 64 | userId, |
| 65 | + requiresCancellationReason: overrides?.requiresCancellationReason, |
57 | 66 | users: { |
58 | 67 | connect: [{ id: userId }], |
59 | 68 | }, |
@@ -104,6 +113,25 @@ describe("getRawEventType", () => { |
104 | 113 | expect(result?.userId).toBe(user.id); |
105 | 114 | }); |
106 | 115 |
|
| 116 | + test("should fetch requiresCancellationReason when it is configured", async () => { |
| 117 | + const user = await createTestUser(); |
| 118 | + const eventType = await createTestEventType(user.id, { |
| 119 | + requiresCancellationReason: CancellationReasonRequirement.MANDATORY_ATTENDEE_ONLY, |
| 120 | + }); |
| 121 | + |
| 122 | + const result = await getRawEventType({ |
| 123 | + userId: user.id, |
| 124 | + eventTypeId: eventType.id, |
| 125 | + isUserOrganizationAdmin: false, |
| 126 | + currentOrganizationId: null, |
| 127 | + prisma: prisma as unknown as PrismaClient, |
| 128 | + }); |
| 129 | + |
| 130 | + expect(result?.requiresCancellationReason).toBe( |
| 131 | + CancellationReasonRequirement.MANDATORY_ATTENDEE_ONLY |
| 132 | + ); |
| 133 | + }); |
| 134 | + |
107 | 135 | test.skip("should return null when user doesn't have access to event type", async () => { |
108 | 136 | // note(Lauris): test skipped because somehow when creating event type eventType.users includes otherUser |
109 | 137 | const owner = await prisma.user.create({ |
|
0 commit comments