app->make(PostRepositoryInterface::class); } #[Test] public function authored_activity_response_uses_singular_comment_count_key(): void { $user = $this->createUser(); $postId = $this->createTestPost([ 'user_id' => $user->id, 'title' => '내 글', ]); // comments_count DB 컬럼에 직접 값 세팅 (단순 키 매핑 테스트) DB::table('board_posts')->where('id', $postId)->update(['comments_count' => 4]); $paginator = $this->repository()->getUserActivities( $user->id, ['activity_type' => 'authored', 'board_slug' => $this->board->slug], 20 ); $items = $paginator->items(); $this->assertNotEmpty($items, 'authored 활동에 게시글이 1건 이상 있어야 합니다'); $first = $items[0]; $this->assertArrayHasKey('comment_count', $first, 'authored 활동 응답은 단수형 comment_count 키를 사용해야 합니다'); $this->assertArrayNotHasKey('comments_count', $first, 'authored 활동 응답에 복수형 comments_count 키가 노출되어서는 안 됩니다'); $this->assertSame(4, $first['comment_count']); } #[Test] public function commented_activity_response_uses_singular_comment_count_key(): void { $user = $this->createUser(); // 다른 사용자의 글에 댓글을 작성 $otherUser = $this->createUser(); $postId = $this->createTestPost([ 'user_id' => $otherUser->id, 'title' => '다른 사람 글', ]); $this->createTestComment($postId, [ 'user_id' => $user->id, 'content' => '내가 단 댓글', ]); DB::table('board_posts')->where('id', $postId)->update(['comments_count' => 7]); $paginator = $this->repository()->getUserActivities( $user->id, ['activity_type' => 'commented', 'board_slug' => $this->board->slug], 20 ); $items = $paginator->items(); $this->assertNotEmpty($items, 'commented 활동에 게시글이 1건 이상 있어야 합니다'); $first = $items[0]; $this->assertArrayHasKey('comment_count', $first, 'commented 활동 응답은 단수형 comment_count 키를 사용해야 합니다'); $this->assertArrayNotHasKey('comments_count', $first, 'commented 활동 응답에 복수형 comments_count 키가 노출되어서는 안 됩니다'); $this->assertSame(7, $first['comment_count']); } }