fix: refactored the codebase

This commit is contained in:
2026-08-20 23:00:47 +02:00
parent 6f47ed0674
commit a77f74911d
64 changed files with 2864 additions and 1739 deletions
+77
View File
@@ -0,0 +1,77 @@
<?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));
});
+42
View File
@@ -171,6 +171,48 @@ test('an authenticated player can restore room access without the previous sessi
->assertSessionHas("room_players.{$room->id}", $moderator->id);
});
test('an active guest with a room session skips the join form', function () {
$room = createLifecycleRoom();
$player = $room->players()->create([
'name' => 'Guest',
'last_seen_at' => now(),
]);
$this->withSession(["room_players.{$room->id}" => $player->id])
->get(route('room.join', ['join_code' => $room->join_code]))
->assertRedirect(route('room.show', $room));
});
test('an inactive guest is sent through join and reuses the existing player', function () {
$room = createLifecycleRoom();
$player = $room->players()->create([
'name' => 'Returning guest',
'last_seen_at' => now()->subHours(2),
'inactive_at' => now()->subHour(),
]);
$session = ["room_players.{$room->id}" => $player->id];
$this->withSession($session)
->get(route('room.show', $room))
->assertRedirect(route('room.join', ['join_code' => $room->join_code]));
$this->withSession($session)
->get(route('room.join', ['join_code' => $room->join_code]))
->assertInertia(fn (Assert $page) => $page
->component('rooms/Join')
->where('defaultPlayerName', 'Returning guest'));
$this->withSession($session)
->post(route('room.code'), [
'join_code' => $room->join_code,
'player_name' => 'Returning guest',
])
->assertRedirect(route('room.show', $room));
expect($room->players()->count())->toBe(1)
->and($player->fresh()->inactive_at)->toBeNull();
});
test('showing or polling a room does not count as room activity', function () {
$room = createLifecycleRoom(['last_activity_at' => now()->subDays(5)]);
$moderator = $room->players()->create([