From 8d02ed32046564ea7cd35c5c1a6fe0a496fc0012 Mon Sep 17 00:00:00 2001 From: Tyler Date: Sat, 20 Jun 2026 15:47:35 -0600 Subject: [PATCH] test(store): 835 batch publishes remittance_written + activity_recorded --- backend/tests/test_store.py | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/backend/tests/test_store.py b/backend/tests/test_store.py index d10d23f..17bbbc9 100644 --- a/backend/tests/test_store.py +++ b/backend/tests/test_store.py @@ -123,6 +123,52 @@ async def test_add_837_publishes_claim_written_and_activity_recorded_events(): assert "claimId" in ev +def test_add_835_publishes_remittance_written_and_activity_recorded_events(): + """835 batches publish remittance_written events (one per remit) and + activity_recorded events (one per activity row).""" + import asyncio + from cyclone.pubsub import EventBus + from cyclone.store import BatchRecord835 + + # Reuse the 835 result helper from test_store_reconcile.py. + from test_store_reconcile import _make_835_result, _make_remit_with_cas + + bus = EventBus() + remit_q = bus.subscribe(["remittance_written"]) + activity_q = bus.subscribe(["activity_recorded"]) + + cp = _make_remit_with_cas(remit_id="CLP-PUB", pcn="PCN-PUB") + rec = BatchRecord835( + id="b-835-1", kind="835", input_filename="test835.txt", + parsed_at=datetime(2026, 6, 19, 12, 0, tzinfo=timezone.utc), + result=_make_835_result([cp]), + ) + CycloneStore().add(rec, event_bus=bus) + + loop = asyncio.new_event_loop() + try: + remits = [] + for _ in range(1): + remits.append(loop.run_until_complete( + asyncio.wait_for(remit_q.__anext__(), timeout=0.5) + )) + activities = [] + for _ in range(1): + activities.append(loop.run_until_complete( + asyncio.wait_for(activity_q.__anext__(), timeout=0.5) + )) + finally: + loop.close() + + for ev in remits: + assert ev["_kind"] == "remittance_written" + assert ev["id"] == "PCN-PUB" + for ev in activities: + assert ev["_kind"] == "activity_recorded" + assert ev["kind"] == "remit_received" + assert ev["remittanceId"] == "PCN-PUB" + + def test_add_837_persists_batch_and_claims(): s = CycloneStore() rec = _make_batch_record()