fix(lobby): ready status anzeigen und Spielstart absichern
This commit is contained in:
@@ -118,8 +118,9 @@ public class GameServiceTests
|
||||
using var db = _factory.CreateDbContext();
|
||||
var host = TestDbHelper.SeedUser(db);
|
||||
var other = TestDbHelper.SeedUser(db, "other", "other@t.local");
|
||||
var (game, _) = TestDbHelper.SeedGame(db, host);
|
||||
db.Players.Add(new Player { UserId = other.Id, GameId = game.Id });
|
||||
var (game, hostPlayer) = TestDbHelper.SeedGame(db, host);
|
||||
hostPlayer.IsReady = true;
|
||||
db.Players.Add(new Player { UserId = other.Id, GameId = game.Id, IsReady = true });
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var result = await _sut.StartGameAsync(game.Id);
|
||||
@@ -131,6 +132,22 @@ public class GameServiceTests
|
||||
Assert.Equal(RoundStatus.Waiting, round.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StartGameAsync_Throws_WhenAnyPlayerIsNotReady()
|
||||
{
|
||||
using var db = _factory.CreateDbContext();
|
||||
var host = TestDbHelper.SeedUser(db);
|
||||
var other = TestDbHelper.SeedUser(db, "other", "other@t.local");
|
||||
var (game, hostPlayer) = TestDbHelper.SeedGame(db, host);
|
||||
hostPlayer.IsReady = true;
|
||||
db.Players.Add(new Player { UserId = other.Id, GameId = game.Id, IsReady = false });
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() => _sut.StartGameAsync(game.Id));
|
||||
|
||||
Assert.Equal("All players must be ready to start the game", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StartGameAsync_Throws_WhenGameNotFound()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user