Skip to content

Conversation

zigzagdev
Copy link
Owner

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.

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

  • 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.

@zigzagdev zigzagdev requested a review from Copilot July 7, 2025 10:01
@zigzagdev zigzagdev self-assigned this Jul 7, 2025
@zigzagdev zigzagdev linked an issue Jul 7, 2025 that may be closed by this pull request
@zigzagdev zigzagdev merged commit 64fa14d into feature/see-other-posts Jul 7, 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 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 like test_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 that visibility is public to ensure correct filtering logic.
        $data = $response->json('data');

]);
$this->userId = $user->id;

$this->createDummyPosts($user->id);
Copy link

Copilot AI Jul 7, 2025

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.

Comment on lines +50 to +56
private function createDummyPosts(): void
{
for ($userIndex = 1; $userIndex <= 3; $userIndex++) {
if ($userIndex === 1) {
continue;
}

Copy link

Copilot AI Jul 7, 2025

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.

Suggested change
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.

Comment on lines +19 to +23
$user = User::create([
'first_name' => 'Cristiano',
'last_name' => 'Ronaldo',
'email' => '[email protected]',
'password' => 'test1234',
Copy link

Copilot AI Jul 7, 2025

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.

Suggested change
$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.

@zigzagdev zigzagdev deleted the feature/see-other-posts-test branch July 7, 2025 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

See Other Posts Feature Test

1 participant