Add files via upload
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
from app.server import sync_progress_from_events
|
||||
|
||||
|
||||
class TurnProgressionTests(unittest.TestCase):
|
||||
def test_turn_ended_advances_to_next_player(self) -> None:
|
||||
metadata = {
|
||||
"GameStartConfiguration": {
|
||||
"NumberOfPlayersAsInt": 2,
|
||||
"Players": {
|
||||
"$values": [
|
||||
{"Color": "Yellow", "SittingOrder": 0},
|
||||
{"Color": "Blue", "SittingOrder": 1},
|
||||
]
|
||||
},
|
||||
},
|
||||
"PlayerMetadata": [
|
||||
{"PlayerNetworkId": "player-yellow", "NickName": "Yellow"},
|
||||
{"PlayerNetworkId": "player-blue", "NickName": "Blue"},
|
||||
],
|
||||
"NetworkGameProgressInformation": {},
|
||||
}
|
||||
game = {
|
||||
"metadata": metadata,
|
||||
"events": [
|
||||
{"$type": "BoardGameRules.Entities.GamePhases.Events.TurnStarted, Assembly-CSharp", "PlayerColor": "Yellow"},
|
||||
{"$type": "BoardGameRules.Entities.GamePhases.Events.TurnEnded, Assembly-CSharp"},
|
||||
],
|
||||
}
|
||||
|
||||
sync_progress_from_events(game)
|
||||
|
||||
self.assertEqual(metadata["NetworkGameProgressInformation"]["CurrentPlayerId"], "player-blue")
|
||||
|
||||
def test_turn_started_after_turn_ended_is_accepted(self) -> None:
|
||||
metadata = {
|
||||
"GameStartConfiguration": {
|
||||
"NumberOfPlayersAsInt": 2,
|
||||
"Players": {
|
||||
"$values": [
|
||||
{"Color": "Yellow", "SittingOrder": 0},
|
||||
{"Color": "Blue", "SittingOrder": 1},
|
||||
]
|
||||
},
|
||||
},
|
||||
"PlayerMetadata": [
|
||||
{"PlayerNetworkId": "player-yellow", "NickName": "Yellow"},
|
||||
{"PlayerNetworkId": "player-blue", "NickName": "Blue"},
|
||||
],
|
||||
"NetworkGameProgressInformation": {},
|
||||
}
|
||||
game = {
|
||||
"metadata": metadata,
|
||||
"events": [
|
||||
{"$type": "BoardGameRules.Entities.GamePhases.Events.TurnStarted, Assembly-CSharp", "PlayerColor": "Yellow"},
|
||||
{"$type": "BoardGameRules.Entities.GamePhases.Events.TurnEnded, Assembly-CSharp"},
|
||||
{"$type": "BoardGameRules.Entities.GamePhases.Events.TurnStarted, Assembly-CSharp", "PlayerColor": "Blue"},
|
||||
],
|
||||
}
|
||||
|
||||
sync_progress_from_events(game)
|
||||
|
||||
self.assertEqual(metadata["NetworkGameProgressInformation"]["CurrentPlayerId"], "player-blue")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user