feat(sp39): Resubmission model + migration 0021 + idempotency tests
This commit is contained in:
@@ -127,14 +127,15 @@ def test_migration_latest_idempotent_on_fresh_db(tmp_path: Path) -> None:
|
||||
SP32 bumped it to 19 with rendering_provider_npi +
|
||||
service_provider_npi on claims and remittances.
|
||||
SP37 bumped it to 20 with batch transaction_set_control_number.
|
||||
SP39 bumped it to 21 with the resubmissions audit table.
|
||||
"""
|
||||
engine = _fresh_engine(tmp_path)
|
||||
db_migrate.run(engine)
|
||||
v_after_first = _user_version(engine)
|
||||
assert v_after_first == 20, f"expected head=20, got {v_after_first}"
|
||||
assert v_after_first == 21, f"expected head=21, got {v_after_first}"
|
||||
|
||||
db_migrate.run(engine)
|
||||
assert _user_version(engine) == 20, "second run should not bump version"
|
||||
assert _user_version(engine) == 21, "second run should not bump version"
|
||||
|
||||
|
||||
def test_drop_claims_unique_constraint_migration(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
@@ -160,7 +161,7 @@ def test_drop_claims_unique_constraint_migration(tmp_path: Path, monkeypatch: py
|
||||
engine = _fresh_engine(tmp_path)
|
||||
|
||||
db_migrate.run(engine)
|
||||
assert _user_version(engine) == 20, f"expected head=20, got {_user_version(engine)}"
|
||||
assert _user_version(engine) == 21, f"expected head=21, got {_user_version(engine)}"
|
||||
|
||||
# Two claims in one batch with the same patient_control_number
|
||||
# must be insertable. If 0015's table recreation re-introduced a
|
||||
@@ -187,3 +188,50 @@ def test_drop_claims_unique_constraint_migration(tmp_path: Path, monkeypatch: py
|
||||
assert [r[0] for r in rows] == ["CLM-1", "CLM-2"]
|
||||
assert [float(r[1]) for r in rows] == [100.0, 200.0]
|
||||
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# SP39: migration 0021 creates the resubmissions table
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_migration_0021_creates_resubmissions_table(tmp_path: Path) -> None:
|
||||
"""SP39: 0021_resubmissions.sql adds the resubmissions audit table
|
||||
with the documented columns + unique constraint on
|
||||
(claim_id, interchange_control_number)."""
|
||||
# Point the runner at the REAL migrations dir so we exercise 0021.
|
||||
real_dir = Path(db_migrate.__file__).parent / "migrations"
|
||||
import cyclone.db_migrate as real_migrate_mod
|
||||
real_dir_str = str(real_dir)
|
||||
|
||||
engine = _fresh_engine(tmp_path)
|
||||
# monkeypatch the module-level MIGRATIONS_DIR
|
||||
import importlib
|
||||
monkey_save = real_migrate_mod.MIGRATIONS_DIR
|
||||
real_migrate_mod.MIGRATIONS_DIR = Path(real_dir_str)
|
||||
try:
|
||||
db_migrate.run(engine)
|
||||
finally:
|
||||
real_migrate_mod.MIGRATIONS_DIR = monkey_save
|
||||
|
||||
# Verify the table exists with the expected columns + unique index.
|
||||
with engine.connect() as conn:
|
||||
version = conn.exec_driver_sql("PRAGMA user_version").scalar()
|
||||
assert version >= 21
|
||||
cols = conn.exec_driver_sql(
|
||||
"PRAGMA table_info(resubmissions)"
|
||||
).all()
|
||||
col_names = {row[1] for row in cols}
|
||||
assert col_names == {
|
||||
"id", "claim_id", "batch_id", "resubmitted_at",
|
||||
"source_corrected_path",
|
||||
"interchange_control_number", "group_control_number",
|
||||
}
|
||||
idx_rows = conn.exec_driver_sql(
|
||||
"SELECT name, sql FROM sqlite_master "
|
||||
"WHERE type='index' AND tbl_name='resubmissions'"
|
||||
).all()
|
||||
idx_names = {row[0] for row in idx_rows}
|
||||
assert "ix_resubmissions_claim_id" in idx_names
|
||||
assert "ix_resubmissions_batch_id" in idx_names
|
||||
assert "ux_resubmissions_claim_icn" in idx_names
|
||||
|
||||
Reference in New Issue
Block a user