Skip to content

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
devin/1771228776-fix-as-any-typing
Feb 16, 2026
Merged

refactor: replace PrismaMock unit test with Prisma integration test for duplicate handler#27973
alishaz-polymath merged 2 commits intodevin/duplicate-managed-event-types-1768299152from
devin/1771228776-fix-as-any-typing

Conversation

@alishaz-polymath
Copy link
Copy Markdown
Member

@alishaz-polymath alishaz-polymath commented Feb 16, 2026

What does this PR do?

Removes the PrismaMock-based unit test for duplicateHandler and 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 all as any casts (there were 10+ in the old test).

  • Old: duplicate.handler.test.ts — mocked Prisma, mocked EventTypeRepository, 10+ as any / eslint-disable lines
  • New: duplicate.handler.integration-test.ts — real DB records, real handler execution, zero as any

Follows the established integration test pattern from listWithTeam.handler.integration-test.ts and getEventTypesFromGroup.integration-test.ts.

Handler bug fix

The duplicateHandler catch block was swallowing intentional TRPCErrors (e.g. FORBIDDEN, NOT_FOUND) and re-throwing them as INTERNAL_SERVER_ERROR. Added an early instanceof TRPCError check to re-throw them as-is. This was discovered because the integration test for non-team-member access was receiving INTERNAL_SERVER_ERROR instead of the intended FORBIDDEN.

Test coverage (7 tests)

  1. Duplicates an individual event type (title, slug, length)
  2. Preserves schedulingType: MANAGED on duplication
  3. Copies hosts but not children for managed event types
  4. Sets parentId to null on duplicated managed event types
  5. Allows team members to duplicate managed event types
  6. Rejects non-team members with FORBIDDEN
  7. Returns CONFLICT on duplicate slug (unique constraint violation)

How should this be tested?

TZ=UTC VITEST_MODE=integration yarn vitest run packages/trpc/server/routers/viewer/eventTypes/heavy/duplicate.handler.integration-test.ts

Requires a running Postgres database with migrations applied (yarn workspace @calcom/prisma db-migrate).

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

Human Review Checklist

  • Handler catch block change (duplicate.handler.ts:228-230): Now re-throws TRPCError instances before the generic INTERNAL_SERVER_ERROR fallback. This is a production behavior change — previously FORBIDDEN and NOT_FOUND were incorrectly returned as INTERNAL_SERVER_ERROR to clients.
  • createCtx helper (integration test line 12-21): Uses as NonNullable<TrpcSessionUser> with only id and profile.id populated. This follows the pattern in getEventTypesFromGroup.integration-test.ts, but verify the handler doesn't access other TrpcSessionUser fields in paths exercised by these tests.
  • Slug conflict test (integration test line 250-280): Asserts only code: "CONFLICT" — the handler has a more specific "duplicate_event_slug_conflict" message branch for when meta.target includes "slug". The P2002 meta.target for the @@unique([userId, slug]) constraint may not match — worth verifying the slug-specific error path is reachable.
  • Cleanup in afterAll: Deletes hosts, event types, memberships, teams, and users in order. Confirm cascade behavior is handled correctly if any beforeAll step partially fails.

Link to Devin run: https://app.devin.ai/sessions/d6a4ad26a26140a2b7d70a5519e2636e
Requested by: @alishaz-polymath

…or duplicate handler

Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>
@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' or '@devin'.
  • 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

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 16, 2026

Devin AI is addressing Cubic AI's review feedback

New feedback has been sent to the existing Devin session.

View Devin Session


✅ Pushed commit 54dbdbb

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 5 additional findings in Devin Review.

Open in Devin Review

…specific error codes in tests

Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>
@alishaz-polymath alishaz-polymath added ready-for-e2e run-ci Approve CI to run for external contributors labels Feb 16, 2026
@alishaz-polymath alishaz-polymath marked this pull request as ready for review February 16, 2026 08:35
@graphite-app graphite-app bot added core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO labels Feb 16, 2026
@graphite-app graphite-app bot requested a review from a team February 16, 2026 08:35
@alishaz-polymath alishaz-polymath merged commit 4a83708 into devin/duplicate-managed-event-types-1768299152 Feb 16, 2026
26 of 28 checks passed
@alishaz-polymath alishaz-polymath deleted the devin/1771228776-fix-as-any-typing branch February 16, 2026 08:37
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>
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 enterprise area: enterprise, audit log, organisation, SAML, SSO ready-for-e2e run-ci Approve CI to run for external contributors size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant