fix: Address second code review findings (test isolation, frontend type safety)

This commit is contained in:
Yunxiao Xu
2026-02-17 02:11:04 -08:00
parent 96e2634053
commit ece12f951a
6 changed files with 31 additions and 24 deletions

View File

@@ -5,7 +5,9 @@ from ea_chatbot.api.main import app
from ea_chatbot.history.models import User
from ea_chatbot.api.utils import create_access_token
client = TestClient(app)
@pytest.fixture
def client():
return TestClient(app)
@pytest.fixture
def mock_user():
@@ -17,7 +19,7 @@ def mock_user():
theme_preference="light"
)
def test_v1_prefix():
def test_v1_prefix(client):
"""Test that routes are prefixed with /api/v1."""
# This should now be 404
response = client.get("/auth/me")
@@ -27,7 +29,7 @@ def test_v1_prefix():
response = client.get("/api/v1/auth/me")
assert response.status_code == 401
def test_login_sets_cookie():
def test_login_sets_cookie(client):
"""Test that login sets the access_token cookie."""
with patch("ea_chatbot.api.routers.auth.history_manager") as mock_hm:
mock_hm.authenticate_user.return_value = User(id="1", username="test@example.com")
@@ -45,7 +47,7 @@ def test_login_sets_cookie():
assert "access_token" in set_cookie
assert "HttpOnly" in set_cookie
def test_register_sets_cookie():
def test_register_sets_cookie(client):
"""Test that register sets the access_token cookie."""
with patch("ea_chatbot.api.routers.auth.history_manager") as mock_hm:
mock_hm.get_user.return_value = None
@@ -59,7 +61,7 @@ def test_register_sets_cookie():
assert response.status_code == 201
assert "access_token" in response.cookies
def test_auth_via_cookie():
def test_auth_via_cookie(client):
"""Test that protected routes work with the access_token cookie."""
token = create_access_token(data={"sub": "123"})
@@ -73,7 +75,7 @@ def test_auth_via_cookie():
assert response.status_code == 200
assert response.json()["email"] == "test@example.com"
def test_logout_clears_cookie():
def test_logout_clears_cookie(client):
"""Test that logout endpoint clears the cookie."""
response = client.post("/api/v1/auth/logout")
assert response.status_code == 200
@@ -81,7 +83,7 @@ def test_logout_clears_cookie():
cookie = response.cookies.get("access_token")
assert not cookie or cookie == ""
def test_oidc_callback_redirects_with_cookie():
def test_oidc_callback_redirects_with_cookie(client):
"""Test that OIDC callback sets cookie and redirects."""
with patch("ea_chatbot.api.routers.auth.oidc_client") as mock_oidc, \
patch("ea_chatbot.api.routers.auth.OIDCSession.decrypt") as mock_decrypt, \