mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-15 09:46:10 +00:00
big shot
This commit is contained in:
@@ -20,7 +20,6 @@ function createEmoteRoom(array $attributes = []): Room
|
||||
}
|
||||
|
||||
test('a participant can throw a realtime paper ball at another player', function () {
|
||||
Event::fake([PaperBallThrown::class]);
|
||||
$room = createEmoteRoom(['last_activity_at' => now()->subDay()]);
|
||||
$sender = $room->players()->create([
|
||||
'name' => 'Eric',
|
||||
@@ -33,6 +32,7 @@ test('a participant can throw a realtime paper ball at another player', function
|
||||
$room->refresh();
|
||||
$activity = $room->last_activity_at;
|
||||
$stateVersion = $room->state_version;
|
||||
Event::fake([PaperBallThrown::class]);
|
||||
|
||||
$this->withSession(["room_players.{$room->id}" => $sender->id])
|
||||
->postJson(route('room.emote.paper-ball.store', $room), [
|
||||
@@ -44,12 +44,14 @@ test('a participant can throw a realtime paper ball at another player', function
|
||||
return $event->roomId === $room->id
|
||||
&& $event->fromPlayerId === $sender->id
|
||||
&& $event->targetPlayerId === $target->id
|
||||
&& $event->chargeLevel === 0
|
||||
&& $event->broadcastOn()->name === "rooms.{$room->id}"
|
||||
&& $event->broadcastAs() === 'room.emote.thrown'
|
||||
&& array_keys($event->broadcastWith()) === [
|
||||
'id',
|
||||
'from_player_id',
|
||||
'target_player_id',
|
||||
'charge_level',
|
||||
];
|
||||
});
|
||||
|
||||
@@ -59,6 +61,65 @@ test('a participant can throw a realtime paper ball at another player', function
|
||||
->and($room->state_version)->toBe($stateVersion);
|
||||
});
|
||||
|
||||
test('paper ball charge percentages map to the expected level', function (int $chargePercentage, int $expectedLevel) {
|
||||
$room = createEmoteRoom();
|
||||
$sender = $room->players()->create([
|
||||
'name' => 'Eric',
|
||||
'is_moderator' => true,
|
||||
]);
|
||||
$target = $room->players()->create([
|
||||
'name' => 'Anna',
|
||||
'is_moderator' => false,
|
||||
]);
|
||||
Event::fake([PaperBallThrown::class]);
|
||||
|
||||
$this->withSession(["room_players.{$room->id}" => $sender->id])
|
||||
->postJson(route('room.emote.paper-ball.store', $room), [
|
||||
'target_player_id' => $target->id,
|
||||
'charge_percentage' => $chargePercentage,
|
||||
])
|
||||
->assertNoContent();
|
||||
|
||||
Event::assertDispatched(
|
||||
PaperBallThrown::class,
|
||||
fn (PaperBallThrown $event): bool => $event->chargeLevel === $expectedLevel,
|
||||
);
|
||||
})->with([
|
||||
'uncharged' => [0, 0],
|
||||
'just below level one' => [99, 0],
|
||||
'level one threshold' => [100, 1],
|
||||
'top of level one' => [199, 1],
|
||||
'level two threshold' => [200, 2],
|
||||
'top of level two' => [299, 2],
|
||||
'level three threshold and cap' => [300, 3],
|
||||
]);
|
||||
|
||||
test('paper ball charge percentages outside the supported range are rejected', function (int $chargePercentage) {
|
||||
$room = createEmoteRoom();
|
||||
$sender = $room->players()->create([
|
||||
'name' => 'Eric',
|
||||
'is_moderator' => true,
|
||||
]);
|
||||
$target = $room->players()->create([
|
||||
'name' => 'Anna',
|
||||
'is_moderator' => false,
|
||||
]);
|
||||
Event::fake([PaperBallThrown::class]);
|
||||
|
||||
$this->withSession(["room_players.{$room->id}" => $sender->id])
|
||||
->postJson(route('room.emote.paper-ball.store', $room), [
|
||||
'target_player_id' => $target->id,
|
||||
'charge_percentage' => $chargePercentage,
|
||||
])
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors('charge_percentage');
|
||||
|
||||
Event::assertNotDispatched(PaperBallThrown::class);
|
||||
})->with([
|
||||
'below zero' => -1,
|
||||
'above the cap' => 301,
|
||||
]);
|
||||
|
||||
test('a participant cannot throw a paper ball at themselves', function () {
|
||||
Event::fake([PaperBallThrown::class]);
|
||||
$room = createEmoteRoom();
|
||||
|
||||
Reference in New Issue
Block a user