From 89d29353238e970f2d50c0cf557aeb84a1543e37 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 31 Jul 2023 22:19:55 +0200 Subject: [PATCH] Fixed test, deprecated method, and changes it's uses --- BackendTests/Services/ActionServiceTests.cs | 4 +++- pac-man-board-game/ClientApp/package.json | 5 ----- pac-man-board-game/Controllers/GameController.cs | 2 +- pac-man-board-game/Services/ActionService.cs | 4 ++-- pac-man-board-game/Services/GameService.cs | 1 + 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/BackendTests/Services/ActionServiceTests.cs b/BackendTests/Services/ActionServiceTests.cs index 721feb8..73734d0 100644 --- a/BackendTests/Services/ActionServiceTests.cs +++ b/BackendTests/Services/ActionServiceTests.cs @@ -148,8 +148,9 @@ public class ActionServiceTests [Test] public void Ready_NotAllReady() { + var game = _gameService.CreateAndJoin(_whitePlayer, _spawns); + _gameService.JoinById(game.Id, _blackPlayer); _service.SetPlayerInfo(_whiteMessage.Data); - _service.SetPlayerInfo(_blackMessage.Data); var result = _service.Ready(); if (result is ReadyData r1) @@ -157,6 +158,7 @@ public class ActionServiceTests else Assert.Fail("Result should be ReadyData"); + _gameService.JoinById(game.Id, _redPlayer); _service.SetPlayerInfo(_redMessage.Data); result = _service.Ready(); diff --git a/pac-man-board-game/ClientApp/package.json b/pac-man-board-game/ClientApp/package.json index fc43c86..7a5d151 100644 --- a/pac-man-board-game/ClientApp/package.json +++ b/pac-man-board-game/ClientApp/package.json @@ -43,11 +43,6 @@ "test": "cross-env CI=true vitest", "coverage": "vitest run --coverage" }, - "eslintConfig": { - "extends": [ - "react-app" - ] - }, "browserslist": { "production": [ ">0.2%", diff --git a/pac-man-board-game/Controllers/GameController.cs b/pac-man-board-game/Controllers/GameController.cs index 0bbd501..51afb34 100644 --- a/pac-man-board-game/Controllers/GameController.cs +++ b/pac-man-board-game/Controllers/GameController.cs @@ -32,7 +32,7 @@ public class GameController : GenericController return _gameService.Games; } - [HttpPost("join/{gameId}")] + [HttpPost("join/{gameId:guid}")] public IActionResult JoinGame(Guid gameId, [FromBody] Player player) // TODO what if player is in a game already? { Logger.Log(LogLevel.Debug, "Joining game {}", gameId); diff --git a/pac-man-board-game/Services/ActionService.cs b/pac-man-board-game/Services/ActionService.cs index d8b586c..4cd5cd5 100644 --- a/pac-man-board-game/Services/ActionService.cs +++ b/pac-man-board-game/Services/ActionService.cs @@ -75,7 +75,7 @@ public class ActionService : IActionService return jsonElement; } - public List SetPlayerInfo(JsonElement? jsonElement) // TODO split up into two actions + public List SetPlayerInfo(JsonElement? jsonElement) // TODO split up into two actions, join and create { var data = jsonElement?.Deserialize() ?? throw new NullReferenceException("Data is null"); Player = data.Player; @@ -93,7 +93,7 @@ public class ActionService : IActionService } else { - Game = _gameService.AddPlayer(Player, data.Spawns); + Game = _gameService.CreateAndJoin(Player, data.Spawns); } Game.Connections += SendSegment; diff --git a/pac-man-board-game/Services/GameService.cs b/pac-man-board-game/Services/GameService.cs index 39b3e47..adbc8ab 100644 --- a/pac-man-board-game/Services/GameService.cs +++ b/pac-man-board-game/Services/GameService.cs @@ -19,6 +19,7 @@ public class GameService : WebSocketService /// public SynchronizedCollection Games { get; } = new(); + [Obsolete("Use CreateAndJoin instead")] public Game AddPlayer(Player player, Queue spawns) { var index = 0;