Skip to content

Add test coverage for the 100KiB body limit and 413 error mapping #17

@mikewheeleer

Description

@mikewheeleer

Test the payload-too-large 413 mapping in the error handler

Description

src/index.ts configures express.json({ limit: "100kb" }) and the final error handler maps the resulting entity.too.large error to a 413 payload_too_large body — but no test exercises this path. The generic 500 internal_error branch is likewise uncovered. This issue adds tests for both.

Requirements and context

  • Repository scope: StableRoute-Org/Stableroute-backend only.
  • POST a body exceeding 100 KiB to a JSON route and assert 413 with error: "payload_too_large" and requestId.
  • Add a test that forces the generic error branch (e.g. a route or mock that throws) and asserts the 500 internal_error shape including method and path.
  • Keep tests independent of network and fast.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/error-handling-17-413-500
  • Implement changes
    • Write comprehensive tests in: create src/__tests__/errorHandler.test.ts.
    • Add documentation: none beyond test names.
    • Construct an oversized payload programmatically (e.g. "x".repeat(...)).
    • Validate security: confirm no stack trace leaks in the 413/500 bodies.
  • Test and commit

Test and commit

  • Run npm run build, npm run lint, and npm test.
  • Cover edge cases: exactly-at-limit accepted, over-limit rejected, malformed JSON.
  • Paste full npm test output and a coverage summary in the PR.

Example commit message

test(error-handling): cover 413 payload-too-large and 500 branches

Guidelines

  • Minimum 95 percent test coverage for impacted code.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions