48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import inspect
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
|
|
from dashboard.page_views import accounts as accounts_page
|
|
from jarca_ledger_mcp.adapters.mcp import server
|
|
|
|
|
|
def test_dashboard_valuation_basis_never_uses_sync_timestamp():
|
|
account = {
|
|
"last_balance_basis_date": "2026-06-30",
|
|
"last_synced_at": "2026-07-09T23:59:00+09:00",
|
|
}
|
|
assert accounts_page._account_balance_basis_date(account) == "2026-06-30"
|
|
assert accounts_page._account_balance_basis_date({"last_synced_at": account["last_synced_at"]}) == ""
|
|
assert "last_synced_at" not in inspect.getsource(accounts_page.page_accounts)
|
|
|
|
|
|
def test_mcp_account_write_tools_forward_explicit_balance_basis(monkeypatch):
|
|
calls: list[tuple[str, tuple, dict]] = []
|
|
|
|
def fake_create(*args, **kwargs):
|
|
calls.append(("create", args, kwargs))
|
|
return {"success": True}
|
|
|
|
def fake_update(*args, **kwargs):
|
|
calls.append(("update", args, kwargs))
|
|
return {"success": True}
|
|
|
|
monkeypatch.setattr(server.contracts, "create_ledger_account", fake_create)
|
|
monkeypatch.setattr(server.contracts, "update_ledger_account", fake_update)
|
|
|
|
assert server.create_ledger_account(
|
|
"dated", last_balance=100, last_synced_at="2026-07-09T00:00:00Z",
|
|
last_balance_basis_date="2026-06-30",
|
|
)["success"]
|
|
assert server.update_ledger_account(
|
|
"account-1", last_balance=200, last_synced_at="2026-07-10T00:00:00Z",
|
|
last_balance_basis_date="2026-07-01",
|
|
)["success"]
|
|
|
|
assert calls[0][2]["last_balance_basis_date"] == "2026-06-30"
|
|
assert calls[1][2]["last_balance_basis_date"] == "2026-07-01"
|