30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import sqlite3
|
|
|
|
from jarca_ledger_mcp.application.monthly_settlement_service import create_monthly_settlement
|
|
from jarca_ledger_mcp.infrastructure.sqlite.migrations import init_db
|
|
|
|
|
|
def test_create_monthly_settlement_persists_canonical_draft_and_rejects_duplicate(tmp_path):
|
|
path = tmp_path / "ledger.sqlite3"
|
|
init_db(str(path))
|
|
|
|
created = create_monthly_settlement("2026-10", db_path=str(path))
|
|
assert created["success"]
|
|
assert created["month"] == "2026-10"
|
|
assert created["status"] == "draft"
|
|
assert created["settlement_id"]
|
|
|
|
with sqlite3.connect(path) as conn:
|
|
row = conn.execute(
|
|
"SELECT id, month, basis_date, status FROM monthly_settlement WHERE id=?",
|
|
(created["settlement_id"],),
|
|
).fetchone()
|
|
assert row == (created["settlement_id"], "2026-10", "2026-10-31", "draft")
|
|
|
|
duplicate = create_monthly_settlement("2026-10", db_path=str(path))
|
|
assert duplicate["success"] is False
|
|
assert duplicate["error_code"] == "duplicate_month"
|
|
assert duplicate["settlement_id"] == created["settlement_id"]
|