import pathlib from collections.abc import Iterator import pytest from starlette.testclient import TestClient from resonance_engine.config import settings from tests.unit.helpers import override_settings @pytest.fixture(autouse=True) def _built_dashboard(tmp_path: pathlib.Path) -> Iterator[None]: (tmp_path / "index.html").write_text("") with override_settings(dashboard_dir=tmp_path, auth_enabled=True): yield def test_serve_dashboard_redirects_to_login_without_cookie(client: TestClient) -> None: client.cookies.clear() response = client.get("/dashboard", follow_redirects=False) assert response.status_code == 307 assert response.headers["location"] == "/dashboard/login" def test_serve_dashboard_route_redirects_to_login_without_cookie( client: TestClient, ) -> None: client.cookies.clear() response = client.get("/dashboard/tasks", follow_redirects=False) assert response.status_code == 307 assert response.headers["location"] == "/dashboard/login" def test_serve_login_page_without_cookie(client: TestClient) -> None: client.cookies.clear() response = client.get("/dashboard/login", follow_redirects=False) assert response.status_code == 200 def test_serve_dashboard_with_cookie(client: TestClient) -> None: client.cookies.clear() client.cookies.set(settings.session_cookie_name, "any-token") response = client.get("/dashboard", follow_redirects=False) assert response.status_code == 200