Implement FIN-WP-0001-T06 HTTP runway read surface
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.
This commit is contained in:
parent
0f2436b34c
commit
29dbaf1c2d
11 changed files with 270 additions and 4 deletions
58
tests/test_api.py
Normal file
58
tests/test_api.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue