Skip to content

test(api): add payload assertions to 422 validation error tests (#469)#481

Merged
nanotaboada merged 1 commit intomasterfrom
test/469-validation-error-payload-assertions
Apr 21, 2026
Merged

test(api): add payload assertions to 422 validation error tests (#469)#481
nanotaboada merged 1 commit intomasterfrom
test/469-validation-error-payload-assertions

Conversation

@nanotaboada
Copy link
Copy Markdown
Owner

@nanotaboada nanotaboada commented Apr 21, 2026

Summary

Follow-up to #479.

  • Unit tests for POST and PUT validation errors now assert the full response payload: ProblemDetails is HttpValidationProblemDetails, Status equals 422, and Errors contains the expected field key and message
  • Stale comment in the integration test updated to reflect that validation failures return 422, not 400
  • CHANGELOG entry split into two sentences to separate the status-code rule from the Problem Details format attribution

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Validation errors now return HTTP 422 (Unprocessable Entity) instead of 400 (Bad Request), aligning with RFC 4918 standards.
    • Error responses follow RFC 9457 Problem Details format, providing detailed validation failure information.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

Warning

Rate limit exceeded

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

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 59 minutes and 21 seconds.

⌛ 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4b719052-4521-4de0-82f7-584013e6d29b

📥 Commits

Reviewing files that changed from the base of the PR and between ccccedc and 4780e84.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • test/Dotnet.Samples.AspNetCore.WebApi.Tests/Integration/PlayerWebApplicationTests.cs
  • test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerControllerTests.cs

Walkthrough

Updated CHANGELOG and test files to document and validate that field validation failures return HTTP 422 Unprocessable Entity with RFC 9457 Problem Details format instead of 400 Bad Request. The changes clarify response behavior and enhance test assertions to verify proper error payload structure.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md
Updated unreleased changelog entry to explicitly state validation errors return RFC 9457 Problem Details format with 422 status code.
Integration Tests
test/Dotnet.Samples.AspNetCore.WebApi.Tests/Integration/PlayerWebApplicationTests.cs
Updated test method documentation to reflect that BeUniqueSquadNumber validation now yields 422 Unprocessable Entity instead of 400 Bad Request.
Unit Tests
test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerControllerTests.cs
Enhanced validation error test cases to assert ProblemHttpResult.ProblemDetails is an HttpValidationProblemDetails with status 422 and Errors containing expected SquadNumber validation message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #479: Directly aligns with code changes that adopt 422 for validation failures with ProblemDetails format across controller and middleware.
  • PR #420: Modifies player controller validation error handling and tests to return RFC-style ProblemDetails with matching assertion updates.
  • PR #464: Updates integration and unit test expectations to validate RFC 9457 Problem Details with HTTP 422 for validation failures.
🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding payload assertions to validation error tests, uses Conventional Commits format (test:), is well under 80 characters (70), and is descriptive and specific.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/469-validation-error-payload-assertions
  • 🛠️ sync documentation: Commit on current branch
  • 🛠️ sync documentation: Create PR
  • 🛠️ enforce http error handling: Commit on current branch
  • 🛠️ enforce http error handling: Create PR
  • 🛠️ idiomatic review: Commit on current branch
  • 🛠️ idiomatic review: Create PR
  • 🛠️ verify api contract: Commit on current branch
  • 🛠️ verify api contract: Create PR

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

@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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Line 49: Changelog entry incorrectly lists "wrong Content-Type" under 400 Bad
Request; update the sentence so 400 remains for malformed requests (unparseable
JSON, route/body mismatch) and move any mention of unsupported media types to
415 Unsupported Media Type (per RFC 9110 §15.5.16) — reference the controller
attribute [Consumes(MediaTypeNames.Application.Json)] to justify that
unsupported media types are handled as 415, and keep the rest of the sentence
about field validation returning 422 Unprocessable Entity and error responses
following Problem Details (RFC 9457).
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c704595e-e3df-4bee-81df-0888f7cf619e

📥 Commits

Reviewing files that changed from the base of the PR and between da5313b and ccccedc.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • test/Dotnet.Samples.AspNetCore.WebApi.Tests/Integration/PlayerWebApplicationTests.cs
  • test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerControllerTests.cs

Comment thread CHANGELOG.md Outdated
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@nanotaboada nanotaboada force-pushed the test/469-validation-error-payload-assertions branch from ccccedc to 4780e84 Compare April 21, 2026 02:01
@sonarqubecloud
Copy link
Copy Markdown

@nanotaboada nanotaboada merged commit 4a20ef3 into master Apr 21, 2026
9 checks passed
@nanotaboada nanotaboada deleted the test/469-validation-error-payload-assertions branch April 21, 2026 03:28
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.

1 participant