Fix loan account conversion invariant
This commit is contained in:
@@ -5,6 +5,39 @@ from jarca_ledger_mcp.application.account_valuation_service import record_accoun
|
||||
from jarca_ledger_mcp.application.imports_service import _record_import_valuation_candidate
|
||||
|
||||
|
||||
def test_bank_to_loan_conversion_rejects_existing_undefined_valuation_without_mutation(tmp_path):
|
||||
path = str(tmp_path / "ledger.sqlite3")
|
||||
created = service.create_ledger_account(
|
||||
"은행", type="bank", last_balance=100, last_synced_at="2026-06-30",
|
||||
last_balance_basis_date="2026-06-30", db_path=path,
|
||||
)
|
||||
account_id = created["account"]["id"]
|
||||
before = service.list_account_valuations(account_id, db_path=path)
|
||||
assert before["count"] == 1
|
||||
assert before["valuations"][0]["representative_liability_definition"] is None
|
||||
|
||||
rejected = service.update_ledger_account(account_id, type="loan", db_path=path)
|
||||
|
||||
assert rejected["success"] is False
|
||||
assert rejected["error_code"] == "validation_error"
|
||||
accounts = service.list_ledger_accounts(active_only=False, db_path=path)["accounts"]
|
||||
assert next(account for account in accounts if account["id"] == account_id)["type"] == "bank"
|
||||
after = service.list_account_valuations(account_id, db_path=path)
|
||||
assert after["count"] == 1
|
||||
assert after["valuations"] == before["valuations"]
|
||||
|
||||
|
||||
def test_bank_to_loan_conversion_without_valuations_remains_allowed(tmp_path):
|
||||
path = str(tmp_path / "ledger.sqlite3")
|
||||
account_id = service.create_ledger_account("은행", type="bank", db_path=path)["account"]["id"]
|
||||
|
||||
converted = service.update_ledger_account(account_id, type="loan", db_path=path)
|
||||
|
||||
assert converted["success"] is True
|
||||
assert converted["account"]["type"] == "loan"
|
||||
assert service.list_account_valuations(account_id, db_path=path)["count"] == 0
|
||||
|
||||
|
||||
def test_loan_balance_requires_representative_liability_definition(tmp_path):
|
||||
path = str(tmp_path / "ledger.sqlite3")
|
||||
bank = service.create_ledger_account("은행", type="bank", db_path=path)["account"]["id"]
|
||||
|
||||
Reference in New Issue
Block a user