Skip to content

test(middleware): cover validation middleware error shape and nested schema contracts - #2213

Open
DeepDev69x3 wants to merge 1 commit into
LabsCrypt:mainfrom
DeepDev69x3:test/validation-middleware-error-shape-2095
Open

DeepDev69x3 wants to merge 1 commit into
LabsCrypt:mainfrom
DeepDev69x3:test/validation-middleware-error-shape-2095

Conversation

@DeepDev69x3

Copy link
Copy Markdown

Summary of Changes

Closes #2095

Adds comprehensive deterministic unit and integration test coverage for Express request validation middleware in backend/src/middleware/validation.ts, ensuring robust handling of nested schemas, boundary inputs, and consistent 400 response contracts when passed through centralized errorHandler.

Detailed Test Coverage

  1. validateBody:

    • Verified clean execution and invocation of next() with no arguments on valid payloads.
    • Verified rejection of missing required fields, capturing z.ZodError.
    • Verified deeply nested schema failures (e.g. nested.details.verified) emitting correct dot-delimited error paths.
    • Verified indexed array element error paths (e.g. tags.1) in structured payloads.
    • Handled boundary inputs (e.g. undefined / empty body) safely without throwing uncaught exceptions.
  2. validateQuery & validateParams:

    • Verified string regex matching for pagination parameters (page, limit) and enum validation for query filters.
    • Verified route parameter validation for UUID format invariants (loanId).
  3. validate & createSchema Helpers:

    • Verified combined validation across body, query, and params simultaneously.
    • Verified isolated schema generators (createSchema.body, createSchema.query, createSchema.params).
  4. Integration with errorHandler (Consistent 400 Contract):

    • Verified HTTP 400 status code on validation errors.
    • Verified legacy format backward compatibility (success: false, message: 'Validation failed', errors: [{ path, message }]`).
    • Verified structured error contract (error.code === 'VALIDATION_ERROR', error.fieldset to first failing field, anderror.detailscontaining complete{ field, message, code }` objects).

Verification

  • npm test -- src/middleware/__tests__/validation.test.ts: 15/15 tests passed (100% green).
  • npm test: 126/126 test suites passed, 1087/1087 tests passed (0 failed).
  • npm run build: tsc -p tsconfig.build.json succeeded with 0 errors.

@github-actions github-actions Bot added the security:malware-suspected Automated malware indicator found in a pull request label Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Malware detection scan flagged this pull request

The scan found 1 indicator(s) in the PR diff. This PR is blocked until a maintainer reviews the flagged files.

  • backend/src/middleware/__tests__/validation.test.ts — hidden-appended-config-payload (high)

This is an automated triage signal; maintainers must verify whether the finding is malicious or intentional.

This branch has not been deployed

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

Labels

security:malware-suspected Automated malware indicator found in a pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[test] Cover validation middleware error shape

1 participant