-
Notifications
You must be signed in to change notification settings - Fork 12k
test: add comprehensive unit tests for handleInstantMeeting #22820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
anikdhabal
merged 20 commits into
main
from
devin/fix-username-constraint-removemember-1753884495
Jul 31, 2025
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c9851e2
fix: resolve username constraint violation in removeMember
devin-ai-integration[bot] 6121a2a
test: update removeMember test to verify constraint violation scenario
devin-ai-integration[bot] 8760e3c
test: add comprehensive unit tests for handleInstantMeeting
devin-ai-integration[bot] c00f61b
update
anikdhabal 18e7694
Update handleInstantMeeting.test.ts
anikdhabal 881dac5
fix: redir parameter for connect atoms (#22815)
Ryukemeister 1a5eca3
feat: Support an array response for a field when used as `Value of Fi…
hariombalhara e7e40bf
fix: flaky e2e (#22819)
anikdhabal 187b8df
fix: merge working hours when adjacent (#21912)
emrysal c828a02
feat: Improving Booking Visibility at Month-End (#22770)
CarinaWolli 171c707
chore: Refactor logs (#22824)
joeauyeung 06dec5f
fix: Errors in org onboarding in some edge cases (#22711)
hariombalhara a35ea94
feat: enable PBAC checking on organization settings page (#22467)
sean-brydon 6bf394f
refactor: convert checkBookingLimits to class service with dependency…
devin-ai-integration[bot] 5dce6b4
fix: Return empty available days if error querying calendar (#22828)
joeauyeung 1ca64f4
chore: release v5.5.9
emrysal 72094fc
include mobile layout (#22836)
CarinaWolli 533d51a
test: fix handleInstantMeeting test with setupAndTeardown and proper …
devin-ai-integration[bot] 0bdbaea
Merge branch 'main' into devin/fix-username-constraint-removemember-1…
anikdhabal aed4bf8
fix typo
anikdhabal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
203 changes: 203 additions & 0 deletions
203
packages/features/instant-meeting/handleInstantMeeting.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| import prismock from "../../../tests/libs/__mocks__/prisma"; | ||
|
|
||
| import { | ||
| createBookingScenario, | ||
| getScenarioData, | ||
| getGoogleCalendarCredential, | ||
| TestData, | ||
| getOrganizer, | ||
| mockSuccessfulVideoMeetingCreation, | ||
| mockCalendarToHaveNoBusySlots, | ||
| mockNoTranslations, | ||
| } from "@calcom/web/test/utils/bookingScenario/bookingScenario"; | ||
|
|
||
| import type { NextApiRequest } from "next"; | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
|
|
||
| import { BookingStatus } from "@calcom/prisma/enums"; | ||
|
|
||
| vi.mock("@calcom/features/notifications/sendNotification", () => ({ | ||
| sendNotification: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@calcom/lib/videoClient", () => ({ | ||
| createInstantMeetingWithCalVideo: vi.fn().mockResolvedValue({ | ||
| type: "daily_video", | ||
| id: "MOCK_INSTANT_MEETING_ID", | ||
| password: "MOCK_INSTANT_PASS", | ||
| url: "http://mock-dailyvideo.example.com/instant-meeting-url", | ||
| }), | ||
| })); | ||
|
|
||
| describe("handleInstantMeeting", () => { | ||
| beforeEach(() => { | ||
| mockNoTranslations(); | ||
| }); | ||
| describe("team event instant meeting", () => { | ||
| it("should successfully create instant meeting for team event", async () => { | ||
| const handler = (await import("./handleInstantMeeting")).default; | ||
| const organizer = getOrganizer({ | ||
| name: "Organizer", | ||
| email: "organizer@example.com", | ||
| id: 101, | ||
| schedules: [TestData.schedules.IstWorkHours], | ||
| credentials: [getGoogleCalendarCredential()], | ||
| selectedCalendars: [TestData.selectedCalendars.google], | ||
| }); | ||
|
|
||
| const { dateString: plus1DateString } = getDate({ dateIncrement: 1 }); | ||
|
|
||
| await createBookingScenario( | ||
| getScenarioData({ | ||
| eventTypes: [ | ||
| { | ||
| id: 1, | ||
| slotInterval: 45, | ||
| length: 45, | ||
| users: [ | ||
| { | ||
| id: 101, | ||
| }, | ||
| ], | ||
| team: { | ||
| id: 1, | ||
| }, | ||
| instantMeetingExpiryTimeOffsetInSeconds: 90, | ||
| }, | ||
| ], | ||
| organizer, | ||
| apps: [TestData.apps["daily-video"], TestData.apps["google-calendar"]], | ||
| }) | ||
| ); | ||
|
|
||
| mockSuccessfulVideoMeetingCreation({ | ||
| metadataLookupKey: "dailyvideo", | ||
| videoMeetingData: { | ||
| id: "MOCK_ID", | ||
| password: "MOCK_PASS", | ||
| url: `http://mock-dailyvideo.example.com/meeting-1`, | ||
| }, | ||
| }); | ||
| mockCalendarToHaveNoBusySlots("googlecalendar", { | ||
| create: { | ||
| uid: "MOCKED_GOOGLE_CALENDAR_EVENT_ID", | ||
| }, | ||
| }); | ||
|
|
||
| const mockReqBody = { | ||
| eventTypeId: 1, | ||
| name: "Test User", | ||
| email: "test@example.com", | ||
| timeZone: "UTC", | ||
| language: "en", | ||
| start: `${plus1DateString}T04:00:00.000Z`, | ||
| end: `${plus1DateString}T04:45:00.000Z`, | ||
| responses: { | ||
| name: "Test User", | ||
| email: "test@example.com", | ||
| }, | ||
| metadata: {}, | ||
| }; | ||
|
|
||
| const mockRequest = { | ||
| body: mockReqBody, | ||
| method: "POST", | ||
| headers: {}, | ||
| query: {}, | ||
| cookies: {}, | ||
| url: "/api/instant-meeting", | ||
| } as NextApiRequest; | ||
|
|
||
| const result = await handler(mockRequest); | ||
|
|
||
| expect(result.message).toBe("Success"); | ||
| expect(result.bookingId).toBeDefined(); | ||
| expect(result.bookingUid).toBeDefined(); | ||
| expect(result.meetingTokenId).toBeDefined(); | ||
| expect(result.expires).toBeInstanceOf(Date); | ||
|
|
||
| const booking = await prismock.booking.findUnique({ | ||
| where: { id: result.bookingId }, | ||
| include: { attendees: true, references: true }, | ||
| }); | ||
|
|
||
| expect(booking).toBeDefined(); | ||
| expect(booking?.status).toBe(BookingStatus.AWAITING_HOST); | ||
| expect(booking?.attendees).toHaveLength(1); | ||
| expect(booking?.attendees[0].email).toBe("test@example.com"); | ||
| expect(booking?.references).toHaveLength(1); | ||
| expect(booking?.references[0].type).toBe("daily_video"); | ||
| }); | ||
|
|
||
| it("should throw error for non-team event types", async () => { | ||
| const handler = (await import("./handleInstantMeeting")).default; | ||
| const organizer = getOrganizer({ | ||
| name: "Organizer", | ||
| email: "organizer@example.com", | ||
| id: 101, | ||
| schedules: [TestData.schedules.IstWorkHours], | ||
| credentials: [getGoogleCalendarCredential()], | ||
| selectedCalendars: [TestData.selectedCalendars.google], | ||
| }); | ||
|
|
||
| const { dateString: plus1DateString } = getDate({ dateIncrement: 1 }); | ||
|
|
||
| await createBookingScenario( | ||
| getScenarioData({ | ||
| eventTypes: [ | ||
| { | ||
| id: 1, | ||
| slotInterval: 45, | ||
| length: 45, | ||
| users: [ | ||
| { | ||
| id: 101, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| organizer, | ||
| apps: [TestData.apps["daily-video"], TestData.apps["google-calendar"]], | ||
| }) | ||
| ); | ||
|
|
||
| const mockReqBody = { | ||
| eventTypeId: 1, | ||
| name: "Test User", | ||
| email: "test@example.com", | ||
| timeZone: "UTC", | ||
| language: "en", | ||
| start: `${plus1DateString}T04:00:00.000Z`, | ||
| end: `${plus1DateString}T04:45:00.000Z`, | ||
| responses: { | ||
| name: "Test User", | ||
| email: "test@example.com", | ||
| }, | ||
| metadata: {}, | ||
| }; | ||
|
|
||
| const mockRequest = { | ||
| body: mockReqBody, | ||
| method: "POST", | ||
| headers: {}, | ||
| query: {}, | ||
| cookies: {}, | ||
| url: "/api/instant-meeting", | ||
| } as NextApiRequest; | ||
|
|
||
| await expect(handler(mockRequest)).rejects.toThrow( | ||
| "Only Team Event Types are supported for Instant Meeting" | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| function getDate(param: { dateIncrement?: number } = {}) { | ||
| const { dateIncrement = 0 } = param; | ||
| const date = new Date(); | ||
| date.setDate(date.getDate() + dateIncrement); | ||
| return { | ||
| date, | ||
| dateString: date.toISOString().split("T")[0], | ||
| }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.