feat: added settings in room to kick

This commit is contained in:
2026-09-06 16:06:12 +02:00
parent 1e0f5cf143
commit 817b1ce1cb
10 changed files with 439 additions and 107 deletions
+73 -2
View File
@@ -104,17 +104,34 @@ test('the room owner can kick an active participant', function () {
Event::assertDispatchedTimes(RoomStateChanged::class, 1);
});
test('a participant cannot kick another player', function () {
test('the room moderator can kick an active participant without shared management', function () {
$owner = User::factory()->create();
$room = createRoomForPlayerKick($owner, ['owner_id' => null]);
$moderator = addPlayerToKickRoom($room, 'Moderator', null, true);
$target = addPlayerToKickRoom($room, 'Anna');
Event::fake([RoomStateChanged::class]);
$this->withSession(["room_players.{$room->id}" => $moderator->id])
->delete(route('room.player.destroy', [$room, $target]))
->assertRedirect();
expect($target->fresh()->inactive_at)->not->toBeNull();
Event::assertDispatchedTimes(RoomStateChanged::class, 1);
});
test('a participant cannot kick another player when participant management is disabled', function () {
$owner = User::factory()->create();
$participantUser = User::factory()->create();
$room = createRoomForPlayerKick($owner);
addPlayerToKickRoom($room, 'Moderator', $owner, true);
addPlayerToKickRoom($room, 'Anna', $participantUser);
$participant = addPlayerToKickRoom($room, 'Anna', $participantUser);
$target = addPlayerToKickRoom($room, 'Ben');
Event::fake([RoomStateChanged::class]);
$this->actingAs($participantUser)
->withSession(["room_players.{$room->id}" => $participant->id])
->delete(route('room.player.destroy', [$room, $target]))
->assertForbidden();
@@ -122,6 +139,60 @@ test('a participant cannot kick another player', function () {
Event::assertNotDispatched(RoomStateChanged::class);
});
test('a participant can kick another player when participant management is enabled', function () {
$owner = User::factory()->create();
$room = createRoomForPlayerKick($owner, [
'allow_participants_to_manage_rounds' => true,
]);
addPlayerToKickRoom($room, 'Moderator', $owner, true);
$participant = addPlayerToKickRoom($room, 'Anna');
$target = addPlayerToKickRoom($room, 'Ben');
Event::fake([RoomStateChanged::class]);
$this->withSession(["room_players.{$room->id}" => $participant->id])
->delete(route('room.player.destroy', [$room, $target]))
->assertRedirect();
expect($target->fresh()->inactive_at)->not->toBeNull();
Event::assertDispatched(RoomStateChanged::class);
});
test('a participant cannot kick themselves when participant management is enabled', function () {
$owner = User::factory()->create();
$room = createRoomForPlayerKick($owner, [
'allow_participants_to_manage_rounds' => true,
]);
$participant = addPlayerToKickRoom($room, 'Anna');
Event::fake([RoomStateChanged::class]);
$this->withSession(["room_players.{$room->id}" => $participant->id])
->delete(route('room.player.destroy', [$room, $participant]))
->assertForbidden();
expect($participant->fresh()->inactive_at)->toBeNull();
Event::assertNotDispatched(RoomStateChanged::class);
});
test('an anonymous visitor without a room session cannot kick from an ownerless room', function () {
$owner = User::factory()->create();
$room = createRoomForPlayerKick($owner, [
'owner_id' => null,
'allow_participants_to_manage_rounds' => true,
]);
addPlayerToKickRoom($room, 'Moderator', null, true);
$target = addPlayerToKickRoom($room, 'Ben');
Event::fake([RoomStateChanged::class]);
$this->delete(route('room.player.destroy', [$room, $target]))
->assertForbidden();
expect($target->fresh()->inactive_at)->toBeNull();
Event::assertNotDispatched(RoomStateChanged::class);
});
test('the room owner cannot kick their own player', function () {
$owner = User::factory()->create();
$room = createRoomForPlayerKick($owner);