from fastapi.testclient import TestClient

from flyway.api.main import create_app
from flyway.config import settings


def test_built_frontend_served_with_spa_fallback(tmp_path, monkeypatch):
    (tmp_path / "index.html").write_text("<div id=app></div>", encoding="utf-8")
    (tmp_path / "assets").mkdir()
    (tmp_path / "assets" / "a.js").write_text("x", encoding="utf-8")
    monkeypatch.setattr(settings, "frontend_dist", str(tmp_path))
    c = TestClient(create_app())
    assert c.get("/assets/a.js").text == "x"
    assert "id=app" in c.get("/load-ins/123").text
    assert c.get("/api/nope").status_code == 404
    assert c.get("/api/auth/me").status_code == 401
