feat(posts): DTO validation, pagination enforcement, Swagger docs, e2e tests#1
Open
Creed1759 wants to merge 1 commit into
Open
feat(posts): DTO validation, pagination enforcement, Swagger docs, e2e tests#1Creed1759 wants to merge 1 commit into
Creed1759 wants to merge 1 commit into
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.
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.
Closes MyFanss#1000, MyFanss#1001, MyFanss#1002, MyFanss#1004
Summary
Four issues resolved in one focused changeset across three files.
MyFanss#1000 – DTO validation tests for invalid input
Added
class-validatordecorators (@IsNotEmpty,@IsString,@MinLength,@MaxLength,@IsBoolean,@IsOptional) toCreatePostDtoandUpdatePostDtoso theValidationPipecan enforce them at runtime.Created
post.dto.spec.tswith unit tests covering:title,content)MyFanss#1001 – e2e test for primary endpoint
Created
test/posts.e2e-spec.tsbootstrapping the fullAppModulewithValidationPipeand URI versioning. Covers:GET /v1/posts→ 200 with correct paginated shapepage/limitquery params accepted and reflected in responselimit > 100orpage < 1POST /v1/posts→ 400 for missing/empty/oversized title, missing content, non-booleanisPublishedGET /v1/posts/author/:authorId→ 200 with pagination supportMyFanss#1002 – Pagination / limit query support
PaginationDto(shared) already carried@IsInt/@Min/@Maxand the service already appliedskip/take. Adding class-validator decorators to the post DTOs completes the input-validation layer so theValidationPiperejects malformed requests (400) before they hit the service, making the pagination contract enforceable end-to-end.MyFanss#1004 – Swagger / OpenAPI documentation
The controller already carried full
@ApiTags,@ApiOperation,@ApiResponse,@ApiBody,@ApiParam,@ApiQuerydecorators. AddedminLength/maxLengthto the@ApiProperty/@ApiPropertyOptionalmetadata onCreatePostDtoandUpdatePostDtoto keep the OpenAPI schema in sync with the class-validator rules.Files changed
backend/src/posts/dto/post.dto.tsCreatePostDto/UpdatePostDtobackend/src/posts/dto/post.dto.spec.tsbackend/test/posts.e2e-spec.ts