Skip to content

feat: implement app-store factory pattern for improved testability#22630

Closed
keithwillcode wants to merge 3 commits intomainfrom
devin/app-store-factory-1752848662
Closed

feat: implement app-store factory pattern for improved testability#22630
keithwillcode wants to merge 3 commits intomainfrom
devin/app-store-factory-1752848662

Conversation

@keithwillcode
Copy link
Copy Markdown
Contributor

@keithwillcode keithwillcode commented Jul 18, 2025

feat: implement app-store factory pattern for improved testability

Summary

This PR refactors the app-store mocking system in bookingScenario.ts by replacing the complex appStoreMock deep mocking approach with a cleaner factory pattern. The new system provides:

  • IAppStore interface defining contracts for Calendar, CRM, and Video services
  • TestAppStore with configurable mock implementations for each service type
  • ProductionAppStore wrapping existing getCalendar/getCrm utilities
  • AppStoreFactory for dependency injection in tests
  • Backward compatibility with existing mockCalendar, mockVideoApp, mockCrmApp APIs

The factory pattern eliminates the need for complex mock overrides while providing better type safety and easier test configuration.

Review & Testing Checklist for Human

  • Run existing booking scenario tests - Verify all tests in apps/web/test/utils/bookingScenario still pass with the new factory system
  • Test production calendar/CRM functionality - Ensure normal (non-test) calendar and CRM operations work correctly after the getCalendar.ts changes
  • Verify factory state cleanup - Check that AppStoreFactory.reset() properly cleans state between tests to prevent test pollution
  • Validate service interface implementations - Ensure TestAppStore services correctly implement the expected Calendar/CRM/Video interfaces
  • Run full type checking - Confirm yarn type-check:ci passes completely (I had to use any for 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:#FFFFFF
Loading

Notes

  • Link to Devin run: https://app.devin.ai/sessions/7b5f33d1cf2a4a3595f6c090a2f81fe0
  • Requested by: @keithwillcode
  • Type Safety Compromise: Had to use any for VideoService due to VideoApiAdapter being a union type with undefined
  • Incomplete Video Implementation: ProductionVideoService throws error - video service factory integration not yet complete
  • Backward Compatibility: Existing test APIs (mockCalendar, etc.) maintained but now use factory internally
  • Factory Singleton: Uses singleton pattern requiring proper cleanup via AppStoreFactory.reset() between tests

- 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>
@vercel
Copy link
Copy Markdown

vercel bot commented Jul 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Jul 18, 2025 3:18pm
cal-eu ⬜️ Ignored (Inspect) Jul 18, 2025 3:18pm

@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 18, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/app-store-factory-1752848662

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@keithwillcode keithwillcode added core area: core, team members only foundation self-hosted labels Jul 18, 2025
@delve-auditor
Copy link
Copy Markdown

delve-auditor bot commented Jul 18, 2025

No security or compliance issues detected. Reviewed everything up to d2fbe5b.

Security Overview
  • 🔎 Scanned files: 9 changed file(s)
Detected Code Changes
Change Type Relevant files
Enhancement ► AppStoreFactory.ts
    Create app store factory pattern
► IAppStore.ts
    Define interfaces for calendar, CRM and video services
► ProductionAppStore.ts
    Implement production app store
► TestAppStore.ts
    Implement test app store with mocks
► bookingScenario.ts
    Refactor mock implementations to use factory pattern
► getCalendar.ts
    Add factory pattern support
► getCrm.ts
    Add factory pattern support
Configuration changes ► setupAndTeardown.ts
    Add AppStoreFactory reset in setup/teardown

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

devin-ai-integration bot and others added 2 commits July 18, 2025 14:52
- 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>
@keithwillcode
Copy link
Copy Markdown
Contributor Author

DevinAI can you try to fix the failing unit tests?

@keithwillcode
Copy link
Copy Markdown
Contributor Author

DevinAI, try 1 more time to fix these unit tests. If you cannot, will handle manually.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 5, 2025

This PR is being marked as stale due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only foundation self-hosted Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant