fix: enforce 1-5 range on booking rating input#28898
Conversation
📝 WalkthroughWalkthroughThe pull request modifies the validation schema for the submit rating endpoint by adding constraints to the 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/trpc/server/routers/publicViewer/submitRating.schema.ts (1)
11-11: Please add boundary tests for the new schema constraints.Given the new runtime guard on Line 11, add tests for
0,1,5,6, and a decimal (e.g.3.5) to prevent regressions.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/trpc/server/routers/publicViewer/submitRating.schema.ts` at line 11, Add boundary unit tests for the submitRating schema's runtime guard on the "rating" field: create tests that validate inputs 0 (should fail), 1 (should pass), 5 (should pass), 6 (should fail), and a decimal like 3.5 (should fail). Target the schema exported from submitRating.schema.ts (the rating: z.number().int().min(1).max(5) validation) and use the same test harness/assertion style as the surrounding router/schema tests to assert success/failure for each value to prevent regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/trpc/server/routers/publicViewer/submitRating.schema.ts`:
- Line 11: Add boundary unit tests for the submitRating schema's runtime guard
on the "rating" field: create tests that validate inputs 0 (should fail), 1
(should pass), 5 (should pass), 6 (should fail), and a decimal like 3.5 (should
fail). Target the schema exported from submitRating.schema.ts (the rating:
z.number().int().min(1).max(5) validation) and use the same test
harness/assertion style as the surrounding router/schema tests to assert
success/failure for each value to prevent regressions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6fabb30b-407f-4bb8-a85c-7c706015a4a7
📒 Files selected for processing (1)
packages/trpc/server/routers/publicViewer/submitRating.schema.ts
What does this PR do?
Adds
int().min(1).max(5)constraints to theratingfield in thesubmitRatingZod schema. The frontend already restricts values to 1–5 viaRATING_OPTIONS, so this aligns the backend validation with the actual contract and protects downstream consumers (e.g.,AVG(rating)aggregations in Insights).Changes
submitRating.schema.ts:rating: z.number()→rating: z.number().int().min(1).max(5)How should this be tested?
Manual
Mandatory Tasks