create(['xp' => 100, 'username' => 'User1']); $user2 = User::factory()->create(['xp' => 300, 'username' => 'User2']); $user3 = User::factory()->create(['xp' => 200, 'username' => 'User3']); // Authenticate as one of the users $this->actingAs($user1); // Call the endpoint $response = $this->getJson('/api/users/leaderboard'); // Assert response status $response->assertOk(); // Assert the order of users in the response $response->assertJson(fn ($json) => $json->has(3) ->where('0.id', $user2->id) // 300 XP ->where('1.id', $user3->id) // 200 XP ->where('2.id', $user1->id) // 100 XP ); });