mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-14 20:15:28 +00:00
Handle authenticated room instance takeover
This commit is contained in:
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user