feat: deliver schema 15 monthly settlement lifecycle
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import sqlite3
|
||||
|
||||
from jarca_ledger_mcp.application.accounts_write_services import create_ledger_account
|
||||
from jarca_ledger_mcp.application.assets_service import (
|
||||
create_manual_asset,
|
||||
list_manual_assets,
|
||||
preview_asset_snapshot_close,
|
||||
)
|
||||
from jarca_ledger_mcp.infrastructure.sqlite.migrations import init_db
|
||||
|
||||
|
||||
def tables(path):
|
||||
with sqlite3.connect(path) as conn:
|
||||
return {r[0] for r in conn.execute("select name from sqlite_master where type='table'")}
|
||||
|
||||
|
||||
def test_fresh_and_repeated_init_never_create_manual_assets(tmp_path):
|
||||
path = str(tmp_path / "fresh.sqlite3")
|
||||
init_db(path)
|
||||
init_db(path)
|
||||
assert "manual_assets" not in tables(path)
|
||||
|
||||
|
||||
def test_existing_legacy_manual_assets_is_dropped_without_other_row_loss(tmp_path):
|
||||
path = str(tmp_path / "legacy.sqlite3")
|
||||
init_db(path)
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("create table manual_assets (id text primary key, name text)")
|
||||
conn.execute("insert into manual_assets values ('old', 'legacy')")
|
||||
conn.execute("insert into accounts (id,name,type,active,created_at,updated_at) values ('a','Keep','bank',1,'t','t')")
|
||||
conn.commit()
|
||||
init_db(path)
|
||||
with sqlite3.connect(path) as conn:
|
||||
assert conn.execute("select count(*) from accounts where id='a'").fetchone()[0] == 1
|
||||
assert "manual_assets" not in tables(path)
|
||||
|
||||
|
||||
def test_manual_asset_public_operations_are_unsupported(tmp_path):
|
||||
path = str(tmp_path / "unsupported.sqlite3")
|
||||
init_db(path)
|
||||
expected = {"success": False, "error_code": "unsupported", "error": "manual assets are no longer supported"}
|
||||
assert create_manual_asset("Emergency", 100, "2026-09-30", "cash", db_path=path) == expected
|
||||
assert list_manual_assets(db_path=path) == expected
|
||||
|
||||
|
||||
def test_account_real_estate_creation_and_snapshot_preview_use_normal_path(tmp_path):
|
||||
path = str(tmp_path / "real-estate.sqlite3")
|
||||
init_db(path)
|
||||
created = create_ledger_account(
|
||||
"House", "other", liquidity_bucket="real_estate", last_balance=500000,
|
||||
last_balance_basis_date="2026-09-30", db_path=path,
|
||||
)
|
||||
assert created["success"] is True
|
||||
assert created["account"]["liquidity_bucket"] == "real_estate"
|
||||
assert preview_asset_snapshot_close("2026-09-30", db_path=path)["success"] is True
|
||||
|
||||
|
||||
def test_manual_assets_absent_after_initialization_with_existing_accounts(tmp_path):
|
||||
path = str(tmp_path / "accounts.sqlite3")
|
||||
init_db(path)
|
||||
with sqlite3.connect(path) as conn:
|
||||
before = conn.execute("select count(*) from accounts").fetchone()[0]
|
||||
init_db(path)
|
||||
with sqlite3.connect(path) as conn:
|
||||
assert conn.execute("select count(*) from accounts").fetchone()[0] == before
|
||||
assert "manual_assets" not in tables(path)
|
||||
Reference in New Issue
Block a user