create(); $category = Forum::create([ 'name' => 'Category', 'description' => null, 'type' => 'category', 'parent_id' => null, 'position' => 1, ]); $forum = Forum::create([ 'name' => 'Forum', 'description' => null, 'type' => 'forum', 'parent_id' => $category->id, 'position' => 1, ]); $thread = Thread::create([ 'forum_id' => $forum->id, 'user_id' => $user->id, 'title' => 'Thread', 'body' => 'Body', ]); Post::create([ 'thread_id' => $thread->id, 'user_id' => $user->id, 'body' => 'Reply', ]); Sanctum::actingAs($user); $response = $this->getJson('/api/portal/summary'); $response->assertOk(); $response->assertJsonStructure(['forums', 'threads', 'stats', 'profile']); $response->assertJsonFragment(['name' => 'Forum']); $response->assertJsonFragment(['title' => 'Thread']); }); it('includes avatar and rank data in portal threads', function (): void { $rank = Rank::create([ 'name' => 'Gold', 'badge_type' => 'image', 'badge_image_path' => 'ranks/gold.png', ]); $role = Role::create(['name' => 'ROLE_SPECIAL', 'color' => '#ff0000']); $user = User::factory()->create([ 'avatar_path' => 'avatars/u.png', 'rank_id' => $rank->id, ]); $user->roles()->attach($role); $category = Forum::create([ 'name' => 'Category', 'description' => null, 'type' => 'category', 'parent_id' => null, 'position' => 1, ]); $forum = Forum::create([ 'name' => 'Forum', 'description' => null, 'type' => 'forum', 'parent_id' => $category->id, 'position' => 1, ]); $thread = Thread::create([ 'forum_id' => $forum->id, 'user_id' => $user->id, 'title' => 'Thread', 'body' => 'Body', ]); Sanctum::actingAs($user); $response = $this->getJson('/api/portal/summary'); $response->assertOk(); $payload = $response->getData(true); expect($payload['threads'][0]['user_avatar_url'])->not->toBeNull(); expect($payload['threads'][0]['user_rank_badge_url'])->not->toBeNull(); expect($payload['threads'][0]['user_group_color'])->toBe('#ff0000'); }); it('handles empty forum last posts and resolveGroupColor', function (): void { $user = User::factory()->create(); $user->setRelation('roles', null); $category = Forum::create([ 'name' => 'Category2', 'description' => null, 'type' => 'category', 'parent_id' => null, 'position' => 1, ]); $forum = Forum::create([ 'name' => 'Forum2', 'description' => null, 'type' => 'forum', 'parent_id' => $category->id, 'position' => 1, ]); Sanctum::actingAs($user); $response = $this->getJson('/api/portal/summary'); $response->assertOk(); $payload = $response->getData(true); expect($payload['forums'][0]['last_post_user_group_color'])->toBeNull(); }); it('handles summary when no forums exist', function (): void { $user = User::factory()->create(); Sanctum::actingAs($user); $response = $this->getJson('/api/portal/summary'); $response->assertOk(); $payload = $response->getData(true); expect($payload['forums'])->toBe([]); });