-
Notifications
You must be signed in to change notification settings - Fork 0
Fix and refactor multiple feature tests for Posts API #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix and refactor feature test for creating posts
Fix and refine feature test for updating a post via API
…all_user_posts Fix and refactor feature test for retrieving all user posts via API
There was a problem hiding this 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
There was a problem hiding this 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 usePostVisibilityEnum
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
ineditById
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(),
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