Handle authenticated room instance takeover
CI/CD / test_and_check_app (push) Failing after 2m7s
CI/CD / Publish immutable image (push) Skipped

This commit is contained in:
2026-09-10 16:33:13 +02:00
parent 2ab95cebdf
commit 640a2970c3
18 changed files with 351 additions and 22 deletions
+33
View File
@@ -1,11 +1,14 @@
<?php
use App\Enums\RoomStateChange;
use App\Events\RoomStateChanged;
use App\Jobs\CloseInactiveRooms;
use App\Models\Deck;
use App\Models\Room;
use App\Models\User;
use App\Models\Vote;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Event;
use Inertia\Testing\AssertableInertia as Assert;
function createLifecycleRoom(array $attributes = []): Room
@@ -156,6 +159,36 @@ test('an authenticated player rejoins with the existing room identity', function
$response->assertSessionHas("room_players.{$room->id}", $player->id);
});
test('a new account instance takes over the player during a regular room join', function () {
$user = User::factory()->create();
$room = createLifecycleRoom();
$player = $room->players()->create([
'user_id' => $user->id,
'name' => 'Room nickname',
'active_instance_id' => '019b8f80-37c4-71a3-b415-5f2697332c16',
]);
Event::fake([RoomStateChanged::class]);
$this->actingAs($user)
->withSession([
'room_player_instance_id' => '019b8f80-37c4-71a3-b415-5f2697332c17',
])
->post(route('room.code'), [
'join_code' => $room->join_code,
'player_name' => 'Room nickname',
])
->assertRedirect(route('room.show', $room));
expect($player->fresh()->active_instance_id)
->toBe('019b8f80-37c4-71a3-b415-5f2697332c17');
Event::assertDispatched(
RoomStateChanged::class,
fn (RoomStateChanged $event): bool => $event->change === RoomStateChange::PlayerInstanceReplaced
&& $event->affectedPlayerId === $player->id,
);
});
test('an authenticated player can restore room access without the previous session', function () {
$user = User::factory()->create();
$room = createLifecycleRoom(['owner_id' => $user->id]);