-
Notifications
You must be signed in to change notification settings - Fork 0
Add feature test for retrieving public posts by other users #347
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
Add feature test for retrieving public posts by other users #347
Conversation
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
- Verified that the endpoint is correctly routed using
str_replace('{userId}', ...)
. - Ensured that public posts are filtered based on visibility (visibility = 0).
- Pagination assertions are correctly scoped to the first page (default behaviour).
- Data generation covers multiple users to prevent false positives from self-posts.
- The database is refreshed before and after each test run.
- The test is isolated and repeatable.
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 adds an endpoint and feature test for fetching public posts created by users other than the requester, and updates the internal services/DTOs to support the new response shape and pagination metadata.
- Introduce
GET /api/users/{userId}/posts/public
route. - Add
GetOthersUserPostsTest
to verify pagination and filtering. - Adjust query service, use case, and DTOs to map entities and include full pagination data.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
src/routes/api.php | Added public route for other users’ posts. |
src/app/Post/Tests/GetOthersUserPostsTest.php | New feature test for pagination and filtering of public posts. |
src/app/Post/Infrastructure/QueryService/GetPostQueryService.php | Updated paginationDto mapping to use GetUserEachPostDto . |
src/app/Post/Application/UseCase/GetOthersAllPostsUseCase.php | Enhanced pagination DTO with additional metadata fields. |
src/app/Post/Application/Dto/GetUserEachPostDto.php | Added buildFromEntity constructor for entity-to-DTO mapping. |
src/app/Post/Application/Dto/GetAllUserPostDtoCollection.php | Refactored collection builder to work with entity-based DTOs. |
Comments suppressed due to low confidence (2)
src/app/Post/Tests/GetOthersUserPostsTest.php:80
- [nitpick] The test method name
test_feature_api
is too generic. Rename it to something more descriptive liketest_retrieve_public_posts_by_other_users_paginates_properly
to clarify its intent.
public function test_feature_api(): void
src/app/Post/Tests/GetOthersUserPostsTest.php:86
- Add assertions to verify that each returned post has
userId != $this->userId
and thatvisibility
is public to ensure correct filtering logic.
$data = $response->json('data');
]); | ||
$this->userId = $user->id; | ||
|
||
$this->createDummyPosts($user->id); |
Copilot
AI
Jul 7, 2025
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.
The method createDummyPosts
is defined without parameters but called with $user->id
, causing an argument mismatch. Update the method signature to accept the excluded userId and pass it through.
Copilot uses AI. Check for mistakes.
private function createDummyPosts(): void | ||
{ | ||
for ($userIndex = 1; $userIndex <= 3; $userIndex++) { | ||
if ($userIndex === 1) { | ||
continue; | ||
} | ||
|
Copilot
AI
Jul 7, 2025
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.
Hardcoding userIndex === 1
won’t reliably skip the requesting user's posts when their ID isn’t 1. Use the passed excludedUserId to conditionally skip based on actual user IDs.
private function createDummyPosts(): void | |
{ | |
for ($userIndex = 1; $userIndex <= 3; $userIndex++) { | |
if ($userIndex === 1) { | |
continue; | |
} | |
private function createDummyPosts(int $excludedUserId): void | |
{ | |
for ($userIndex = 1; $userIndex <= 3; $userIndex++) { |
Copilot uses AI. Check for mistakes.
$user = User::create([ | ||
'first_name' => 'Cristiano', | ||
'last_name' => 'Ronaldo', | ||
'email' => '[email protected]', | ||
'password' => 'test1234', |
Copilot
AI
Jul 7, 2025
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.
[nitpick] Consider using Laravel model factories (e.g. User::factory()
) to create test users and posts—this reduces boilerplate and follows testing best practices.
$user = User::create([ | |
'first_name' => 'Cristiano', | |
'last_name' => 'Ronaldo', | |
'email' => '[email protected]', | |
'password' => 'test1234', | |
$user = User::factory()->create([ | |
'first_name' => 'Cristiano', | |
'last_name' => 'Ronaldo', | |
'email' => '[email protected]', | |
'password' => bcrypt('test1234'), |
Copilot uses AI. Check for mistakes.
Description
This pull request introduces a feature test to validate the API endpoint responsible for retrieving public posts created by users other than the requester.