Skip to content

🧪 Add parameter validation tests for commentaryRouter - #14

Open
somyaknotfound wants to merge 1 commit into
mainfrom
add-commentary-router-tests-16732254526166772507
Open

🧪 Add parameter validation tests for commentaryRouter#14
somyaknotfound wants to merge 1 commit into
mainfrom
add-commentary-router-tests-16732254526166772507

Conversation

@somyaknotfound

Copy link
Copy Markdown
Owner

🎯 What:
Added tests for the commentaryRouter to verify parameter validation when accessing or creating commentary for matches.

📊 Coverage:

  • GET /matches/:id/commentary with a non-numeric match ID
  • GET /matches/:id/commentary with a negative match ID
  • GET /matches/:id/commentary with invalid query parameters (e.g. limit)
  • POST /matches/:id/commentary with an invalid match ID
  • POST /matches/:id/commentary with an invalid commentary payload

Result:

  • Improved test coverage for route validation without hitting the database, utilizing supertest and vitest.
  • Ensure robust handling of edge cases for the commentary endpoints.
  • Added a proper test script to package.json to make running tests uniform across the codebase.

PR created automatically by Jules for task 16732254526166772507 started by @somyaknotfound

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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 9, 2026 06:53
@coderabbitai

coderabbitai Bot commented Mar 9, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@somyaknotfound has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d483a7b-789a-4fc2-b64a-20916536aa3f

📥 Commits

Reviewing files that changed from the base of the PR and between 8072c68 and 394ffba.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json
  • src/routes/commentary.test.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-commentary-router-tests-16732254526166772507

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 + new src/routes/commentary.test.js covering 400 responses for invalid match IDs, query params, and POST payloads.
  • Added test script (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);

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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');

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants