79 lines
2.5 KiB
Python
79 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
from decimal import Decimal
|
|
|
|
from fints.models import SEPAAccount
|
|
from mousehold_agent.fints_connector import transaction_to_observation
|
|
|
|
|
|
class DummyTransaction:
|
|
def __init__(self, data: dict[str, object]) -> None:
|
|
self.data = data
|
|
|
|
|
|
def test_fints_debit_transaction_becomes_expense_observation() -> None:
|
|
observation = transaction_to_observation(
|
|
DummyTransaction(
|
|
{
|
|
"date": date(2026, 6, 1),
|
|
"amount": Decimal("-42.50"),
|
|
"currency": "EUR",
|
|
"applicant_name": "REWE",
|
|
"purpose": "Kartenzahlung",
|
|
"customer_reference": "abc-123",
|
|
}
|
|
),
|
|
account=SEPAAccount("DE001234", "TESTBIC", "1234", None, "43060967"),
|
|
household_id="household-1",
|
|
source_account_id="account-1",
|
|
owner_user_id="user-1",
|
|
)
|
|
|
|
assert observation["source_type"] == "fints"
|
|
assert observation["event_type"] == "expense"
|
|
assert observation["amount"] == "42.50"
|
|
assert observation["provider_transaction_id"] == "abc-123"
|
|
assert observation["event_date"] == "2026-06-01"
|
|
|
|
|
|
def test_fints_credit_transaction_becomes_income_observation() -> None:
|
|
observation = transaction_to_observation(
|
|
DummyTransaction(
|
|
{
|
|
"date": date(2026, 6, 2),
|
|
"amount": Decimal("100.00"),
|
|
"currency": "EUR",
|
|
"applicant_name": "Employer",
|
|
"purpose": "Salary",
|
|
}
|
|
),
|
|
account=SEPAAccount("DE001234", "TESTBIC", "1234", None, "43060967"),
|
|
household_id="household-1",
|
|
source_account_id="account-1",
|
|
owner_user_id="user-1",
|
|
)
|
|
|
|
assert observation["event_type"] == "income"
|
|
assert observation["amount"] == "100.00"
|
|
|
|
|
|
def test_fints_paypal_bank_debit_becomes_liability_payment() -> None:
|
|
observation = transaction_to_observation(
|
|
DummyTransaction(
|
|
{
|
|
"date": date(2026, 6, 3),
|
|
"amount": Decimal("-18.99"),
|
|
"currency": "EUR",
|
|
"applicant_name": "PayPal Europe",
|
|
"purpose": "Funding debit",
|
|
}
|
|
),
|
|
account=SEPAAccount("DE001234", "TESTBIC", "1234", None, "43060967"),
|
|
household_id="household-1",
|
|
source_account_id="account-1",
|
|
owner_user_id="user-1",
|
|
)
|
|
|
|
assert observation["event_type"] == "liability_payment"
|