| 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") | |