🧪 Add parameter validation tests for commentaryRouter - #14
Conversation
Added a new test file `src/routes/commentary.test.js` to test parameter validation for `GET /matches/:id/commentary` and `POST /matches/:id/commentary` methods. Uses `supertest` to isolate routing tests from the database layer, specifically ensuring invalid match IDs correctly return a 400 Bad Request error. Also updated `package.json` with `supertest` dev dependency and a `test` script using `vitest`. Co-authored-by: somyaknotfound <118343482+somyaknotfound@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
✨ Finishing Touches🧪 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.
Pull request overview
Adds route-level validation tests around commentaryRouter to ensure bad params/query/body are rejected early (before DB access), and standardizes how tests are executed via an npm script.
Changes:
- Added
supertest+ newsrc/routes/commentary.test.jscovering 400 responses for invalid match IDs, query params, and POST payloads. - Added
testscript (vitest run) to make running the test suite consistent. - Updated lockfile for the new dev dependency (
supertest) and its transitive deps.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/routes/commentary.test.js | New supertest-backed tests verifying 400 validation behavior for GET/POST commentary endpoints. |
| package.json | Adds a test script and includes supertest as a dev dependency. |
| package-lock.json | Lockfile updates reflecting supertest and transitive dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| expect(response.status).toBe(400); | ||
| expect(response.body).toHaveProperty('error', 'Invalid match ID.'); | ||
| expect(response.body).toHaveProperty('details'); | ||
| expect(response.body.details[0].message).toMatch(/Expected number, received /i); |
There was a problem hiding this comment.
This assertion couples the test to Zod’s exact issue message text, which is not a stable API and can change across Zod versions (or based on coercion behavior). Consider asserting on more stable properties (e.g., that details is a non-empty array and the issue path includes id, or only assert the top-level error string) to avoid brittle tests.
| expect(response.body.details[0].message).toMatch(/Expected number, received /i); | |
| expect(Array.isArray(response.body.details)).toBe(true); | |
| expect(response.body.details.length).toBeGreaterThan(0); | |
| expect(response.body.details[0]).toHaveProperty('path'); | |
| expect(response.body.details[0].path).toContain('id'); |
🎯 What:
Added tests for the
commentaryRouterto verify parameter validation when accessing or creating commentary for matches.📊 Coverage:
GET /matches/:id/commentarywith a non-numeric match IDGET /matches/:id/commentarywith a negative match IDGET /matches/:id/commentarywith invalid query parameters (e.g.limit)POST /matches/:id/commentarywith an invalid match IDPOST /matches/:id/commentarywith an invalid commentary payload✨ Result:
supertestandvitest.testscript topackage.jsonto make running tests uniform across the codebase.PR created automatically by Jules for task 16732254526166772507 started by @somyaknotfound