diff --git a/lobby/tests.py b/lobby/tests.py index 9ef6803..2495309 100644 --- a/lobby/tests.py +++ b/lobby/tests.py @@ -100,6 +100,21 @@ class LobbyFlowTests(TestCase): self.assertEqual(response.status_code, 409) self.assertEqual(response.json()["error"], "Nickname already taken") + def test_player_can_join_during_scoreboard_phase(self): + session = GameSession.objects.create(host=self.host, code="ZXCV97", status=GameSession.Status.SCOREBOARD) + + response = self.client.post( + reverse("lobby:join_session"), + data={"code": "ZXCV97", "nickname": "Kai"}, + content_type="application/json", + ) + + self.assertEqual(response.status_code, 201) + body = response.json() + self.assertEqual(body["session"]["status"], GameSession.Status.SCOREBOARD) + self.assertEqual(body["player"]["nickname"], "Kai") + self.assertTrue(Player.objects.filter(session=session, nickname="Kai").exists()) + def test_join_rejects_non_joinable_session(self): GameSession.objects.create(host=self.host, code="ZXCV98", status=GameSession.Status.FINISHED) @@ -686,7 +701,7 @@ class ScoreCalculationTests(TestCase): self.player_two = Player.objects.create(session=self.session, nickname="Mads") self.player_three = Player.objects.create(session=self.session, nickname="Nora") - def test_host_can_calculate_scores_and_transition_to_reveal(self): + def test_host_can_calculate_scores_and_transition_to_scoreboard(self): Guess.objects.create(round_question=self.round_question, player=self.player_one, selected_text="Tennis", is_correct=True) Guess.objects.create( round_question=self.round_question, @@ -713,7 +728,7 @@ class ScoreCalculationTests(TestCase): self.assertEqual(response.status_code, 200) payload = response.json() - self.assertEqual(payload["session"]["status"], GameSession.Status.REVEAL) + self.assertEqual(payload["session"]["status"], GameSession.Status.SCOREBOARD) self.assertEqual(payload["events_created"], 2) self.player_one.refresh_from_db() @@ -722,7 +737,7 @@ class ScoreCalculationTests(TestCase): self.assertEqual(self.player_one.score, 5) self.assertEqual(self.player_three.score, 4) - self.assertEqual(self.session.status, GameSession.Status.REVEAL) + self.assertEqual(self.session.status, GameSession.Status.SCOREBOARD) def test_calculate_scores_requires_host(self): self.client.login(username="other_score", password="secret123") diff --git a/lobby/views.py b/lobby/views.py index 8b94fbe..73c17ee 100644 --- a/lobby/views.py +++ b/lobby/views.py @@ -30,6 +30,7 @@ JOINABLE_STATUSES = { GameSession.Status.LIE, GameSession.Status.GUESS, GameSession.Status.REVEAL, + GameSession.Status.SCOREBOARD, } ERROR_CODES = lobby_i18n_errors() @@ -896,7 +897,7 @@ def calculate_scores(request: HttpRequest, code: str, round_question_id: int) -> ScoreEvent.objects.bulk_create(score_events) - locked_session.status = GameSession.Status.REVEAL + locked_session.status = GameSession.Status.SCOREBOARD locked_session.save(update_fields=["status"]) leaderboard = list( @@ -909,7 +910,7 @@ def calculate_scores(request: HttpRequest, code: str, round_question_id: int) -> { "session": { "code": session.code, - "status": GameSession.Status.REVEAL, + "status": GameSession.Status.SCOREBOARD, "current_round": session.current_round, }, "round_question": {