"""infra routers unit tests.""" from fastapi.testclient import TestClient from pytest_mock import MockerFixture from contributor.api.datasources import get_splitio_client def test_hello( test_client: TestClient, mocker: MockerFixture, ) -> None: """Verify the /hello/ endpoint responds with 200 and OK status.""" response = test_client.get( "/hello/", headers={"Authorization": "Bearer test-token"}, ) assert response.status_code == 200 assert response.json() == {"status": "ok"} def test_root(test_client: TestClient) -> None: """Verify the / endpoint responds with 200 and OK status.""" response = test_client.get("/") assert response.status_code == 200 assert response.json() == {"Hello": "World!"} def test_hello_split_returns_bonjour_when_feature_on( test_client: TestClient, app, mocker: MockerFixture, ) -> None: """Verify /hello/split returns bonjour when bonjour feature is enabled.""" mock_splitio_client = mocker.MagicMock() mock_splitio_client.get_treatment.return_value = "on" app.dependency_overrides[get_splitio_client] = lambda: mock_splitio_client response = test_client.get("/hello/split") app.dependency_overrides.pop(get_splitio_client, None) assert response.status_code == 200 assert response.json() == {"message": "bonjour"} def test_hello_split_returns_hello_when_feature_off( test_client: TestClient, app, mocker: MockerFixture, ) -> None: """Verify /hello/split returns hello when bonjour feature is disabled.""" mock_splitio_client = mocker.MagicMock() mock_splitio_client.get_treatment.return_value = "off" app.dependency_overrides[get_splitio_client] = lambda: mock_splitio_client response = test_client.get("/hello/split") app.dependency_overrides.pop(get_splitio_client, None) assert response.status_code == 200 assert response.json() == {"message": "hello"}