feat(issue-225): extend backend i18n error contract to flow endpoints
All checks were successful
CI / test-and-quality (push) Successful in 3m40s
CI / test-and-quality (pull_request) Successful in 3m43s

This commit is contained in:
2026-03-01 22:32:33 +00:00
parent 64fe273691
commit 257732e2ab
3 changed files with 174 additions and 16 deletions

View File

@@ -209,6 +209,8 @@ class StartRoundTests(TestCase):
)
self.assertEqual(response.status_code, 403)
self.assertEqual(response.json()["error_code"], "host_only_start_round")
self.assertEqual(response.json()["locale"], "en")
self.assertEqual(response.json()["error"], "Only host can start round")
def test_start_round_requires_existing_active_category_with_questions(self):
@@ -228,6 +230,8 @@ class StartRoundTests(TestCase):
content_type="application/json",
)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json()["error_code"], "category_has_no_questions")
self.assertEqual(response.json()["locale"], "en")
self.assertEqual(response.json()["error"], "Category has no active questions")
def test_start_round_rejects_non_lobby_session(self):
@@ -244,6 +248,36 @@ class StartRoundTests(TestCase):
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json()["error"], "Round can only be started from lobby")
def test_start_round_error_localizes_to_danish(self):
self.client.login(username="other", password="secret123")
response = self.client.post(
reverse("lobby:start_round", kwargs={"code": self.session.code}),
data={"category_slug": self.category.slug},
content_type="application/json",
HTTP_ACCEPT_LANGUAGE="da",
)
self.assertEqual(response.status_code, 403)
self.assertEqual(response.json()["error_code"], "host_only_start_round")
self.assertEqual(response.json()["locale"], "da")
self.assertEqual(response.json()["error"], "Kun værten kan starte runden")
def test_start_round_error_falls_back_to_english_for_unsupported_locale(self):
self.client.login(username="other", password="secret123")
response = self.client.post(
reverse("lobby:start_round", kwargs={"code": self.session.code}),
data={"category_slug": self.category.slug},
content_type="application/json",
HTTP_ACCEPT_LANGUAGE="fr",
)
self.assertEqual(response.status_code, 403)
self.assertEqual(response.json()["error_code"], "host_only_start_round")
self.assertEqual(response.json()["locale"], "en")
self.assertEqual(response.json()["error"], "Only host can start round")
class LieSubmissionTests(TestCase):
def setUp(self):
@@ -434,6 +468,8 @@ class MixAnswersTests(TestCase):
)
self.assertEqual(response.status_code, 403)
self.assertEqual(response.json()["error_code"], "host_only_mix_answers")
self.assertEqual(response.json()["locale"], "en")
self.assertEqual(response.json()["error"], "Only host can mix answers")
def test_mix_answers_deduplicates_case_insensitive_lies(self):