"""Tests for REST API routes — TDD: tests before implementation.""" import pytest from i2p_apps.console.app import create_app @pytest.fixture def client(): app = create_app({"TESTING": True}) return app.test_client() class TestAPIStatus: def test_status_endpoint(self, client): resp = client.get("/api/v1/status") assert resp.status_code == 200 data = resp.get_json() assert "state" in data assert "uptime" in data assert "version" in data def test_status_has_network(self, client): resp = client.get("/api/v1/status") data = resp.get_json() assert "network" in data assert "active_peers" in data["network"] class TestAPIPeers: def test_peers_endpoint(self, client): resp = client.get("/api/v1/peers") assert resp.status_code == 200 data = resp.get_json() assert "peers" in data assert isinstance(data["peers"], list) class TestAPITunnels: def test_tunnels_endpoint(self, client): resp = client.get("/api/v1/tunnels") assert resp.status_code == 200 data = resp.get_json() assert "tunnels" in data assert isinstance(data["tunnels"], list) class TestAPIConfig: def test_get_config(self, client): resp = client.get("/api/v1/config") assert resp.status_code == 200 data = resp.get_json() assert isinstance(data, dict) def test_post_config(self, client): resp = client.post( "/api/v1/config", json={"test.key": "test_value"}, ) assert resp.status_code == 200 data = resp.get_json() assert data["status"] == "ok" class TestAPIRouter: def test_router_action_invalid(self, client): resp = client.post("/api/v1/router/invalid_action") assert resp.status_code == 400