feat(backend): fix T4 index drift, lazy import, FK policy, expand test coverage
This commit is contained in:
@@ -78,3 +78,80 @@ def test_create_and_query_claim_with_default_state():
|
||||
assert loaded.state == ClaimState.SUBMITTED
|
||||
assert loaded.charge_amount == Decimal("124.00")
|
||||
assert loaded.service_date_from == date(2026, 6, 1)
|
||||
|
||||
|
||||
def test_claim_uses_db_default_when_state_omitted():
|
||||
"""The `state` column has a DB-side DEFAULT of 'submitted' (per migration
|
||||
and ORM `default=`). When the caller omits `state=`, the loaded value
|
||||
must be ClaimState.SUBMITTED, not None."""
|
||||
with db.SessionLocal()() as s:
|
||||
s.add(Batch(
|
||||
id="b1", kind="837p", input_filename="x",
|
||||
parsed_at=datetime(2026, 6, 19, tzinfo=timezone.utc),
|
||||
))
|
||||
c = Claim(
|
||||
id="CLM-1",
|
||||
batch_id="b1",
|
||||
patient_control_number="CLM-1",
|
||||
charge_amount=Decimal("0"),
|
||||
)
|
||||
s.add(c)
|
||||
s.commit()
|
||||
|
||||
with db.SessionLocal()() as s:
|
||||
loaded = s.get(Claim, "CLM-1")
|
||||
assert loaded is not None
|
||||
assert loaded.state == ClaimState.SUBMITTED
|
||||
|
||||
|
||||
def test_state_before_reversal_round_trips():
|
||||
"""`state_before_reversal` is nullable but stores a ClaimState enum.
|
||||
Setting it to PAID must round-trip as ClaimState.PAID after commit+reload."""
|
||||
with db.SessionLocal()() as s:
|
||||
s.add(Batch(
|
||||
id="b1", kind="837p", input_filename="x",
|
||||
parsed_at=datetime(2026, 6, 19, tzinfo=timezone.utc),
|
||||
))
|
||||
c = Claim(
|
||||
id="CLM-1",
|
||||
batch_id="b1",
|
||||
patient_control_number="CLM-1",
|
||||
charge_amount=Decimal("50.00"),
|
||||
state_before_reversal=ClaimState.PAID,
|
||||
)
|
||||
s.add(c)
|
||||
s.commit()
|
||||
|
||||
with db.SessionLocal()() as s:
|
||||
loaded = s.get(Claim, "CLM-1")
|
||||
assert loaded is not None
|
||||
assert loaded.state_before_reversal == ClaimState.PAID
|
||||
|
||||
|
||||
def test_batch_cascade_delete_drops_claims():
|
||||
"""Deleting a Batch must cascade-delete its claims (FK is ON DELETE CASCADE
|
||||
in migration; ORM relationship uses cascade='all, delete-orphan' which makes
|
||||
SQLAlchemy emit the child DELETE at flush time even without
|
||||
PRAGMA foreign_keys=ON)."""
|
||||
with db.SessionLocal()() as s:
|
||||
s.add(Batch(
|
||||
id="b1", kind="837p", input_filename="x",
|
||||
parsed_at=datetime(2026, 6, 19, tzinfo=timezone.utc),
|
||||
))
|
||||
s.add(Claim(
|
||||
id="CLM-1",
|
||||
batch_id="b1",
|
||||
patient_control_number="CLM-1",
|
||||
charge_amount=Decimal("0"),
|
||||
))
|
||||
s.commit()
|
||||
|
||||
with db.SessionLocal()() as s:
|
||||
batch = s.get(Batch, "b1")
|
||||
assert batch is not None
|
||||
s.delete(batch)
|
||||
s.commit()
|
||||
|
||||
with db.SessionLocal()() as s:
|
||||
assert s.get(Batch, "b1") is None
|
||||
assert s.get(Claim, "CLM-1") is None
|
||||
|
||||
Reference in New Issue
Block a user