Improve CarPass product UX and service flows
This commit is contained in:
@@ -87,3 +87,44 @@ async def test_stats_do_not_fail_with_insufficient_data(client, auth_headers) ->
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["avg_consumption_l_per_100km"] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_expense_crud_and_insurance_allocation(client, auth_headers) -> None:
|
||||
car = (await client.post("/api/cars", headers=auth_headers, json={"name": "Cost car"})).json()
|
||||
created = await client.post(
|
||||
"/api/expenses",
|
||||
headers=auth_headers,
|
||||
json={
|
||||
"car_id": car["id"],
|
||||
"entry_date": "2026-01-01",
|
||||
"category": "insurance",
|
||||
"title": "Insurance",
|
||||
"total_cost": 1200,
|
||||
"period_start": "2026-01-01",
|
||||
"period_end": "2026-12-31",
|
||||
"is_recurring": True,
|
||||
},
|
||||
)
|
||||
assert created.status_code == 201
|
||||
entry_id = created.json()["id"]
|
||||
|
||||
stats = await client.get(
|
||||
f"/api/cars/{car['id']}/stats?date_from=2026-01-01&date_to=2026-01-31",
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert stats.status_code == 200
|
||||
body = stats.json()
|
||||
assert body["expenses_cost"] in {"101.92", "101.93"}
|
||||
assert body["cost_by_category"]["insurance"] in {"101.92", "101.93"}
|
||||
|
||||
patched = await client.patch(
|
||||
f"/api/expenses/{entry_id}",
|
||||
headers=auth_headers,
|
||||
json={"title": "Insurance policy"},
|
||||
)
|
||||
assert patched.status_code == 200
|
||||
assert patched.json()["title"] == "Insurance policy"
|
||||
|
||||
deleted = await client.delete(f"/api/expenses/{entry_id}", headers=auth_headers)
|
||||
assert deleted.status_code == 204
|
||||
|
||||
Reference in New Issue
Block a user