Skip to content

fix: enforce 1-5 range on booking rating input#28898

Merged
pedroccastro merged 2 commits intomainfrom
fix/rating-input-range
Apr 15, 2026
Merged

fix: enforce 1-5 range on booking rating input#28898
pedroccastro merged 2 commits intomainfrom
fix/rating-input-range

Conversation

@pedroccastro
Copy link
Copy Markdown
Contributor

What does this PR do?

Adds int().min(1).max(5) constraints to the rating field in the submitRating Zod schema. The frontend already restricts values to 1–5 via RATING_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

  1. Submit a rating with value 1–5 from the booking success page → saves normally
  2. Submit a rating with value 0, 6, or a decimal via direct tRPC call → rejected with Zod validation error

Mandatory Tasks

  • I have self-reviewed the code.
  • N/A I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

The pull request modifies the validation schema for the submit rating endpoint by adding constraints to the rating field in submitRating.schema.ts. The rating field validation was updated from accepting any number to requiring an integer value between 1 and 5 inclusive. The bookingUid string field and optional comment field remain unchanged. The exported TypeScript type maintains the same shape, with only the Zod runtime validation logic modified. One line was added and one removed to implement this change.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: enforce 1-5 range on booking rating input' directly and concisely summarizes the main change: adding validation constraints to the rating field to enforce a 1-5 range.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining what the PR does (adds int().min(1).max(5) constraints), why it matters (aligns backend validation with frontend, protects downstream aggregations), and how to test it.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rating-input-range

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between a17f28e and 8a13b37.

📒 Files selected for processing (1)
  • packages/trpc/server/routers/publicViewer/submitRating.schema.ts

@pedroccastro pedroccastro merged commit 00693bb into main Apr 15, 2026
36 checks passed
@pedroccastro pedroccastro deleted the fix/rating-input-range branch April 15, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants