Conversation
… listWithTeam integration test
Originally by: zomars
# fix: resolve unique constraint violations in listWithTeam integration test
## Summary
Fixed a failing integration test in `listWithTeam.handler.integration-test.ts` that was causing unique constraint violations. The test was using hardcoded email addresses and slugs that persisted between test runs, causing failures when the same test data already existed in the database.
**Key changes:**
- Added timestamp-based unique identifiers for usernames, emails, team slugs, and event type slugs
- Implemented robust error handling in test cleanup with null checks and try-catch blocks
- Test success rate improved from 113/114 to 114/114 (100% pass rate)
**Root cause:** The test used static values like `testuser-lwt-1@example.com` and `team-1-lwt` that violated unique constraints on subsequent test runs.
## Review & Testing Checklist for Human
- [ ] **Verify test passes consistently** - Run `TZ=UTC yarn test -- --integrationTestsOnly` multiple times to ensure the fix is robust
- [ ] **Check timestamp uniqueness approach** - Confirm that `Date.now()` provides sufficient uniqueness for concurrent test scenarios
- [ ] **Validate cleanup logic** - Ensure the new error handling in `afterAll` properly cleans up test data without masking real errors
- [ ] **Test multiple rapid runs** - Execute the test suite several times in quick succession to verify no race conditions exist
---
### Diagram
```mermaid
%%{ init : { "theme" : "default" }}%%
graph TD
Test["packages/trpc/server/routers/viewer/eventTypes/<br/>listWithTeam.handler.integration-test.ts"]:::major-edit
Handler["listWithTeam.handler"]:::context
UserModel["User (Prisma Model)"]:::context
TeamModel["Team (Prisma Model)"]:::context
EventTypeModel["EventType (Prisma Model)"]:::context
Test --> Handler
Test --> UserModel
Test --> TeamModel
Test --> EventTypeModel
Test -- "creates with unique timestamps" --> UserModel
Test -- "creates with unique slugs" --> TeamModel
Test -- "creates with unique slugs" --> EventTypeModel
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
```
### Notes
- This fix addresses the PrismaClientKnownRequestError: Unique constraint failed on the fields: (`email`) that was preventing the integration test suite from achieving 100% pass rate
- The solution maintains test isolation by ensuring each test run creates truly unique database records
- Session requested by @zomars: https://app.devin.ai/sessions/3d62b140e87c424ab80c9ed76ac298ca
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit
* **Tests**
* Improved test reliability by ensuring unique test data for each run and enhancing cleanup procedures for better error handling.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
|
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details: |
|
cursor review |
There was a problem hiding this comment.
✅ BugBot reviewed your changes and found no bugs!
BugBot free trial expires on July 22, 2025
Learn more in the Cursor dashboard.
Was this report helpful? Give feedback by reacting with 👍 or 👎
There was a problem hiding this comment.
Greptile Summary
This PR fixes failing integration tests by addressing unique constraint violations in the listWithTeam.handler.integration-test.ts file. The key issue was that tests were using static values for emails and slugs, causing database conflicts when tests were run multiple times. The solution adds timestamp-based unique identifiers and improves error handling during test cleanup.
Specific changes include:
- Using
Date.now()to generate unique identifiers for test data (usernames, emails, team slugs) - Adding robust error handling with try-catch blocks in test cleanup
- Implementing proper null checks and Boolean filtering for cleanup operations
This fix takes the test suite from a 99.1% pass rate (113/114) to 100% (114/114).
Confidence score: 5/5
- This PR is very safe to merge as it only affects test code and has no impact on production
- The changes follow best practices for test isolation and error handling
- Files needing attention:
packages/trpc/server/routers/viewer/eventTypes/listWithTeam.handler.integration-test.ts- Verify the timestamp-based uniqueness approach works for concurrent test scenarios
1 file reviewed, no comments
Edit PR Review Bot Settings | Greptile
This is a copy of calcom#22493
Originally by: zomars
fix: resolve unique constraint violations in listWithTeam integration test
Summary
Fixed a failing integration test in
listWithTeam.handler.integration-test.tsthat was causing unique constraint violations. The test was using hardcoded email addresses and slugs that persisted between test runs, causing failures when the same test data already existed in the database.Key changes:
Root cause: The test used static values like
testuser-lwt-1@example.comandteam-1-lwtthat violated unique constraints on subsequent test runs.Review & Testing Checklist for Human
TZ=UTC yarn test -- --integrationTestsOnlymultiple times to ensure the fix is robustDate.now()provides sufficient uniqueness for concurrent test scenariosafterAllproperly cleans up test data without masking real errorsDiagram
%%{ init : { "theme" : "default" }}%% graph TD Test["packages/trpc/server/routers/viewer/eventTypes/<br/>listWithTeam.handler.integration-test.ts"]:::major-edit Handler["listWithTeam.handler"]:::context UserModel["User (Prisma Model)"]:::context TeamModel["Team (Prisma Model)"]:::context EventTypeModel["EventType (Prisma Model)"]:::context Test --> Handler Test --> UserModel Test --> TeamModel Test --> EventTypeModel Test -- "creates with unique timestamps" --> UserModel Test -- "creates with unique slugs" --> TeamModel Test -- "creates with unique slugs" --> EventTypeModel 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
email) that was preventing the integration test suite from achieving 100% pass rateSummary by CodeRabbit