mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 17:12:08 +00:00
do not need login
This commit is contained in:
@@ -19,22 +19,43 @@ function createEmbeddedRoom(array $attributes = []): Room
|
||||
]);
|
||||
}
|
||||
|
||||
test('embedded room access sends guests through login and remembers the intended room', function () {
|
||||
test('a guest automatically joins the embedded room', function () {
|
||||
$room = createEmbeddedRoom();
|
||||
$url = route('embedded.room', [
|
||||
'join_code' => $room->join_code,
|
||||
'player_name' => 'Nico',
|
||||
$response = $this->get(route('embedded.room', [
|
||||
'join_code' => strtolower($room->join_code),
|
||||
'player_name' => ' Nico ',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('embedded/Room')
|
||||
->where('room.id', $room->id)
|
||||
->where('currentPlayer.name', 'Nico'));
|
||||
|
||||
$player = $room->players()->sole();
|
||||
|
||||
expect($player->user_id)->toBeNull()
|
||||
->and($player->is_moderator)->toBeFalse();
|
||||
|
||||
$response->assertSessionHas("room_players.{$room->id}", $player->id);
|
||||
});
|
||||
|
||||
test('embedded guest access reuses the session player and applies a changed display name', function () {
|
||||
$room = createEmbeddedRoom();
|
||||
$player = $room->players()->create([
|
||||
'name' => 'Old name',
|
||||
'inactive_at' => now(),
|
||||
]);
|
||||
|
||||
$this->get($url)
|
||||
->assertRedirect(route('login'))
|
||||
->assertSessionHas('embedded_login', true)
|
||||
->assertSessionHas('url.intended', $url);
|
||||
$this->withSession(["room_players.{$room->id}" => $player->id])
|
||||
->get(route('embedded.room', [
|
||||
'join_code' => $room->join_code,
|
||||
'player_name' => 'New name',
|
||||
]))
|
||||
->assertOk();
|
||||
|
||||
$this->get(route('login'))
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('auth/Login')
|
||||
->where('rememberByDefault', true));
|
||||
expect($room->players()->count())->toBe(1)
|
||||
->and($player->fresh()->name)->toBe('New name')
|
||||
->and($player->fresh()->inactive_at)->toBeNull();
|
||||
});
|
||||
|
||||
test('an authenticated user automatically joins the embedded room', function () {
|
||||
@@ -83,16 +104,39 @@ test('embedded access reuses the user player and applies a changed display name'
|
||||
->and($player->fresh()->inactive_at)->toBeNull();
|
||||
});
|
||||
|
||||
test('embedded access shows a dedicated error when the display name is taken', function () {
|
||||
$user = User::factory()->create();
|
||||
test('an embedded guest keeps the same player after logging in separately', function () {
|
||||
$user = User::factory()->create([
|
||||
'email' => 'nico@example.com',
|
||||
]);
|
||||
$room = createEmbeddedRoom();
|
||||
$url = route('embedded.room', [
|
||||
'join_code' => $room->join_code,
|
||||
'player_name' => 'Nico',
|
||||
]);
|
||||
|
||||
$this->get($url)->assertOk();
|
||||
|
||||
$player = $room->players()->sole();
|
||||
|
||||
$this->post(route('login.store'), [
|
||||
'email' => 'nico@example.com',
|
||||
'password' => 'password',
|
||||
])->assertRedirect();
|
||||
|
||||
$this->get($url)->assertOk();
|
||||
|
||||
expect($room->players()->count())->toBe(1)
|
||||
->and($player->fresh()->user_id)->toBe($user->id);
|
||||
});
|
||||
|
||||
test('embedded guest access shows a dedicated error when the display name is taken', function () {
|
||||
$room = createEmbeddedRoom();
|
||||
$room->players()->create(['name' => 'Nico']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('embedded.room', [
|
||||
'join_code' => $room->join_code,
|
||||
'player_name' => 'Nico',
|
||||
]))
|
||||
$this->get(route('embedded.room', [
|
||||
'join_code' => $room->join_code,
|
||||
'player_name' => 'Nico',
|
||||
]))
|
||||
->assertUnprocessable()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('embedded/Error')
|
||||
@@ -100,30 +144,39 @@ test('embedded access shows a dedicated error when the display name is taken', f
|
||||
});
|
||||
|
||||
test('embedded access shows a dedicated error for an unknown room code', function () {
|
||||
$this->actingAs(User::factory()->create())
|
||||
->get(route('embedded.room', [
|
||||
'join_code' => 'ABC234',
|
||||
'player_name' => 'Nico',
|
||||
]))
|
||||
$this->get(route('embedded.room', [
|
||||
'join_code' => 'ABC234',
|
||||
'player_name' => 'Nico',
|
||||
]))
|
||||
->assertUnprocessable()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('embedded/Error')
|
||||
->where('message', 'Dieser Raumcode existiert nicht.'));
|
||||
});
|
||||
|
||||
test('embedded logout returns to the same configured room and signs the user out', function () {
|
||||
test('embedded logout returns to the same room as a guest without duplicating the player', function () {
|
||||
$user = User::factory()->create();
|
||||
$room = createEmbeddedRoom();
|
||||
$url = route('embedded.room', [
|
||||
'join_code' => $room->join_code,
|
||||
'player_name' => 'Nico',
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
$this->actingAs($user)->get($url)->assertOk();
|
||||
|
||||
$player = $room->players()->sole();
|
||||
|
||||
$this
|
||||
->followingRedirects()
|
||||
->post(route('embedded.logout', [
|
||||
'join_code' => $room->join_code,
|
||||
'player_name' => 'Nico',
|
||||
]))
|
||||
->assertRedirect(route('embedded.room', [
|
||||
'join_code' => $room->join_code,
|
||||
'player_name' => 'Nico',
|
||||
]));
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('embedded/Room')
|
||||
->where('currentPlayer.id', $player->id));
|
||||
|
||||
$this->assertGuest();
|
||||
$this->assertGuest()
|
||||
->assertDatabaseCount('players', 1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user