feat: Planungs- und Szenario-API mit Projektion und Vorschlaegen
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
47
finance/tests/test_planning_api.py
Normal file
47
finance/tests/test_planning_api.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
from app.models.tables import Account, Statement
|
||||
|
||||
H = {"Authorization": "Bearer test-key"}
|
||||
|
||||
|
||||
def _seed_balance(db, amount="1000.00"):
|
||||
acc = Account(bank="dkb", iban="DE01", name="G", type="giro")
|
||||
db.add(acc)
|
||||
db.flush()
|
||||
db.add(Statement(filename="s.pdf", bank="dkb", account_id=acc.id,
|
||||
period_start=date(2026, 6, 1), period_end=date(2026, 6, 30),
|
||||
opening_balance=Decimal("0"), closing_balance=Decimal(amount),
|
||||
status="confirmed"))
|
||||
db.commit()
|
||||
|
||||
|
||||
def test_scenario_projection(client, db):
|
||||
_seed_balance(db)
|
||||
client.post("/api/recurring", headers=H, json={
|
||||
"name": "Miete", "amount": "-600.00", "rhythm": "monthly", "due_day": 1})
|
||||
sc = client.post("/api/scenarios", headers=H, json={"name": "Basis"}).json()
|
||||
r = client.post(f"/api/scenarios/{sc['id']}/project", headers=H,
|
||||
params={"horizon_days": 92, "start_date": "2026-07-15"})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
# 3 Mietzahlungen (01.08., 01.09., 01.10.): 400 -> -200 -> -800
|
||||
assert Decimal(body["low_point_balance"]) == Decimal("-800.00")
|
||||
assert body["below_zero_date"] == "2026-09-01"
|
||||
assert len(body["series"]) == 92
|
||||
|
||||
|
||||
def test_loan_in_scenario_keeps_balance_positive(client, db):
|
||||
_seed_balance(db)
|
||||
client.post("/api/recurring", headers=H, json={
|
||||
"name": "Miete", "amount": "-600.00", "rhythm": "monthly", "due_day": 1})
|
||||
loan = client.post("/api/loans", headers=H, json={
|
||||
"name": "K1", "principal": "5000.00", "annual_rate_pct": "6.0",
|
||||
"term_months": 48, "payout_date": "2026-07-20",
|
||||
"repayment_type": "annuity"}).json()
|
||||
sc = client.post("/api/scenarios", headers=H, json={"name": "Kredit"}).json()
|
||||
client.post(f"/api/scenarios/{sc['id']}/loans/{loan['id']}", headers=H)
|
||||
body = client.post(f"/api/scenarios/{sc['id']}/project", headers=H,
|
||||
params={"horizon_days": 92, "start_date": "2026-07-15"}).json()
|
||||
assert Decimal(body["low_point_balance"]) > Decimal("0")
|
||||
Reference in New Issue
Block a user