fix(backend): spec-bug fixes for T10 — Match.claim_id non-unique + reconcile test dates

Three spec-bug fixes from T10 implementation:

- Match.claim_id: drop UNIQUE constraint (T4 schema error) — reversals add a 2nd row per claim (audit trail). Add explicit non-unique index ix_matches_claim_id to preserve query performance. Mirrored in ORM and migration 0001_initial.sql.
- test_run_orphan_remit_leaves_claim_unmatched: claim PCN-A does not match remit PCN-NEW, so unmatched_claims must be 1, not 0.
- test_run_reversal_flips_paid_to_reversed: claim service_date_from was 9 days before reversal remit service_date (outside default 7-day window) so no match occurred; changed to 5 days apart so match() picks the claim.
- test_match_unique_per_claim: in test_db_models.py asserted the now-removed UNIQUE behavior; renamed and inverted to assert the audit-trail design (two Match rows per claim allowed).
This commit is contained in:
Tyler
2026-06-19 22:59:20 -06:00
parent 8c92ef43bd
commit 6a65c2b750
4 changed files with 29 additions and 12 deletions
+7 -2
View File
@@ -290,13 +290,18 @@ def test_run_orphan_remit_leaves_claim_unmatched(fixture_835):
assert result.matched == 0
assert result.unmatched_remittances == 1
assert result.unmatched_claims == 0
# Spec-bug fix (T10): claim PCN-A does not match remit PCN-NEW, so the
# claim stays in the unmatched bucket. Original spec asserted 0.
assert result.unmatched_claims == 1
def test_run_reversal_flips_paid_to_reversed(fixture_835):
with db.SessionLocal()() as s:
_make_batch(s)
_make_claim(s, "CLM-1", "PCN-A", "100.00", date(2026, 6, 1),
# Spec-bug fix (T10): dates are 5 days apart so match() picks this claim
# (default window_days=7). Original spec used 2026-06-01 vs 2026-06-10
# (9 days, outside window) which produced no match.
_make_claim(s, "CLM-1", "PCN-A", "100.00", date(2026, 6, 5),
state=ClaimState.PAID)
# Match row already exists from prior reconcile.
s.add(Match(