feat(posts): DTO validation, pagination enforcement, Swagger docs, e2… - #1319
Merged
aji70 merged 1 commit intoJun 28, 2026
Merged
Conversation
…e tests Closes MyFanss#1000, MyFanss#1001, MyFanss#1002, MyFanss#1004 ## What was done ### MyFanss#1000 – DTO validation tests for invalid input Added class-validator decorators (@isnotempty, @IsString, @minlength, @maxlength, @isboolean, @IsOptional) to CreatePostDto and UpdatePostDto in post.dto.ts so the ValidationPipe can enforce them at runtime. Created post.dto.spec.ts with unit tests covering: missing required fields, empty strings, boundary lengths (500/10000 chars), non-string titles, non-boolean flags, and optional-field absence for both DTOs. ### MyFanss#1001 – e2e test for primary endpoint Created test/posts.e2e-spec.ts bootstrapping the full AppModule with ValidationPipe and URI versioning. Covers: GET /v1/posts returns 200 with paginated shape, page/limit query params, 400 on limit > 100 or page < 1, POST /v1/posts 400 responses for missing/empty/oversized title, missing content, and non-boolean isPublished, and GET /v1/posts/author/:authorId returns 200 with pagination support. ### MyFanss#1002 – Pagination / limit query support The PaginationDto (shared common DTO) already carried @IsInt/@Min/@max validators and the service already applied skip/take. Adding the class-validator decorators to CreatePostDto/UpdatePostDto completes the input-validation layer so the ValidationPipe rejects malformed requests (400) before they reach the service, making the pagination contract enforceable end-to-end. ### MyFanss#1004 – Swagger / OpenAPI documentation The controller already carried @apitags, @apioperation, @apiresponse, @ApiBody, @ApiParam, @apiquery decorators. Added minLength/maxLength constraints to the @ApiProperty/@ApiPropertyOptional metadata on CreatePostDto and UpdatePostDto to keep the OpenAPI schema in sync with the class-validator rules, so the generated spec accurately reflects the accepted input ranges.
|
@Creed1759 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…e tests
Closes #1000 , Closes #1001 , Closes #1002, Closes #1004
What was done
#1000 – DTO validation tests for invalid input Added class-validator decorators (@isnotempty, @IsString, @minlength, @maxlength, @isboolean, @IsOptional) to CreatePostDto and UpdatePostDto in post.dto.ts so the ValidationPipe can enforce them at runtime. Created post.dto.spec.ts with unit tests covering: missing required fields, empty strings, boundary lengths (500/10000 chars), non-string titles, non-boolean flags, and optional-field absence for both DTOs.
#1001 – e2e test for primary endpoint
Created test/posts.e2e-spec.ts bootstrapping the full AppModule with ValidationPipe and URI versioning. Covers: GET /v1/posts returns 200 with paginated shape, page/limit query params, 400 on limit > 100 or page < 1, POST /v1/posts 400 responses for missing/empty/oversized title, missing content, and non-boolean isPublished, and GET /v1/posts/author/:authorId returns 200 with pagination support.
#1002 – Pagination / limit query support
The PaginationDto (shared common DTO) already carried @IsInt/@Min/@max validators and the service already applied skip/take. Adding the class-validator decorators to CreatePostDto/UpdatePostDto completes the input-validation layer so the ValidationPipe rejects malformed requests (400) before they reach the service, making the pagination contract enforceable end-to-end.
#1004 – Swagger / OpenAPI documentation
The controller already carried @apitags, @apioperation, @apiresponse, @ApiBody, @ApiParam, @apiquery decorators. Added minLength/maxLength constraints to the @ApiProperty/@ApiPropertyOptional metadata on CreatePostDto and UpdatePostDto to keep the OpenAPI schema in sync with the class-validator rules, so the generated spec accurately reflects the accepted input ranges.