refactor: replace PrismaMock unit test with Prisma integration test for duplicate handler#27973
Merged
alishaz-polymath merged 2 commits intodevin/duplicate-managed-event-types-1768299152from Feb 16, 2026
Conversation
…or duplicate handler Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>
Contributor
🤖 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:
|
Contributor
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/trpc/server/routers/viewer/eventTypes/heavy/duplicate.handler.integration-test.ts">
<violation number="1" location="packages/trpc/server/routers/viewer/eventTypes/heavy/duplicate.handler.integration-test.ts:246">
P3: This assertion is too broad for a test that promises a FORBIDDEN error. It will pass even if the handler throws the wrong TRPCError code. Assert the error code to ensure the access-control behavior is covered.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
packages/trpc/server/routers/viewer/eventTypes/heavy/duplicate.handler.integration-test.ts
Outdated
Show resolved
Hide resolved
Contributor
Devin AI is addressing Cubic AI's review feedbackNew feedback has been sent to the existing Devin session. ✅ Pushed commit |
packages/trpc/server/routers/viewer/eventTypes/heavy/duplicate.handler.integration-test.ts
Show resolved
Hide resolved
…specific error codes in tests Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>
4a83708
into
devin/duplicate-managed-event-types-1768299152
26 of 28 checks passed
alishaz-polymath
added a commit
that referenced
this pull request
Feb 18, 2026
* feat: add duplicate functionality for managed event types Co-Authored-By: peer@cal.com <peer@cal.com> * feat: add disclaimer and redirect for managed event type duplication - Add info alert disclaimer in duplicate modal for managed event types - Pass schedulingType to duplicate dialog via query params - Redirect to assignment tab after duplicating managed event types - Add translation key for managed event type duplicate disclaimer Co-Authored-By: peer@cal.com <peer@cal.com> * test: add tests for managed event type duplication Co-Authored-By: peer@cal.com <peer@cal.com> * refactor: replace PrismaMock unit test with Prisma integration test for duplicate handler (#27973) * refactor: replace PrismaMock unit test with Prisma integration test for duplicate handler Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * fix: re-throw TRPCErrors in duplicate handler catch block and assert specific error codes in tests Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Hariom Balhara <1780212+hariombalhara@users.noreply.github.com> Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>
pedroccastro
pushed a commit
that referenced
this pull request
Feb 21, 2026
* feat: add duplicate functionality for managed event types Co-Authored-By: peer@cal.com <peer@cal.com> * feat: add disclaimer and redirect for managed event type duplication - Add info alert disclaimer in duplicate modal for managed event types - Pass schedulingType to duplicate dialog via query params - Redirect to assignment tab after duplicating managed event types - Add translation key for managed event type duplicate disclaimer Co-Authored-By: peer@cal.com <peer@cal.com> * test: add tests for managed event type duplication Co-Authored-By: peer@cal.com <peer@cal.com> * refactor: replace PrismaMock unit test with Prisma integration test for duplicate handler (#27973) * refactor: replace PrismaMock unit test with Prisma integration test for duplicate handler Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * fix: re-throw TRPCErrors in duplicate handler catch block and assert specific error codes in tests Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Hariom Balhara <1780212+hariombalhara@users.noreply.github.com> Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Removes the PrismaMock-based unit test for
duplicateHandlerand replaces it with an integration test that uses Prisma directly against a real database. This aligns with the codebase's migration away from PrismaMock and eliminates allas anycasts (there were 10+ in the old test).duplicate.handler.test.ts— mocked Prisma, mockedEventTypeRepository, 10+as any/eslint-disablelinesduplicate.handler.integration-test.ts— real DB records, real handler execution, zeroas anyFollows the established integration test pattern from
listWithTeam.handler.integration-test.tsandgetEventTypesFromGroup.integration-test.ts.Handler bug fix
The
duplicateHandlercatch block was swallowing intentionalTRPCErrors (e.g.FORBIDDEN,NOT_FOUND) and re-throwing them asINTERNAL_SERVER_ERROR. Added an earlyinstanceof TRPCErrorcheck to re-throw them as-is. This was discovered because the integration test for non-team-member access was receivingINTERNAL_SERVER_ERRORinstead of the intendedFORBIDDEN.Test coverage (7 tests)
schedulingType: MANAGEDon duplicationparentIdto null on duplicated managed event typesFORBIDDENCONFLICTon duplicate slug (unique constraint violation)How should this be tested?
Requires a running Postgres database with migrations applied (
yarn workspace @calcom/prisma db-migrate).Mandatory Tasks (DO NOT REMOVE)
Human Review Checklist
duplicate.handler.ts:228-230): Now re-throwsTRPCErrorinstances before the genericINTERNAL_SERVER_ERRORfallback. This is a production behavior change — previouslyFORBIDDENandNOT_FOUNDwere incorrectly returned asINTERNAL_SERVER_ERRORto clients.createCtxhelper (integration test line 12-21): Usesas NonNullable<TrpcSessionUser>with onlyidandprofile.idpopulated. This follows the pattern ingetEventTypesFromGroup.integration-test.ts, but verify the handler doesn't access otherTrpcSessionUserfields in paths exercised by these tests.code: "CONFLICT"— the handler has a more specific"duplicate_event_slug_conflict"message branch for whenmeta.targetincludes"slug". The P2002meta.targetfor the@@unique([userId, slug])constraint may not match — worth verifying the slug-specific error path is reachable.afterAll: Deletes hosts, event types, memberships, teams, and users in order. Confirm cascade behavior is handled correctly if anybeforeAllstep partially fails.Link to Devin run: https://app.devin.ai/sessions/d6a4ad26a26140a2b7d70a5519e2636e
Requested by: @alishaz-polymath