fix: align schema 15 settlement tests and integer validation

This commit is contained in:
2026-10-17 15:58:28 +09:00
parent 38a854d525
commit a97548c36b
8 changed files with 76 additions and 144 deletions
+13 -34
View File
@@ -1,44 +1,23 @@
from pathlib import Path
import sqlite3
from jarca_ledger_mcp.db import init_db
from jarca_ledger_mcp.application.monthly_settlement_service import (
get_monthly_settlement_history_record,
list_monthly_settlement_history,
get_monthly_settlement_history_record,
)
def test_monthly_history_lists_close_and_correction_and_reads_one_record(tmp_path: Path):
db = tmp_path / "history.sqlite3"
init_db(str(db))
with sqlite3.connect(db) as conn:
conn.execute(
"""INSERT INTO asset_snapshot_runs
(id,basis_date,close_status,correction_of_run_id,correction_reason,
created_at,settlement_month,draft_version,approved_at)
VALUES (?,?,?,?,?,?,?,?,?)""",
("run-1", "2026-09-30", "complete_exact", "", "",
"2026-10-01T00:00:00Z", "2026-09", 1, "2026-10-01T00:00:00Z"),
)
conn.execute(
"""INSERT INTO asset_snapshot_runs
(id,basis_date,close_status,correction_of_run_id,correction_reason,
created_at,settlement_month,draft_version,approved_at)
VALUES (?,?,?,?,?,?,?,?,?)""",
("run-2", "2026-09-30", "conditional", "run-1", "누락 거래 반영",
"2026-10-02T00:00:00Z", "2026-09", 2, "2026-10-02T00:00:00Z"),
)
conn.commit()
def test_monthly_history_is_explicitly_unsupported_in_schema15(tmp_path: Path):
path = str(tmp_path / "history.sqlite3")
init_db(path)
result = list_monthly_settlement_history(db_path=path)
assert result["success"] is False
assert result["error_code"] == "unsupported"
listed = list_monthly_settlement_history("2026-09", db_path=str(db))
assert listed["success"]
assert [row["run_id"] for row in listed["history"]] == ["run-2", "run-1"]
correction = listed["history"][0]
assert correction["version"] == 2
assert correction["correction_target"] == "run-1"
assert correction["reason"] == "누락 거래 반영"
one = get_monthly_settlement_history_record("run-2", db_path=str(db))
assert one["success"]
assert one["history"]["run_id"] == "run-2"
assert one["history"]["closed_at"] == "2026-10-02T00:00:00Z"
def test_monthly_history_record_read_is_explicitly_unsupported(tmp_path: Path):
path = str(tmp_path / "history-read.sqlite3")
init_db(path)
result = get_monthly_settlement_history_record("run-1", db_path=path)
assert result["success"] is False
assert result["error_code"] == "unsupported"