Skip to content

Conversation

zigzagdev
Copy link
Owner

Description

This PR addresses various corrections and structural improvements across multiple feature tests related to the Posts module.
The modifications ensure alignment with domain enum definitions, strengthen data consistency, and improve assertion accuracy.

Updated Tests:

  • Post_CreateTest
  • Post_EditTest
  • GetAllUserPostsTest

@zigzagdev zigzagdev requested a review from Copilot July 9, 2025 10:18
@zigzagdev zigzagdev self-assigned this Jul 9, 2025
@zigzagdev zigzagdev added bug Something isn't working test refactor labels Jul 9, 2025
@zigzagdev zigzagdev linked an issue Jul 9, 2025 that may be closed by this pull request
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

  • Enum handling is now strictly value-based and domain-driven
  • Visibility-related assertions reflect correct enum outputs (int or string depending on use case)
  • Test data creation is predictable, readable, and suitable for pagination edge cases
  • Route and payload structures are validated against expected API contract
  • No remaining hardcoded or ambiguous values present in test logic

@zigzagdev zigzagdev merged commit d6b6bfc into main Jul 9, 2025
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 refactors the Posts API feature tests and related domain code to ensure consistency with the PostVisibilityEnum, standardize naming, and realign the edit endpoint behavior.

  • Updates the edit route and controller parameters to camelCase and simplifies the endpoint path.
  • Refactors feature tests (Post_CreateTest, Post_EditTest, GetAllUserPostsTest) to use PostVisibilityEnum values and clearer variable names.
  • Enhances domain logic in entity factories, repository methods, and use cases for robust visibility handling and ownership updates.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/routes/api.php Simplified edit route pattern to /{postId}
src/app/Post/Tests/Post_EditTest.php Renamed variables ($userId, $postId) and aligned visibility with enum labels
src/app/Post/Tests/Post_CreateTest.php Added import for PostVisibilityEnum and renamed test method
src/app/Post/Tests/GetAllUserPostsTest.php Updated dummy post visibility to use PostVisibilityEnum values
src/app/Post/Presentation/Controller/PostController.php Renamed route method parameters to camelCase and imported edit use case
src/app/Post/Infrastructure/Repository/PostRepository.php Enabled updating user_id in editById
src/app/Post/Domain/EntityFactory/PostFromModelEntityFactory.php Cast visibility input to int before enum conversion
src/app/Post/Domain/Entity/PostEntity.php Improved visibility parsing for numeric and string inputs
src/app/Post/Application/UseCase/GetAllUserPostUseCase.php Removed manual DTO mapping and now returns raw pagination
src/app/Common/Domain/Enum/PostVisibility.php Changed toLabel() outputs from capitalized to lowercase
Comments suppressed due to low confidence (4)

src/app/Post/Tests/Post_CreateTest.php:35

  • [nitpick] The @testdox docblock was removed in favor of a generic method name. Consider adding a descriptive annotation or more specific method name to improve test readability.
    public function test_create_post(): void

src/routes/api.php:23

  • The edit route no longer includes {userId}, but tests and the controller still expect a userId segment in the URL. Restore the {userId}/posts/{postId} pattern or update tests and controller to match the new endpoint.
        Route::put('{postId}', [PostController::class, 'edit'])->name('edit');

src/app/Post/Presentation/Controller/PostController.php:127

  • The controller's edit signature expects a $userId parameter, but the route no longer provides it. Either remove this parameter or restore it in the route definition to avoid runtime errors.
        int $userId,

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

  • [nitpick] Updating user_id in editById may unintentionally allow changing a post's owner. Confirm if ownership changes are intended or remove this field from the update payload.
            'user_id' => $entity->getUserId()->getValue(),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working refactor test

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Fix Posts Feature Tests

1 participant