Add create_runway_router() following the hub-core factory pattern, expose GET /runway/summary and /runway/monthly-burn via create_app, and add finhub serve for local operation.
58 lines
No EOL
1.9 KiB
Python
58 lines
No EOL
1.9 KiB
Python
from pathlib import Path
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from fin_hub.app import create_app
|
|
from fin_hub.routers.runway import create_runway_router
|
|
from fin_hub.services.evidence import seed_fixture_ledger
|
|
|
|
|
|
def _client_for_ledger(ledger: Path) -> TestClient:
|
|
app = create_app()
|
|
app.include_router(
|
|
create_runway_router(ledger_path_resolver=lambda _: ledger),
|
|
prefix="/test",
|
|
)
|
|
return TestClient(app)
|
|
|
|
|
|
def test_runway_summary_and_monthly_burn_endpoints(tmp_path: Path):
|
|
ledger = tmp_path / "ledger.db"
|
|
seed_fixture_ledger(ledger_path=ledger, opening_balance=12000.0)
|
|
client = _client_for_ledger(ledger)
|
|
|
|
burn_response = client.get("/test/runway/monthly-burn")
|
|
assert burn_response.status_code == 200
|
|
burns = burn_response.json()
|
|
assert any(row["currency"] == "EUR" and row["period_month"] == "2026-06" for row in burns)
|
|
|
|
summary_response = client.get("/test/runway/summary")
|
|
assert summary_response.status_code == 200
|
|
summary = summary_response.json()
|
|
assert summary["opening_balance"] == 12000.0
|
|
assert summary["runway"]["currency"] == "EUR"
|
|
assert summary["runway"]["monthly_burn"] > 0
|
|
|
|
|
|
def test_runway_summary_requires_balance_when_unset(tmp_path: Path):
|
|
from fin_hub.services.ledger import monthly_summary
|
|
|
|
ledger = tmp_path / "empty.db"
|
|
monthly_summary(ledger_path=ledger)
|
|
client = _client_for_ledger(ledger)
|
|
response = client.get("/test/runway/summary")
|
|
assert response.status_code == 422
|
|
|
|
|
|
def test_runway_summary_404_when_ledger_missing(tmp_path: Path):
|
|
ledger = tmp_path / "missing.db"
|
|
client = _client_for_ledger(ledger)
|
|
response = client.get("/test/runway/summary?balance=12000")
|
|
assert response.status_code == 404
|
|
|
|
|
|
def test_create_app_healthz():
|
|
client = TestClient(create_app())
|
|
response = client.get("/healthz")
|
|
assert response.status_code == 200
|
|
assert response.json()["service"] == "fin-hub" |