Skip to content

feat(posts): DTO validation, pagination enforcement, Swagger docs, e2e tests#1

Open
Creed1759 wants to merge 1 commit into
mainfrom
feat/posts-dto-validation-pagination-swagger-e2e
Open

feat(posts): DTO validation, pagination enforcement, Swagger docs, e2e tests#1
Creed1759 wants to merge 1 commit into
mainfrom
feat/posts-dto-validation-pagination-swagger-e2e

Conversation

@Creed1759

Copy link
Copy Markdown
Owner

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-validator decorators (@IsNotEmpty, @IsString, @MinLength, @MaxLength, @IsBoolean, @IsOptional) to CreatePostDto and UpdatePostDto so the ValidationPipe can enforce them at runtime.

Created post.dto.spec.ts with unit tests covering:

  • Missing required fields (title, content)
  • Empty strings and boundary lengths (500 / 10000 chars)
  • Non-string title, non-boolean flag values
  • Optional-field absence valid 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 → 200 with correct paginated shape
  • page / limit query params accepted and reflected in response
  • 400 on limit > 100 or page < 1
  • POST /v1/posts → 400 for missing/empty/oversized title, missing content, non-boolean isPublished
  • GET /v1/posts/author/:authorId → 200 with pagination support

MyFanss#1002 – Pagination / limit query support

PaginationDto (shared) already carried @IsInt/@Min/@Max and the service already applied skip/take. Adding class-validator decorators to the post DTOs completes the input-validation layer so the ValidationPipe rejects 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, @ApiQuery decorators. Added minLength/maxLength to the @ApiProperty/@ApiPropertyOptional metadata on CreatePostDto and UpdatePostDto to keep the OpenAPI schema in sync with the class-validator rules.


Files changed

File Change
backend/src/posts/dto/post.dto.ts Added class-validator decorators to CreatePostDto / UpdatePostDto
backend/src/posts/dto/post.dto.spec.ts New — DTO validation unit tests (issue MyFanss#1000)
backend/test/posts.e2e-spec.ts New — e2e tests for posts endpoints (issue MyFanss#1001)

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend Posts: Add DTO validation tests for invalid input

1 participant