Fix Review 63 snapshot and balance regressions
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
from jarca_ledger_mcp import service
|
||||
from jarca_ledger_mcp.application import imports_service
|
||||
|
||||
|
||||
def _transaction(date, balance):
|
||||
return SimpleNamespace(
|
||||
transaction_date=date,
|
||||
transaction_datetime=f"{date} 10:00:00",
|
||||
amount=100,
|
||||
counterparty="상대",
|
||||
raw_summary="입금",
|
||||
branch="",
|
||||
remittance_memo="",
|
||||
balance_after=balance,
|
||||
type="income",
|
||||
page=1,
|
||||
action="입금",
|
||||
external_id=lambda source_hash: f"review63:{source_hash}",
|
||||
raw_payload=lambda: "{}",
|
||||
)
|
||||
|
||||
|
||||
def test_create_rejects_basis_only_without_mutation(tmp_path):
|
||||
path = str(tmp_path / "ledger.sqlite3")
|
||||
|
||||
rejected = service.create_ledger_account(
|
||||
"기준일만 있는 계좌",
|
||||
last_balance_basis_date="2026-07-31",
|
||||
db_path=path,
|
||||
)
|
||||
|
||||
assert rejected == {
|
||||
"success": False,
|
||||
"error_code": "validation_error",
|
||||
"error": "last_balance_basis_date requires last_balance",
|
||||
}
|
||||
baseline = service.create_ledger_account("정상 계좌", db_path=path)
|
||||
assert baseline["success"] is True
|
||||
listed = service.list_ledger_accounts(active_only=False, db_path=path)
|
||||
assert listed["count"] == 1
|
||||
assert listed["accounts"][0]["name"] == "정상 계좌"
|
||||
|
||||
|
||||
def test_basis_only_create_cannot_block_later_dated_import(tmp_path, monkeypatch):
|
||||
path = str(tmp_path / "ledger.sqlite3")
|
||||
rejected = service.create_ledger_account(
|
||||
"기준일만 있는 계좌",
|
||||
last_balance_basis_date="2026-07-31",
|
||||
db_path=path,
|
||||
)
|
||||
assert rejected["success"] is False
|
||||
|
||||
account = service.create_ledger_account("정상 계좌", db_path=path)["account"]["id"]
|
||||
monkeypatch.setattr(
|
||||
imports_service,
|
||||
"parse_kb_bank_pdf",
|
||||
lambda *_: {
|
||||
"transactions": [_transaction("2026-06-30", 50)],
|
||||
"validation": {"ok": True},
|
||||
"source_hash": "review63",
|
||||
"metadata": {"final_balance": 50, "account_number_masked": ""},
|
||||
"file_path": "/tmp/synthetic.pdf",
|
||||
"page_count": 1,
|
||||
},
|
||||
)
|
||||
|
||||
imported = imports_service.import_kb_bank_pdf(
|
||||
"ignored", "pw", account_id=account, db_path=path,
|
||||
)
|
||||
|
||||
current = service.list_ledger_accounts(active_only=False, db_path=path)["accounts"][0]
|
||||
assert imported["success"] is True
|
||||
assert current["last_balance"] == 50
|
||||
assert current["last_balance_basis_date"] == "2026-06-30"
|
||||
Reference in New Issue
Block a user