from fastapi.testclient import TestClient

from beaver.interfaces.web.app import create_app


def test_local_frontend_origin_can_preflight_api_requests() -> None:
    app = create_app(service=None, manage_service_lifecycle=False)
    client = TestClient(app)

    response = client.options(
        "/api/auth/me",
        headers={
            "Origin": "http://127.0.0.1:3080",
            "Access-Control-Request-Method": "GET",
            "Access-Control-Request-Headers": "authorization",
        },
    )

    assert response.status_code == 200
    assert response.headers["access-control-allow-origin"] == "http://127.0.0.1:3080"
    assert "authorization" in response.headers["access-control-allow-headers"].lower()
