feat: implement app-store factory pattern for improved testability#22630
feat: implement app-store factory pattern for improved testability#22630keithwillcode wants to merge 3 commits intomainfrom
Conversation
- Create IAppStore interface with Calendar, CRM, and Video service abstractions - Implement TestAppStore with configurable mock implementations - Implement ProductionAppStore wrapping existing getCalendar/getCrm utilities - Add AppStoreFactory for dependency injection in tests - Refactor bookingScenario.ts to use factory pattern instead of deep mocks - Maintain backward compatibility with existing test APIs - Add proper cleanup in test setup/teardown - Update getCalendar.ts to support factory override for testing This replaces the complex appStoreMock overrides with a clean factory pattern that provides better type safety and easier test configuration. Co-Authored-By: keith@cal.com <keithwillcode@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 comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
✅ No security or compliance issues detected. Reviewed everything up to d2fbe5b. Security Overview
Detected Code Changes
Reply to this PR with |
- Remove AppStoreFactory integration from getCalendar.ts to prevent infinite recursion - Make ProductionAppStore throw errors - factory is for testing only - Update AppStoreFactory to require explicit initialization - Production code continues to work as before, factory only used in tests Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
- Import CalEventResponses from Calendar types - Fix createContacts parameter type to match CRM interface - Update IVideoService to use any type for compatibility - Add non-null assertion for calendarType in getCalendar Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
|
DevinAI can you try to fix the failing unit tests? |
|
DevinAI, try 1 more time to fix these unit tests. If you cannot, will handle manually. |
|
This PR is being marked as stale due to inactivity. |
feat: implement app-store factory pattern for improved testability
Summary
This PR refactors the app-store mocking system in
bookingScenario.tsby replacing the complexappStoreMockdeep mocking approach with a cleaner factory pattern. The new system provides:getCalendar/getCrmutilitiesmockCalendar,mockVideoApp,mockCrmAppAPIsThe factory pattern eliminates the need for complex mock overrides while providing better type safety and easier test configuration.
Review & Testing Checklist for Human
apps/web/test/utils/bookingScenariostill pass with the new factory systemgetCalendar.tschangesAppStoreFactory.reset()properly cleans state between tests to prevent test pollutionTestAppStoreservices correctly implement the expected Calendar/CRM/Video interfacesyarn type-check:cipasses completely (I had to useanyfor VideoService due to union type issues)Recommended Test Plan: Run the booking scenario test suite, then test a few production calendar/CRM operations to ensure normal functionality isn't broken.
Diagram
%%{ init : { "theme" : "default" }}%% graph TB subgraph "Test Files" BookingScenario["apps/web/test/utils/bookingScenario/<br/>bookingScenario.ts"]:::major-edit SetupTeardown["apps/web/test/utils/bookingScenario/<br/>setupAndTeardown.ts"]:::minor-edit end subgraph "New Factory System" IAppStore["packages/app-store/factory/<br/>IAppStore.ts"]:::major-edit TestAppStore["packages/app-store/factory/<br/>TestAppStore.ts"]:::major-edit ProductionAppStore["packages/app-store/factory/<br/>ProductionAppStore.ts"]:::major-edit AppStoreFactory["packages/app-store/factory/<br/>AppStoreFactory.ts"]:::major-edit end subgraph "Production Code" GetCalendar["packages/app-store/_utils/<br/>getCalendar.ts"]:::minor-edit GetCrm["packages/app-store/_utils/<br/>getCrm.ts"]:::context end BookingScenario --> AppStoreFactory AppStoreFactory --> TestAppStore AppStoreFactory --> ProductionAppStore ProductionAppStore --> GetCalendar ProductionAppStore --> GetCrm TestAppStore --> IAppStore SetupTeardown --> AppStoreFactory subgraph Legend L1[Major Edit]:::major-edit L2[Minor Edit]:::minor-edit L3[Context/No Edit]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
anyfor VideoService due toVideoApiAdapterbeing a union type withundefinedmockCalendar, etc.) maintained but now use factory internallyAppStoreFactory.reset()between tests