-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
test: add comprehensive unit tests for handleInstantMeeting #22820
Conversation
- Update username to - format when removing users from organizations - Fix unique constraint violation on (username, organizationId) when organizationId is null - Add test case to verify username format change and successful removal - Fix skipped test by adding proper imports and removing describe.skip Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
WalkthroughA new test file, Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
- Create two users with same username (one with null orgId, one with orgId) - Verify removing org user updates username without unique constraint error - Test ensures username gets updated to - format Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (07/30/25)1 reviewer was added to this PR based on Keith Williams's automation. "Add ready-for-e2e label" took an action on this PR • (07/31/25)1 label was added to this PR based on Keith Williams's automation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/features/ee/teams/lib/removeMember.ts
(1 hunks)packages/trpc/server/routers/viewer/teams/removeMember.test.ts
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.ts
📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
**/*.ts
: For Prisma queries, only select data you need; never useinclude
, always useselect
Ensure thecredential.key
field is never returned from tRPC endpoints or APIs
Files:
packages/trpc/server/routers/viewer/teams/removeMember.test.ts
packages/features/ee/teams/lib/removeMember.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()
in hot paths like loops
Files:
packages/trpc/server/routers/viewer/teams/removeMember.test.ts
packages/features/ee/teams/lib/removeMember.ts
🔇 Additional comments (2)
packages/trpc/server/routers/viewer/teams/removeMember.test.ts (2)
3-10
: LGTM! Comprehensive test utilities imported.The imported test utilities are appropriate and necessary for creating the comprehensive test scenario that validates the username constraint fix.
173-283
: Excellent test coverage for the constraint violation fix!This test comprehensively validates the core issue described in the PR objectives. It creates the exact scenario that would cause the unique constraint violation (two users with identical usernames, one with null organizationId) and verifies:
- The removal operation completes without throwing an exception
- The removed user's username is correctly updated to include their ID
- The other user's data remains unchanged
The test structure follows best practices and provides strong confidence in the fix.
Pull request was converted to draft
- Revert previous removeMember changes - Add full test coverage for instant meeting functionality - Test team validation, booking creation, token generation - Test webhook triggers and browser notifications - Mock external dependencies for isolated unit tests - Translation issue to be addressed in future iteration Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
* encode redirect url to make sure it has all parameters * add changesets
…eld` (#22740) * Passing tests and fixed * self review addressed adn more tests
* fix: Adjacency issue when working hours connect over multiple days * Add tests to validate the new merging of day end logic * Update to correct annotation. Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Implement subsequent date ranges for date overrides also * The map needs to be updated on successful resolve. * test: add failing test for overlapping ranges with same end time Demonstrates bug where overlapping working hour ranges (6:00-10:00 and 8:00-10:00) lose the earlier portion (6:00-8:00), showing only 8:00 and 9:00 slots instead of all 4 slots (6:00, 7:00, 8:00, 9:00). Related to Carina's comment on PR #21912. Co-Authored-By: alex@cal.com <me@alexvanandel.com> * fix: properly merge overlapping ranges with same end time Fixes bug where overlapping working hour ranges with the same end time (e.g., 6:00-10:00 and 8:00-10:00) would lose the earlier portion of the first range. The merging logic now correctly preserves the earliest start time when ranges overlap and share the same end time. This ensures all expected time slots are available (6:00, 7:00, 8:00, 9:00) instead of losing the earlier slots (6:00, 7:00). Resolves the issue identified in Carina's comment on PR #21912. Co-Authored-By: alex@cal.com <me@alexvanandel.com> * perf: optimize overlapping range detection from O(n²) to O(n) Replaces Object.keys().find() with Map-based lookup for ranges with same end time. This optimization handles 2000+ date ranges efficiently, reducing complexity from 4M operations to linear time while maintaining the same merging behavior. Performance improvement for high-volume event types with many availability ranges. Co-Authored-By: alex@cal.com <me@alexvanandel.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* remove first weeks and add last * fix added last week * prefetch availability of next month * don't switch month * On hover show month * only show new UI in monthly view * show month tooldtip only when needed * show month on first day of month * remove isFirstDayOfNextMonth * fix prefetching next month * fix datePicker tests * preventMonthSwitching in monthly view * add tests * code clean up * code clean up * code clena up for ooo days * push first day of month * remove bg color for the month badge * fix text colour * remove not needed * use object param * revert: use object param * use object param * fix DatePicker tests --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Sean Brydon <sean@cal.com> Co-authored-by: Eunjae Lee <hey@eunjae.dev>
* Refactor logs * Add specific info to log
* Automatically enable migration of a team that conflicts with Orgs slug * Allow changing the orgs slug and name if user goes back and changes it * avoid crashing on some scenarios * Revert "Allow changing the orgs slug and name if user goes back and changes it" This reverts commit f8872b0. * fix: handle unpublished teams gracefully in org migration - Change 'No oldSlug for team' from error to warning for unpublished teams - Keep 'No slug for team' as error since org onboarding ensures teams have names - Add test for migrating unpublished teams without oldSlug - Add clarifying comments about when each condition can occur
… injection (#22768) * refactor: convert checkBookingLimits to class service with dependency injection - Create CheckBookingLimitsService class following AvailableSlotsService pattern - Add countBookingsByEventTypeAndDateRange method to BookingRepository - Move direct prisma calls from service to repository layer - Implement dependency injection with proper DI tokens and modules - Update all usage points to use the new service through DI - Maintain backward compatibility with error-throwing wrapper functions - Update tests to use the new service pattern - Resolve TODO comment in AvailableSlotsService for DI integration Co-Authored-By: morgan@cal.com <morgan@cal.com> * chore: DI CheckBookingLimitsService in v2 slots service * chore: bump libraries * chore: create getCheckBookingLimitsService * refactor: convert checkBookingAndDurationLimits to service class with DI - Create CheckBookingAndDurationLimitsService class following DI pattern - Add DI tokens and module for the new service - Update booking-limits container to provide the new service - Refactor handleNewBooking.ts to use service through DI - Maintain backward compatibility with deprecated function export - Preserve all existing functionality while improving code organization Co-Authored-By: morgan@cal.com <morgan@cal.com> * chore: CheckBookingAndDurationLimitsService * chore: bump platform libs --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: morgan@cal.com <morgan@cal.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
* Return a busy block placeholder if calendar throws an error * Refactor `getCalendarsEvents` to return an object with a success prop * Throw error in `getBusyTimes` if failed to fetch calendar availability * Return empty available days if error getting busy times * yeet. * Type fix * Fix type error in getLuckyUsers * Type fixes * Type fix * Type fix * Fix test * Fix test mocks * Refactor calendars.service to use new calendarBusyTimesQuery --------- Co-authored-by: Alex van Andel <me@alexvanandel.com>
Co-authored-by: CarinaWolli <wollencarina@gmail.com>
…mocking - Add setupAndTeardown() for proper test environment setup - Use mockNoTranslations() to fix translation function mocking - Simplify NextApiRequest mock to resolve TypeScript errors - Both test cases now pass successfully Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/features/instant-meeting/handleInstantMeeting.test.ts (1)
195-203
: Consider using the existinggetDate
utility to reduce code duplication.The local
getDate
function duplicates functionality available in the importedbookingScenario
utilities. The existing utility function provides more comprehensive date handling with proper overflow management.Consider removing the local function and using the imported one:
- 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], - }; - }And update the usage (lines 48, 143) to use the imported function:
- const { dateString: plus1DateString } = getDate({ dateIncrement: 1 }); + const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });The imported
getDate
already returns adateString
property, so the usage would remain the same.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/features/instant-meeting/handleInstantMeeting.test.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.ts
📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
**/*.ts
: For Prisma queries, only select data you need; never useinclude
, always useselect
Ensure thecredential.key
field is never returned from tRPC endpoints or APIs
Files:
packages/features/instant-meeting/handleInstantMeeting.test.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()
in hot paths like loops
Files:
packages/features/instant-meeting/handleInstantMeeting.test.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: vijayraghav-io
PR: calcom/cal.com#21072
File: packages/app-store/office365calendar/api/webhook.ts:120-123
Timestamp: 2025-07-18T17:57:16.395Z
Learning: The office365calendar webhook handler in packages/app-store/office365calendar/api/webhook.ts is specifically designed for Office365 calendar integration, not as a generic webhook handler. Therefore, it's safe to assume that fetchAvailabilityAndSetCache method will be implemented in the Office365CalendarService, making explicit validation checks unnecessary.
packages/features/instant-meeting/handleInstantMeeting.test.ts (1)
Learnt from: vijayraghav-io
PR: #21072
File: packages/app-store/office365calendar/api/webhook.ts:120-123
Timestamp: 2025-07-18T17:57:16.395Z
Learning: The office365calendar webhook handler in packages/app-store/office365calendar/api/webhook.ts is specifically designed for Office365 calendar integration, not as a generic webhook handler. Therefore, it's safe to assume that fetchAvailabilityAndSetCache method will be implemented in the Office365CalendarService, making explicit validation checks unnecessary.
🧬 Code Graph Analysis (1)
packages/features/instant-meeting/handleInstantMeeting.test.ts (1)
apps/web/test/utils/bookingScenario/bookingScenario.ts (9)
mockNoTranslations
(1630-1638)getOrganizer
(1474-1530)TestData
(1193-1465)getGoogleCalendarCredential
(1146-1154)getDate
(1047-1094)createBookingScenario
(932-963)getScenarioData
(1532-1618)mockSuccessfulVideoMeetingCreation
(2000-2018)mockCalendarToHaveNoBusySlots
(1879-1892)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Install dependencies / Yarn install & cache
🔇 Additional comments (4)
packages/features/instant-meeting/handleInstantMeeting.test.ts (4)
1-18
: LGTM! Well-structured imports following established patterns.The import structure is clean and follows the established pattern used in other Cal.com test files, importing necessary testing utilities and dependencies.
19-31
: LGTM! Proper dependency mocking for unit testing.The mocks appropriately isolate external dependencies (notifications and video client) while providing realistic mock data for testing the core functionality.
37-131
: Excellent comprehensive test coverage for successful instant meeting creation.The test thoroughly covers the happy path scenario:
- Proper test data setup using established utilities
- Appropriate mocking of external dependencies
- Comprehensive assertions validating both API response and database state
- Realistic request data structure
The test follows established patterns and provides good coverage of the instant meeting creation functionality.
132-192
: LGTM! Proper error handling test for business rule validation.The test effectively validates that the handler correctly enforces the business rule that only team event types support instant meetings. The test structure mirrors the success case but omits the team property, ensuring the error path is properly tested.
E2E results are ready! |
test: add comprehensive unit tests for handleInstantMeeting
Summary
This PR reverts all previous changes related to the username constraint violation fix and instead adds comprehensive unit tests for the
handleInstantMeeting
function located atpackages/features/instant-meeting/handleInstantMeeting.ts
.Key Changes:
packages/features/instant-meeting/handleInstantMeeting.test.ts
handleInstantMeeting.ts
implementation itself remains untouchedThe new test suite covers:
AWAITING_HOST
statusReview & Testing Checklist for Human
getTranslation
mock may need adjustment or the handleInstantMeeting.ts code may need modification to remove translation dependency.Recommended test plan:
TZ=UTC yarn test packages/features/instant-meeting/handleInstantMeeting.test.ts
Diagram
Notes
getTranslation
function returns a function that should be called with translation keys, but the mock may not be returning the correct structure.fresh-booking.test.ts
pattern with minimal mocking and integration testing approach usingprismock
.Link to Devin run: https://app.devin.ai/sessions/12f0c4070a404750aaaee19477da6c32
Requested by: @anikdhabal (anik@cal.com)