Skip to content

test(common): Add unit tests for HttpErrorByCode#17068

Closed
Se3do wants to merge 1 commit into
nestjs:masterfrom
Se3do:test/http-error-by-code
Closed

test(common): Add unit tests for HttpErrorByCode#17068
Se3do wants to merge 1 commit into
nestjs:masterfrom
Se3do:test/http-error-by-code

Conversation

@Se3do
Copy link
Copy Markdown
Contributor

@Se3do Se3do commented Jun 1, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe: Add unit test coverage for HttpErrorByCode utility

What is the current behavior?

HttpErrorByCode has no unit tests. This utility maps 19 HTTP status codes
to their corresponding exception classes (e.g. 400BadRequestException).
It is used by 8 built-in pipes (validation, parse-int, parse-uuid, parse-float,
parse-enum, parse-date, parse-bool, parse-file) to throw the correct HTTP
exception on validation failure. A wrong mapping silently causes all these
pipes to throw the wrong exception across every NestJS application.

Issue Number: N/A

What is the new behavior?

Adds packages/common/test/utils/http-error-by-code.util.spec.ts covering:

  • Each of the 19 status codes maps to the correct exception class
    (verified by reference equality)
  • Total entry count is exactly 19 (catches silent additions or deletions)
  • Each exception class is constructible (imports resolve at runtime)

Follows the same testCases.forEach data-driven pattern used in
http.exception.spec.ts.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This change only adds test coverage and does not modify runtime behavior.

Copilot AI review requested due to automatic review settings June 1, 2026 13:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new unit test suite to validate that HttpErrorByCode maps HTTP status codes to the expected exception classes.

Changes:

  • Introduces a HttpErrorByCode spec verifying mapping correctness across a set of status codes.
  • Adds assertions to ensure the mapping has no extra entries beyond the tested cases.
  • Adds a constructibility check for each mapped exception.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/common/test/utils/http-error-by-code.util.spec.ts Outdated
Comment thread packages/common/test/utils/http-error-by-code.util.spec.ts Outdated
Comment thread packages/common/test/utils/http-error-by-code.util.spec.ts Outdated
@Se3do Se3do force-pushed the test/http-error-by-code branch from c566eb1 to 876c8a4 Compare June 1, 2026 13:53
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 374024

Coverage remained the same at 90.028%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 8624
Covered Lines: 7764
Line Coverage: 90.03%
Relevant Branches: 2943
Covered Branches: 2386
Branch Coverage: 81.07%
Branches in Coverage %: No
Coverage Strength: 56.73 hits per line

💛 - Coveralls

@kamilmysliwiec
Copy link
Copy Markdown
Member

doesn't look like something we'd need a unit test for

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.

4 participants