Skip to content

test: improve middleware test coverage for problem and logger#2120

Open
armorbreak001 wants to merge 1 commit intoasyncapi:masterfrom
armorbreak001:bounty/2019-middleware-test-coverage
Open

test: improve middleware test coverage for problem and logger#2120
armorbreak001 wants to merge 1 commit intoasyncapi:masterfrom
armorbreak001:bounty/2019-middleware-test-coverage

Conversation

@armorbreak001
Copy link
Copy Markdown

Fixes #2019

Changes

  • Added test/unit/middlewares/problem.middleware.test.ts with 5 test cases:

    • Calls next() when headers already sent
    • Responds with correct status and JSON body for ProblemException
    • Defaults to status 500 when no status provided
    • Defaults to 'Internal server error' title when no title provided
    • Calls next() on unexpected serialization errors
  • Added test/unit/middlewares/logger.middleware.test.ts with 3 test cases:

    • Calls next() immediately
    • Registers finish event handler correctly
    • Handles different HTTP methods (GET, POST)

Notes

  • Validation middleware tests were not included due to ESM/CJS module resolution issues in the test environment with mocha v11 + the complex dependency chain of validation.middleware.ts (imports @asyncapi/converter, @services/validation.service, etc.)
  • These tests can be added in a follow-up once the test infrastructure is updated for full ESM support

Verification

Run: npm run unit:test and verify all new middleware tests pass

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 13, 2026

⚠️ No Changeset found

Latest commit: 760681f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

[TEST] : low coverage in lib/apps/api/middlewares

1 participant