Files
scrum-poker-internal/tests/Feature/RoomFavoritesTest.php
2026-08-20 23:00:47 +02:00

78 lines
2.4 KiB
PHP

<?php
use App\Models\Room;
use App\Models\User;
use Inertia\Testing\AssertableInertia as Assert;
test('favorited rooms are presented on the dashboard with player counts', function () {
$owner = User::factory()->create();
$user = User::factory()->create();
$room = Room::create([
'owner_id' => $owner->id,
'title' => 'Favorite planning',
'deck_config' => [
'name' => 'Fibonacci',
'cards' => [['key' => '3', 'label' => '3']],
],
]);
$room->players()->create([
'name' => 'Active player',
'last_seen_at' => now(),
]);
$room->players()->create([
'name' => 'Inactive player',
'last_seen_at' => now()->subHour(),
'inactive_at' => now(),
]);
$this->actingAs($user)
->post(route('room.favorite', $room))
->assertRedirect();
$this->assertDatabaseHas('user_room_favorites', [
'user_id' => $user->id,
'room_id' => $room->id,
]);
$this->get(route('dashboard'))
->assertInertia(fn (Assert $page) => $page
->has('favoriteRooms', 1)
->where('favoriteRooms.0.id', $room->id)
->where('favoriteRooms.0.players_count', 2)
->where('favoriteRooms.0.active_player_count', 1));
});
test('the room resource exposes favorite and owner state', function () {
$owner = User::factory()->create();
$user = User::factory()->create();
$room = Room::create([
'owner_id' => $owner->id,
'title' => 'Resource planning',
'deck_config' => [
'name' => 'Fibonacci',
'cards' => [['key' => '3', 'label' => '3']],
],
]);
$ownerPlayer = $room->players()->create([
'user_id' => $owner->id,
'name' => 'Owner',
'is_moderator' => true,
]);
$currentPlayer = $room->players()->create([
'user_id' => $user->id,
'name' => 'Participant',
]);
$user->favoriteRooms()->attach($room);
$this->actingAs($user)
->withSession(["room_players.{$room->id}" => $currentPlayer->id])
->get(route('room.show', $room))
->assertInertia(fn (Assert $page) => $page
->where('room.is_favorite', true)
->where('room.owner_id', $owner->id)
->where('room.players.0.id', $ownerPlayer->id)
->where('room.players.0.is_owner', true)
->where('currentPlayer.id', $currentPlayer->id));
});