feat: add test to verify unpublished platform orgs are excluded from credit usage#22567
Conversation
…credit usage - Add filtering logic in _getTeamWithAvailableCredits to skip unpublished platform organizations - Add comprehensive test case that verifies user with memberships in both unpublished platform org and regular team - Ensure only regular team is selected for credit usage, not unpublished platform org - Test validates team.findUnique calls and credit balance checks for correct team filtering 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 was added to the "User credits" suite in the Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/features/ee/billing/credit-service.test.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-playwright". (The package "eslint-plugin-playwright" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "eslint-plugin-playwright" was referenced from the config file in ".eslintrc.js". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. ✨ Finishing Touches
🪧 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 (
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
|
✅ No security or compliance issues detected. Reviewed everything up to 99523f1. Security Overview
Detected Code Changes
Reply to this PR with |
…hed platform orgs - Remove obsolete team.findUnique mocking since filtering moved to repository layer - Update test to mock findAllAcceptedPublishedTeamMemberships correctly - Test now validates integration with repository-level filtering - Maintains core validation that unpublished platform orgs are excluded from credit usage Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
…nario - Add clearer comments explaining user has memberships in both teams - Clarify that repository method filters out unpublished platform orgs - Better document the architectural change from PR #22600 Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
- Add detailed comments explaining user has memberships in TWO teams initially - Clarify that unpublished platform org (teamId: 1) and regular team (teamId: 2) scenario - Explain repository-level filtering removes unpublished platform orgs before credit service - Address user feedback about demonstrating two-team membership scenario Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
- Clarify that user has memberships in BOTH teams initially in database - Explain that repository method filters out unpublished platform org (teamId: 1) - Document that only regular team (teamId: 2) is returned to credit service - Address user feedback about demonstrating the filtering behavior clearly - Test validates integration with repository-level filtering from PR #22600 Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
- Mock repository to return only regular team (teamId: 2) as expected after filtering - Update credit balance mock and expectations to match teamId: 2 - Test now passes and validates that unpublished platform org is filtered out - Address user feedback about showing correct filtering behavior in test logic Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
- Mock repository to return both membership objects: teamId 1 and teamId 2 - Show user has memberships in both unpublished platform org and regular team - Mock different credit states: teamId 1 has no credits/limit reached, teamId 2 has available credits - Verify both teams are processed but only regular team (teamId 2) is selected - Test now demonstrates actual filtering behavior in test logic, not just comments - Addresses user feedback: 'create two membership with those two teams in that test' Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
- Mock repository to return both membership objects: teamId 1 and teamId 2 - Show user has memberships in both unpublished platform org and regular team - Mock different credit states: teamId 1 has no credits/limit reached, teamId 2 has available credits - Verify both teams are processed but only regular team (teamId 2) is selected - Test now demonstrates actual filtering behavior in test logic, not just comments - Addresses user feedback: 'create two membership with those two teams in that test' Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
This reverts commit d7c4beb.
…9519' of https://git-manager.devin.ai/proxy/github.com/calcom/cal.com into devin/test-unpublished-platform-org-credit-usage-1752689519
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/features/ee/billing/credit-service.test.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: vijayraghav-io
PR: calcom/cal.com#21072
File: .env.example:354-357
Timestamp: 2025-07-18T08:49:18.742Z
Learning: For E2E integration tests that require real third-party service credentials (like Outlook calendar), it's acceptable to temporarily include actual test account credentials in .env.example during feature development and validation, provided there's a clear plan to replace them with placeholder values before final release. Test credentials should be for dedicated test tenants/accounts, not production systems.
packages/features/ee/billing/credit-service.test.ts (1)
Learnt from: vijayraghav-io
PR: calcom/cal.com#21072
File: .env.example:354-357
Timestamp: 2025-07-18T08:49:18.742Z
Learning: For E2E integration tests that require real third-party service credentials (like Outlook calendar), it's acceptable to temporarily include actual test account credentials in .env.example during feature development and validation, provided there's a clear plan to replace them with placeholder values before final release. Test credentials should be for dedicated test tenants/accounts, not production systems.
⏰ 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). (2)
- GitHub Check: Install dependencies / Yarn install & cache
- GitHub Check: Security Check
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (07/19/25)1 reviewer was added to this PR based on Keith Williams's automation. "Add platform team as reviewer" took an action on this PR • (07/19/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/19/25)1 label was added to this PR based on Keith Williams's automation. |
E2E results are ready! |
…credit usage (#22567) * feat: add test to verify unpublished platform orgs are excluded from credit usage - Add filtering logic in _getTeamWithAvailableCredits to skip unpublished platform organizations - Add comprehensive test case that verifies user with memberships in both unpublished platform org and regular team - Ensure only regular team is selected for credit usage, not unpublished platform org - Test validates team.findUnique calls and credit balance checks for correct team filtering Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * Update credit-service.ts * Update credit-service.test.ts * fix: update test to work with repository-level filtering for unpublished platform orgs - Remove obsolete team.findUnique mocking since filtering moved to repository layer - Update test to mock findAllAcceptedPublishedTeamMemberships correctly - Test now validates integration with repository-level filtering - Maintains core validation that unpublished platform orgs are excluded from credit usage Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * docs: improve test comments to clarify repository-level filtering scenario - Add clearer comments explaining user has memberships in both teams - Clarify that repository method filters out unpublished platform orgs - Better document the architectural change from PR #22600 Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * docs: clarify test demonstrates user with memberships in both teams - Add detailed comments explaining user has memberships in TWO teams initially - Clarify that unpublished platform org (teamId: 1) and regular team (teamId: 2) scenario - Explain repository-level filtering removes unpublished platform orgs before credit service - Address user feedback about demonstrating two-team membership scenario Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * docs: add comprehensive comments explaining two-team filtering scenario - Clarify that user has memberships in BOTH teams initially in database - Explain that repository method filters out unpublished platform org (teamId: 1) - Document that only regular team (teamId: 2) is returned to credit service - Address user feedback about demonstrating the filtering behavior clearly - Test validates integration with repository-level filtering from PR #22600 Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * fix: update test to properly demonstrate filtering behavior - Mock repository to return only regular team (teamId: 2) as expected after filtering - Update credit balance mock and expectations to match teamId: 2 - Test now passes and validates that unpublished platform org is filtered out - Address user feedback about showing correct filtering behavior in test logic Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * feat: demonstrate two-team membership scenario in test logic - Mock repository to return both membership objects: teamId 1 and teamId 2 - Show user has memberships in both unpublished platform org and regular team - Mock different credit states: teamId 1 has no credits/limit reached, teamId 2 has available credits - Verify both teams are processed but only regular team (teamId 2) is selected - Test now demonstrates actual filtering behavior in test logic, not just comments - Addresses user feedback: 'create two membership with those two teams in that test' Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * feat: demonstrate two-team membership scenario in test logic - Mock repository to return both membership objects: teamId 1 and teamId 2 - Show user has memberships in both unpublished platform org and regular team - Mock different credit states: teamId 1 has no credits/limit reached, teamId 2 has available credits - Verify both teams are processed but only regular team (teamId 2) is selected - Test now demonstrates actual filtering behavior in test logic, not just comments - Addresses user feedback: 'create two membership with those two teams in that test' Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * Revert "feat: demonstrate two-team membership scenario in test logic" This reverts commit d7c4beb. * Update credit-service.test.ts * Update credit-service.test.ts * Update credit-service.test.ts --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Fix: Add unpublished platform org filtering test & implement host-based attendee filtering
Summary
This PR addresses two main requirements:
Credit Service Testing: Adds comprehensive tests to verify that unpublished platform organizations (teams with
isPlatform: trueandslug: null) are excluded from credit usage selection. The tests demonstrate that when a user has memberships in both an unpublished platform org and a regular team, only the regular team is considered for credit allocation.Host-Based Attendee Filtering: Implements the
checkIfUserIsHostfunction and integrates it into the bookings handler to filter attendees when the current user is not the booking host. This prevents users from seeing attendee details for bookings where they don't have host privileges.The implementation required adding
usersandhostsselections to theeventTypemodel in the bookings query to support host verification logic.Review & Testing Checklist for Human
checkIfUserIsHostworks correctly for booking owners, event type users, and hosts with various attendee email configurationsseatsShowAttendees: falseand user is not hostDiagram
%%{ init : { "theme" : "default" }}%% flowchart TD CreditService["packages/features/ee/billing/<br/>credit-service.ts"]:::minor-edit CreditTest["packages/features/ee/billing/<br/>credit-service.test.ts"]:::major-edit BookingsHandler["packages/trpc/server/routers/viewer/<br/>bookings/get.handler.ts"]:::major-edit CreditTest --> CreditService BookingsHandler --> EventTypeModel["EventType Model<br/>(users & hosts)"]:::context BookingsHandler --> CheckHostFunc["checkIfUserIsHost<br/>Function"]:::major-edit CheckHostFunc --> AttendeeFilter["Attendee Filtering<br/>Logic"]:::context 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
_EventTypeToUserjunction table to directEventType.userIdrelationship for users selectioncheckIfUserIsHostimplementation follows the same pattern used inbookings-single-view.getServerSideProps.tsxLink to Devin run: https://app.devin.ai/sessions/ec17a836891347abb35efe5f036b1f2b
Requested by: @anikdhabal