Files
rail-game/backend/tests/test_network_api.py
zwitschi fc1e874309
Some checks failed
Backend CI / lint-and-test (push) Failing after 2m15s
Frontend CI / lint-and-build (push) Successful in 1m1s
feat: Initialize frontend and backend structure with essential configurations
- Added TypeScript build info for frontend.
- Created Vite configuration for React application.
- Implemented pre-commit hook to run checks before commits.
- Set up PostgreSQL Dockerfile with PostGIS support and initialization scripts.
- Added database creation script for PostgreSQL with necessary extensions.
- Established Python project configuration with dependencies and development tools.
- Developed pre-commit script to enforce code quality checks for backend and frontend.
- Created PowerShell script to set up Git hooks path.
2025-10-11 15:25:32 +02:00

36 lines
1.1 KiB
Python

from fastapi.testclient import TestClient
from backend.app.main import app
AUTH_CREDENTIALS = {"username": "demo", "password": "railgame123"}
client = TestClient(app)
def _authenticate() -> str:
response = client.post("/api/auth/login", json=AUTH_CREDENTIALS)
assert response.status_code == 200
return response.json()["accessToken"]
def test_network_snapshot_requires_authentication() -> None:
response = client.get("/api/network")
assert response.status_code == 401
def test_network_snapshot_endpoint_returns_collections() -> None:
token = _authenticate()
response = client.get(
"/api/network", headers={"Authorization": f"Bearer {token}"}
)
assert response.status_code == 200
payload = response.json()
assert set(payload.keys()) == {"stations", "tracks", "trains"}
assert all(isinstance(payload[key], list) for key in payload)
assert payload["stations"], "Expected sample station data"
assert payload["trains"], "Expected sample train data"
station = payload["stations"][0]
assert "name" in station and "createdAt" in station