File size: 975 Bytes
3a4ffcf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
from datetime import datetime
from app.schemas import Transaction
from app.services import generate_insights
def _txn(ts: str, category: str, amount: float) -> Transaction:
return Transaction(
timestamp=datetime.fromisoformat(ts),
category=category,
amount=amount,
currency="INR",
)
def test_generate_insights_detects_increase():
txns = [
_txn("2025-09-05T00:00:00", "Groceries", 100),
_txn("2025-10-05T00:00:00", "Groceries", 130),
_txn("2025-11-05T00:00:00", "Groceries", 200),
]
insights, months = generate_insights(txns)
assert insights, "Expected at least one insight"
assert any("increased" in insight.message for insight in insights)
assert months, "Expected evaluated months to be returned"
def test_generate_insights_handles_new_user():
insights, months = generate_insights([])
assert months == []
assert insights[0].message.startswith("Add a few expenses")
|