mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-14 16:35:28 +00:00
Implement instant websocket room updates
This commit is contained in:
@@ -5,6 +5,7 @@ use App\Events\RoomStateChanged;
|
||||
use App\Jobs\CloseInactiveRooms;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
@@ -23,18 +24,20 @@ function createBroadcastRoom(array $attributes = []): Room
|
||||
]);
|
||||
}
|
||||
|
||||
test('room state broadcasts expose only invalidation metadata', function () {
|
||||
test('room state broadcasts synchronously expose sanitized state', function () {
|
||||
$event = new RoomStateChanged(
|
||||
'019b8f80-37c4-71a3-b415-5f2697332c16',
|
||||
7,
|
||||
RoomStateChange::VoteChanged,
|
||||
);
|
||||
|
||||
expect($event->broadcastAs())->toBe('room.state.changed')
|
||||
expect($event)->toBeInstanceOf(ShouldBroadcastNow::class)
|
||||
->and($event->broadcastAs())->toBe('room.state.changed')
|
||||
->and($event->broadcastOn()->name)->toBe('rooms.019b8f80-37c4-71a3-b415-5f2697332c16')
|
||||
->and($event->broadcastWith())->toBe([
|
||||
'version' => 7,
|
||||
'change' => 'vote_changed',
|
||||
'state' => null,
|
||||
])
|
||||
->and($event->broadcastWith())->not->toHaveKeys([
|
||||
'player_name',
|
||||
@@ -68,23 +71,23 @@ test('voting and round actions broadcast their state changes', function () {
|
||||
|
||||
$this->withSession($session)
|
||||
->post(route('room.vote.store', $room), ['value' => '5'])
|
||||
->assertRedirect();
|
||||
->assertNoContent();
|
||||
|
||||
$this->withSession($session)
|
||||
->post(route('room.reveal', $room))
|
||||
->assertRedirect();
|
||||
->assertNoContent();
|
||||
|
||||
$this->withSession($session)
|
||||
->post(route('room.next-round', $room))
|
||||
->assertRedirect();
|
||||
->assertNoContent();
|
||||
|
||||
$this->withSession($session)
|
||||
->post(route('room.vote.store', $room), ['value' => '3'])
|
||||
->assertRedirect();
|
||||
->assertNoContent();
|
||||
|
||||
$this->withSession($session)
|
||||
->post(route('room.reset', $room))
|
||||
->assertRedirect();
|
||||
->assertNoContent();
|
||||
|
||||
foreach ([
|
||||
RoomStateChange::VoteChanged,
|
||||
@@ -98,6 +101,35 @@ test('voting and round actions broadcast their state changes', function () {
|
||||
);
|
||||
}
|
||||
|
||||
Event::assertDispatched(
|
||||
RoomStateChanged::class,
|
||||
function (RoomStateChanged $event) use ($moderator): bool {
|
||||
if ($event->change !== RoomStateChange::VoteChanged || $event->state === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$player = collect($event->state['players'])->firstWhere('id', $moderator->id);
|
||||
|
||||
return $event->state['revealed'] === false
|
||||
&& $player['has_voted'] === true
|
||||
&& $player['vote'] === null;
|
||||
},
|
||||
);
|
||||
|
||||
Event::assertDispatched(
|
||||
RoomStateChanged::class,
|
||||
function (RoomStateChanged $event) use ($moderator): bool {
|
||||
if ($event->change !== RoomStateChange::CardsRevealed || $event->state === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$player = collect($event->state['players'])->firstWhere('id', $moderator->id);
|
||||
|
||||
return $event->state['revealed'] === true
|
||||
&& $player['vote'] === '5';
|
||||
},
|
||||
);
|
||||
|
||||
Event::assertDispatchedTimes(RoomStateChanged::class, 5);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user