Skip to content

Conversation

zigzagdev
Copy link
Owner

Description

This PR corrects and improves the feature test for the post update endpoint (PUT /api/users/{userId}/posts/{postId}).
The previous implementation failed due to a mismatch between the expected response structure and the actual API behaviour, particularly concerning the visibility field.

@zigzagdev zigzagdev requested a review from Copilot July 8, 2025 11:09
Copy link
Owner Author

@zigzagdev zigzagdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self Review

  • Confirmed that PostVisibility enum requires an int, not string, for casting
  • Test request now passes the proper visibility value via PostVisibility::PRIVATE->value or similar
  • Response assertions adjusted to match actual return format (string or int, depending on API design)
  • Verified test passes and updates are reflected correctly
  • Ensured that the test fails properly when invalid data is submitted (edge case ready)

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aligns the feature test for the post-update API endpoint with the actual behavior by standardizing visibility handling via PostVisibilityEnum, adjusting variable naming, and correcting route/controller parameters.

  • Standardize visibility request and response using PostVisibilityEnum
  • Rename test variables to camelCase and import the enum in creation tests
  • Refine edit route signature and visibility mapping in the domain/entity layer

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/routes/api.php Simplified the PUT route to /{postId} and updated route name
src/app/Post/Tests/Post_EditTest.php Renamed vars, switched visibility to enum ->value, updated URL
src/app/Post/Tests/Post_CreateTest.php Imported PostVisibilityEnum and switched visibility to ->value
src/app/Post/Presentation/Controller/PostController.php Updated edit signature to camelCase params
src/app/Post/Infrastructure/Repository/PostRepository.php Added user_id fill on edit
src/app/Post/Domain/Entity/PostEntity.php Fixed visibility mapping in build()
src/app/Common/Domain/Enum/PostVisibility.php Lowercased enum toLabel() outputs
src/app/Post/Application/UseCase/EditUseCase.php Formatting adjustment
Comments suppressed due to low confidence (2)

src/routes/api.php:23

  • The edit route no longer includes the {userId} segment, but tests and the controller still expect it. Either restore the '{userId}/posts/{postId}' path or update tests and controller to match the new '/api/users/{postId}' pattern.
        Route::put('{postId}', [PostController::class, 'edit'])->name('edit');

src/app/Post/Infrastructure/Repository/PostRepository.php:42

  • Including 'user_id' in the update payload will overwrite the post's original owner on edits. Remove this field from editById to preserve post ownership.
            'user_id' => $entity->getUserId()->getValue(),

Comment on lines +127 to 132
int $userId,
int $postId,
EditUseCase $useCase
): JsonResponse {
DB::connection('mysql')->beginTransaction();
try {
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The controller's edit method expects both $userId and $postId parameters, but the route only supplies {postId}. Update the signature to accept just $postId or adjust the route to provide both parameters.

Suggested change
int $userId,
int $postId,
EditUseCase $useCase
): JsonResponse {
DB::connection('mysql')->beginTransaction();
try {
int $postId,
EditUseCase $useCase
): JsonResponse {
DB::connection('mysql')->beginTransaction();
try {
$userId = auth()->id(); // Retrieve the authenticated user's ID

Copilot uses AI. Check for mistakes.

@zigzagdev zigzagdev linked an issue Jul 8, 2025 that may be closed by this pull request
@zigzagdev zigzagdev self-assigned this Jul 8, 2025
@zigzagdev zigzagdev merged commit 04a553a into feature/fix-post-api-tests Jul 8, 2025
@zigzagdev zigzagdev deleted the feature/fix-post-api-test-edit branch July 8, 2025 11:19
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.

Post Edit Test

1 participant