feat: block structural project edits#680
Conversation
|
@usmanliaqat0 is attempting to deploy a commit to the TryCatch 4 Match's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughAdds structural change detection to the team-project PUT endpoint, blocks structural updates after team formation, refactors stack persistence into a helper, adds unit tests, and configures SonarCloud LCOV coverage reporting. ChangesStructural Change Guard for Team-Project Updates
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant PUTRoute
participant planProjectStackChanges
participant Prisma
PUTRoute->>planProjectStackChanges: compare existing and incoming structure
planProjectStackChanges-->>PUTRoute: stack changes
PUTRoute->>Prisma: delete/update/create projectStack rows
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/tests/unit/api/team-project/team-project-id-route.test.ts (1)
146-206: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider adding coverage for
deadlineandtotalValuestructural blocks.
hasStructuralProjectChangesalso guardsdeadlineandtotalValue(route lines 85-86), but onlyname,skills, andstacksare exercised here. Two small cases mirroring the existing blocked-update tests would lock in the full guard contract.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tests/unit/api/team-project/team-project-id-route.test.ts` around lines 146 - 206, Add test coverage in team-project-id-route.test for the remaining structural guards handled by hasStructuralProjectChanges in the PUT route: verify that changing deadline and changing totalValue after stacksTaken exist both return 403 and do not call prisma.project.update. Mirror the existing blocked-update cases using PUT, createRequest, createContext, existingProject, and the same MESSAGES.AUTH.UNAUTHORIZED assertion pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/api/team-project/`[id]/route.ts:
- Around line 92-129: The stack CRUD in applyProjectStackChanges and the later
project update are not atomic, so partial failures can leave projectStack and
stackTaken mutations persisted without the project update. Refactor
applyProjectStackChanges to accept a transactional Prisma client and execute its
deleteMany/update/create work inside a single prisma.$transaction alongside the
prisma.project.update call in the team-project route handler. Use the same tx
for all stack and project writes so the diff application and project update
succeed or fail together.
---
Nitpick comments:
In `@src/tests/unit/api/team-project/team-project-id-route.test.ts`:
- Around line 146-206: Add test coverage in team-project-id-route.test for the
remaining structural guards handled by hasStructuralProjectChanges in the PUT
route: verify that changing deadline and changing totalValue after stacksTaken
exist both return 403 and do not call prisma.project.update. Mirror the existing
blocked-update cases using PUT, createRequest, createContext, existingProject,
and the same MESSAGES.AUTH.UNAUTHORIZED assertion pattern.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8f34f932-55f0-4be0-a55c-4173774e01d1
📒 Files selected for processing (3)
sonar-project.propertiessrc/app/api/team-project/[id]/route.tssrc/tests/unit/api/team-project/team-project-id-route.test.ts
|



Summary
Validation
npx jest src/tests/unit/api/team-project/team-project-id-route.test.ts --coverage --collectCoverageFrom='src/app/api/team-project/[id]/route.ts' --runInBandnpm run lintnpm testnpm run buildnpm run test:push/,/login,/dashboard/team-projects/1234567890123456789012345/edit, andPUT /api/team-project/[id]Summary by CodeRabbit
PUT /api/team-project/[id]route covering both permitted updates and blocked structural changes after team formation.