feat: API fuer Szenario-Ende-Modifikator und szenario-eigene Einmalzahlungen
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -186,3 +186,46 @@ def test_patch_transaction_category(client):
|
||||
r = client.patch(f"/api/transactions/{tx_id}", headers=H,
|
||||
json={"category_id": 9999})
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_scenario_patch_beschreibung_leeren(client):
|
||||
sc = client.post("/api/scenarios", headers=H, json={"name": "DescNull", "description": "x"}).json()
|
||||
r = client.patch(f"/api/scenarios/{sc['id']}", headers=H, json={"description": None})
|
||||
assert r.status_code == 200 and r.json()["description"] == ""
|
||||
|
||||
|
||||
def test_modifier_ende_validierung(client, db):
|
||||
sc = client.post("/api/scenarios", headers=H, json={"name": "EndeVal"}).json()
|
||||
# ende ohne Datum -> 422
|
||||
r = client.post(f"/api/scenarios/{sc['id']}/modifiers", headers=H, json={
|
||||
"target_type": "recurring", "target_id": 1, "kind": "ende"})
|
||||
assert r.status_code == 422
|
||||
# ende mit Datum -> 201, end_date in der Antwort
|
||||
r = client.post(f"/api/scenarios/{sc['id']}/modifiers", headers=H, json={
|
||||
"target_type": "recurring", "target_id": 1, "kind": "ende",
|
||||
"end_date": "2026-08-31"})
|
||||
assert r.status_code == 201
|
||||
assert r.json()["end_date"] == "2026-08-31"
|
||||
# andere Arten nullen end_date
|
||||
r = client.post(f"/api/scenarios/{sc['id']}/modifiers", headers=H, json={
|
||||
"target_type": "recurring", "target_id": 1, "kind": "remove",
|
||||
"end_date": "2026-08-31"})
|
||||
assert r.status_code == 201 and r.json()["end_date"] is None
|
||||
|
||||
|
||||
def test_scenario_planned_crud_und_cleanup(client, db):
|
||||
sc = client.post("/api/scenarios", headers=H, json={"name": "SPI-CRUD"}).json()
|
||||
r = client.post(f"/api/scenarios/{sc['id']}/planned", headers=H, json={
|
||||
"name": "Sonderzahlung", "amount": "5000.00", "due": "2026-07-30"})
|
||||
assert r.status_code == 201
|
||||
item = r.json()
|
||||
assert item["scenario_id"] == sc["id"] and item["amount"] == "5000.00"
|
||||
assert client.get(f"/api/scenarios/{sc['id']}/planned", headers=H).json()[0]["name"] == "Sonderzahlung"
|
||||
# DELETE mit fremder scenario_id -> 404
|
||||
other = client.post("/api/scenarios", headers=H, json={"name": "SPI-Other"}).json()
|
||||
assert client.delete(f"/api/scenarios/{other['id']}/planned/{item['id']}",
|
||||
headers=H).status_code == 404
|
||||
# Szenario loeschen raeumt Einmalzahlungen mit ab (kein FK-Fehler):
|
||||
assert client.delete(f"/api/scenarios/{sc['id']}", headers=H).status_code == 204
|
||||
from app.models.tables import ScenarioPlannedItem
|
||||
assert db.query(ScenarioPlannedItem).count() == 0
|
||||
|
||||
Reference in New Issue
Block a user