def test_clear_disconnected_should_clear_game_when_no_players_left_in_room(): controller = GameController() controller.handle(HelloServerMsg(0, 'Piotr'), 0) controller.handle(WantToJoinMsg(0), 0) controller.disconnected(0) controller.clear_disconnected() actual = controller.handle(HelloServerMsg(2, 'Piotr'), 2) assert actual == MsgToSend(2, message='hello client', status='can create', list_of_players_in_room=[])
def test_should_emit_can_create_when_player_reconnects_before_game_started(): controller = GameController() controller.handle(HelloServerMsg(0, 'Piotr'), 0) controller.handle(WantToJoinMsg(0), 0) controller.disconnected(0) actual = controller.handle(HelloServerMsg(1, 'Piotr'), 1) assert actual == MsgToSend(1, message='hello client', status='can create', list_of_players_in_room=[])
def test_clear_disconnected_should_remove_players_from_room(): controller = GameController() controller.handle(HelloServerMsg(0, 'Piotr'), 0) controller.handle(HelloServerMsg(1, 'Marta'), 1) controller.handle(WantToJoinMsg(0), 0) controller.handle(WantToJoinMsg(1), 1) controller.disconnected(0) controller.clear_disconnected() actual = controller.handle(HelloServerMsg(2, 'Piotr'), 2) assert actual == MsgToSend(2, message='hello client', status='can join', list_of_players_in_room=['Marta'])
def test_should_emit_can_resume_when_player_reconnects_during_the_game(): controller = GameController() controller.handle(HelloServerMsg(0, 'Piotr'), 0) controller.handle(WantToJoinMsg(0), 0) controller.handle(HelloServerMsg(1, 'Marta'), 1) controller.handle(WantToJoinMsg(1), 1) controller.handle(StartGameMsg(0), 0) controller.disconnected(0) actual = controller.handle(HelloServerMsg(0, 'Piotr'), 1) assert actual == MsgToSend(1, message='hello client', status='can resume', list_of_players_in_room=['Piotr', 'Marta'])