https://github.com/alsiola/test-nest-validation
https://github.com/alsiola/test-nest-validation
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/alsiola/test-nest-validation
- Owner: alsiola
- Created: 2021-02-04T20:56:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-04T21:08:26.000Z (over 5 years ago)
- Last Synced: 2025-01-02T20:36:15.802Z (over 1 year ago)
- Language: TypeScript
- Size: 105 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nest Validation Test
Demonstrates an issue with validation using `ValidationPipe`. My expectation is that both e2e tests in this repository should pass, currently one fails.
## Setup
`BodyDTO` has one property (`age`), which is protected by an `@IsNumber` decorator.
A global validation pipe is applied in `main.ts`.
There are two endpoints - `POST /works` and `POST /broken`. They both use the same `@Body`, which is declared and validated to be a `BodyDTO`.
Endpoint `POST /works` additionally passes `ValidationPipe` to the `@Body` decorator - `@Body(ValidationPipe)`
## Expected bahaviour
The validation on these endpoints is identical
## Actual behaviour
A body of `{ age: 'a string' }` fails validation for `/works` (with `ValidationPipe` passed directly to `@Body`), but passes validation for `/broken` (relying on the global validation pipe).