merge(main): resolve PR #320 gameplay conflicts
This commit is contained in:
138
lobby/tests.py
138
lobby/tests.py
@@ -867,6 +867,79 @@ class CanonicalRoundFlowTests(TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
def test_canonical_round_flow_bootstraps_second_round_without_first_round_carry_over(self):
|
||||
self.client.login(username="host_canonical", password="secret123")
|
||||
extra_question = Question.objects.create(
|
||||
category=self.category,
|
||||
prompt="Hvem malede Mona Lisa?",
|
||||
correct_answer="Da Vinci",
|
||||
is_active=True,
|
||||
)
|
||||
|
||||
start_response = self.client.post(
|
||||
reverse("lobby:start_round", kwargs={"code": self.session.code}),
|
||||
data={"category_slug": self.category.slug},
|
||||
content_type="application/json",
|
||||
)
|
||||
self.assertEqual(start_response.status_code, 201)
|
||||
first_round_question_id = start_response.json()["round_question"]["id"]
|
||||
first_round_prompt = start_response.json()["round_question"]["prompt"]
|
||||
first_round_correct_answer = RoundQuestion.objects.get(pk=first_round_question_id).correct_answer
|
||||
second_question = extra_question if first_round_prompt == self.question.prompt else self.question
|
||||
|
||||
final_lie_response = None
|
||||
for index, player in enumerate(self.players, start=1):
|
||||
lie_response = self.client.post(
|
||||
reverse("lobby:submit_lie", kwargs={"code": self.session.code, "round_question_id": first_round_question_id}),
|
||||
data={"player_id": player.id, "session_token": player.session_token, "text": f"Første løgn {index}"},
|
||||
content_type="application/json",
|
||||
)
|
||||
self.assertEqual(lie_response.status_code, 201)
|
||||
final_lie_response = lie_response
|
||||
|
||||
self.assertIsNotNone(final_lie_response)
|
||||
|
||||
for player, selected_text in zip(
|
||||
self.players,
|
||||
[first_round_correct_answer, first_round_correct_answer, first_round_correct_answer],
|
||||
strict=True,
|
||||
):
|
||||
guess_response = self.client.post(
|
||||
reverse("lobby:submit_guess", kwargs={"code": self.session.code, "round_question_id": first_round_question_id}),
|
||||
data={"player_id": player.id, "session_token": player.session_token, "selected_text": selected_text},
|
||||
content_type="application/json",
|
||||
)
|
||||
self.assertEqual(guess_response.status_code, 201)
|
||||
|
||||
scoreboard_payload = self.client.get(reverse("lobby:session_detail", kwargs={"code": self.session.code})).json()
|
||||
self.assertEqual(scoreboard_payload["session"]["status"], GameSession.Status.SCOREBOARD)
|
||||
self.assertEqual(scoreboard_payload["round_question"]["id"], first_round_question_id)
|
||||
self.assertIsNotNone(scoreboard_payload["reveal"])
|
||||
self.assertIsNotNone(scoreboard_payload["scoreboard"])
|
||||
self.assertGreaterEqual(len(scoreboard_payload["reveal"]["guesses"]), 1)
|
||||
|
||||
next_round_response = self.client.post(reverse("lobby:start_next_round", kwargs={"code": self.session.code}))
|
||||
self.assertEqual(next_round_response.status_code, 200)
|
||||
self.assertEqual(next_round_response.json()["session"]["status"], GameSession.Status.LIE)
|
||||
self.assertEqual(next_round_response.json()["session"]["current_round"], 2)
|
||||
|
||||
detail_payload = self.client.get(reverse("lobby:session_detail", kwargs={"code": self.session.code})).json()
|
||||
self.assertEqual(detail_payload["session"]["status"], GameSession.Status.LIE)
|
||||
self.assertEqual(detail_payload["session"]["current_round"], 2)
|
||||
self.assertEqual(detail_payload["phase_view_model"]["current_phase"], GameSession.Status.LIE)
|
||||
self.assertIsNone(detail_payload["reveal"])
|
||||
self.assertIsNone(detail_payload["scoreboard"])
|
||||
self.assertEqual(detail_payload["round_question"]["round_number"], 2)
|
||||
self.assertNotEqual(detail_payload["round_question"]["id"], first_round_question_id)
|
||||
self.assertEqual(detail_payload["round_question"]["prompt"], second_question.prompt)
|
||||
self.assertEqual(detail_payload["round_question"]["answers"], [])
|
||||
|
||||
round_two_question = RoundQuestion.objects.get(session=self.session, round_number=2)
|
||||
self.assertEqual(round_two_question.question, second_question)
|
||||
self.assertEqual(round_two_question.lies.count(), 0)
|
||||
self.assertEqual(round_two_question.guesses.count(), 0)
|
||||
self.assertEqual(round_two_question.mixed_answers, [])
|
||||
|
||||
@patch("lobby.views.sync_broadcast_phase_event")
|
||||
@patch("lobby.views._resolve_scores")
|
||||
@patch("lobby.views.GameSession.objects.get")
|
||||
@@ -1347,6 +1420,45 @@ class RevealRoundFlowTests(TestCase):
|
||||
self.assertEqual(RoundConfig.objects.filter(session=self.session, number=1).count(), 1)
|
||||
self.assertEqual(RoundQuestion.objects.filter(session=self.session, round_number=1).count(), 1)
|
||||
|
||||
def test_start_next_round_clears_existing_next_round_bootstrap_state(self):
|
||||
self.client.login(username="host_reveal", password="secret123")
|
||||
self.client.get(reverse("lobby:reveal_scoreboard", kwargs={"code": self.session.code}))
|
||||
|
||||
stale_round_question = RoundQuestion.objects.create(
|
||||
session=self.session,
|
||||
round_number=2,
|
||||
question=self.next_question,
|
||||
correct_answer=self.next_question.correct_answer,
|
||||
mixed_answers=["Stale truth", "Stale lie"],
|
||||
)
|
||||
LieAnswer.objects.create(round_question=stale_round_question, player=self.player_one, text="Stale lie")
|
||||
Guess.objects.create(
|
||||
round_question=stale_round_question,
|
||||
player=self.player_two,
|
||||
selected_text="Stale truth",
|
||||
is_correct=True,
|
||||
)
|
||||
|
||||
response = self.client.post(reverse("lobby:start_next_round", kwargs={"code": self.session.code}))
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.session.refresh_from_db()
|
||||
stale_round_question.refresh_from_db()
|
||||
self.assertEqual(self.session.status, GameSession.Status.LIE)
|
||||
self.assertEqual(self.session.current_round, 2)
|
||||
self.assertEqual(response.json()["round_question"]["id"], stale_round_question.id)
|
||||
self.assertEqual(stale_round_question.mixed_answers, [])
|
||||
self.assertEqual(stale_round_question.lies.count(), 0)
|
||||
self.assertEqual(stale_round_question.guesses.count(), 0)
|
||||
|
||||
detail_payload = self.client.get(reverse("lobby:session_detail", kwargs={"code": self.session.code})).json()
|
||||
self.assertEqual(detail_payload["session"]["status"], GameSession.Status.LIE)
|
||||
self.assertEqual(detail_payload["session"]["current_round"], 2)
|
||||
self.assertEqual(detail_payload["round_question"]["id"], stale_round_question.id)
|
||||
self.assertEqual(detail_payload["round_question"]["answers"], [])
|
||||
self.assertIsNone(detail_payload["reveal"])
|
||||
self.assertIsNone(detail_payload["scoreboard"])
|
||||
|
||||
def test_start_next_round_requires_host(self):
|
||||
self.session.status = GameSession.Status.SCOREBOARD
|
||||
self.session.save(update_fields=["status"])
|
||||
@@ -1968,7 +2080,7 @@ class SmokeStagingCommandTests(TestCase):
|
||||
self.assertEqual(session.status, GameSession.Status.FINISHED)
|
||||
self.assertEqual(Player.objects.filter(session=session).count(), 3)
|
||||
|
||||
def test_smoke_staging_writes_artifact_when_requested(self):
|
||||
def test_smoke_staging_writes_phase_evidence_artifact_when_requested(self):
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
artifact_path = Path(tmp_dir) / "smoke.json"
|
||||
call_command("smoke_staging", artifact=str(artifact_path))
|
||||
@@ -1976,24 +2088,40 @@ class SmokeStagingCommandTests(TestCase):
|
||||
self.assertTrue(artifact_path.exists())
|
||||
payload = json.loads(artifact_path.read_text(encoding="utf-8"))
|
||||
self.assertTrue(payload["ok"])
|
||||
self.assertEqual(payload["command"], "smoke_staging")
|
||||
self.assertEqual(payload["command"], "python manage.py smoke_staging --artifact <path>")
|
||||
self.assertEqual(payload["players"], ["P1", "P2", "P3"])
|
||||
self.assertIn("generated_at", payload)
|
||||
self.assertIn("session_code", payload)
|
||||
self.assertEqual(payload["question"]["correct_answer"], "Correct")
|
||||
self.assertEqual(payload["guess_plan"]["P2"], "Correct")
|
||||
|
||||
step_names = [step["step"] for step in payload["steps"]]
|
||||
self.assertEqual(
|
||||
payload["steps"],
|
||||
step_names,
|
||||
[
|
||||
"create_session",
|
||||
"join_players",
|
||||
"start_round",
|
||||
"submit_lies",
|
||||
"auto_guess_transition",
|
||||
"submit_guesses",
|
||||
"auto_reveal_to_scoreboard",
|
||||
"auto_reveal_transition",
|
||||
"auto_scoreboard_transition",
|
||||
"finish_game",
|
||||
],
|
||||
)
|
||||
|
||||
reveal_step = payload["steps"][5]
|
||||
self.assertEqual(reveal_step["session_status"], GameSession.Status.REVEAL)
|
||||
self.assertEqual(reveal_step["reveal"]["correct_answer"], "Correct")
|
||||
self.assertEqual(reveal_step["reveal"]["lies_count"], 3)
|
||||
self.assertEqual(reveal_step["reveal"]["guesses_count"], 3)
|
||||
self.assertEqual(len(reveal_step["reveal"]["fooled_player_ids"]), 2)
|
||||
self.assertEqual(len(reveal_step["reveal"]["correct_guess_player_ids"]), 1)
|
||||
|
||||
scoreboard_step = payload["steps"][6]
|
||||
self.assertEqual(scoreboard_step["session_status"], GameSession.Status.SCOREBOARD)
|
||||
self.assertEqual(len(scoreboard_step["leaderboard"]), 3)
|
||||
|
||||
|
||||
class I18nResolverTests(TestCase):
|
||||
def test_resolve_locale_accepts_language_tags_and_normalizes_to_supported_base_locale(self):
|
||||
|
||||
Reference in New Issue
Block a user