"""Pre-split regression tests for /api/ideas/* and /api/feedback routes.""" from __future__ import annotations from fastapi.testclient import TestClient class TestIdeas: def test_list_unauthenticated_returns_401(self, client: TestClient): assert client.get("/api/ideas").status_code == 401 def test_create_unauthenticated_returns_4xx(self, client: TestClient): # Pydantic validates the body before auth runs, so empty body → 422; # a valid body → 401. Either is an auth/validation rejection. r = client.post("/api/ideas", json={"title": "test", "body": ""}) assert r.status_code == 401 def test_authenticated_list_returns_ideas(self, user_client: TestClient): r = user_client.get("/api/ideas") assert r.status_code == 200 assert "ideas" in r.json() def test_create_idea(self, user_client: TestClient): r = user_client.post("/api/ideas", json={"title": "My idea", "body": "Details"}) assert r.status_code == 200 assert "id" in r.json() def test_create_idea_empty_title_returns_400(self, user_client: TestClient): r = user_client.post("/api/ideas", json={"title": "", "body": ""}) assert r.status_code == 400 def test_vote_on_missing_idea_returns_404(self, user_client: TestClient): assert user_client.post("/api/ideas/no-such-id/vote").status_code == 404 def test_vote_toggle(self, user_client: TestClient): create_r = user_client.post("/api/ideas", json={"title": "Votable", "body": ""}) idea_id = create_r.json()["id"] r = user_client.post(f"/api/ideas/{idea_id}/vote") assert r.status_code == 200 assert r.json()["voted"] is True r2 = user_client.post(f"/api/ideas/{idea_id}/vote") assert r2.json()["voted"] is False class TestFeedback: def test_unauthenticated_returns_401(self, client: TestClient): assert client.post("/api/feedback", data={}).status_code == 401