-
Notifications
You must be signed in to change notification settings - Fork 10.3k
refactor: improve test structure with builder patterns and scenario templates #22635
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
base: main
Are you sure you want to change the base?
Conversation
…emplates - Extend existing builders with sensible defaults and new utilities - Create scenario templates for common test patterns (fresh, reschedule, team) - Add standardized mock factories to reduce repetitive setup code - Provide high-level test helpers that combine setup, mocking, and expectations - Maintain backward compatibility with existing test utilities - Add comprehensive documentation and examples - Fix lint issues by replacing any types with proper type annotations The refactoring reduces test setup from 50+ lines to 3 lines while preserving exact test behavior and coverage. All existing tests continue to work unchanged. Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
🤖 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:
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ 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. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ No security or compliance issues detected. Reviewed everything up to f3942f4. Security Overview
Detected Code Changes
Reply to this PR with |
- Fix organizer type to include required timeZone property - Cast rescheduleUid to string type in mock factories - Update type definitions for better type safety - Ensure all test helper functions return properly typed objects Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
…thub.com/calcom/cal.com into devin/1752864512-refactor-test-structure
- Create complementary architecture between foundation and convenience layers - Foundation layer (packages/lib/test/testHelpers.ts): Advanced builder classes and low-level utilities - Convenience layer (apps/web/test/utils/bookingScenario/testHelpers.ts): Beginner-friendly setup functions - Update booking scenario helpers to use foundation utilities via createBookingMocks - Add comprehensive README.md documentation explaining when to use each approach - Support for seated events, round-robin, and recurring event scenarios - Maintain backward compatibility with all existing tests - Fix type checking issues and method access problems This provides both simplicity for beginners (90% of cases) and flexibility for advanced users (10% of cases). Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
- Move README.md from apps/web/test/utils/bookingScenario/ to packages/lib/test/ - Centralizes documentation for both testHelpers files in foundation layer location - Makes test utility guide more discoverable for all developers - No functional changes, just improved organization Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
refactor: improve test structure with builder patterns and scenario templates
Summary
This PR refactors Cal.com's unit test structure to reduce bloated and complex test setup by adopting builder patterns, factory functions, scenario templates, and standardized test utilities. The changes are additive and maintain backward compatibility - all existing tests continue to work unchanged.
Key improvements:
buildBookingScenario
,buildTestUser
,buildMockRequestData
providing sensible defaultscreateFreshBookingScenario
,createRescheduleScenario
,createTeamBookingScenario
for common test patternscreateStandardCalendarMock
,createStandardVideoMock
setupFreshBookingTest
that combine setup, mocking, and expectationsBefore/After comparison:
Review & Testing Checklist for Human
organizer
/booker
types andRecord<string, unknown>
usagegetOrganizer
,createBookingScenario
, etc.)Recommended test plan:
TZ=UTC yarn test apps/web/test/utils/bookingScenario/examples/refactoredFreshBooking.test.ts
Diagram
Notes
Record<string, unknown>
instead ofany
and explicit type casting where neededSession details: Requested by @anikdhabal
Devin session: https://app.devin.ai/sessions/bc4f255018b6475d95d66fce4243008a