fix(gameplay): align scoreboard API contract
All checks were successful
CI / test-and-quality (pull_request) Successful in 2m42s
CI / test-and-quality (push) Successful in 2m45s

This commit is contained in:
2026-03-15 07:43:38 +00:00
parent 638c9452d8
commit dc0c203f7f
2 changed files with 21 additions and 5 deletions

View File

@@ -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")

View File

@@ -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": {