|
11 | 11 |
|
12 | 12 | from ctms.app import app, get_pubsub_claim |
13 | 13 | from ctms.models import PendingAcousticRecord |
| 14 | +from tests.unit.sample_data import fake_stripe_id |
14 | 15 | from tests.unit.test_ingest_stripe import ( |
15 | 16 | stripe_customer_data, |
16 | 17 | stripe_invoice_data, |
@@ -137,6 +138,21 @@ def test_api_post_conflicting_fxa_id(dbsession, client, contact_with_stripe_cust |
137 | 138 | assert log["fxa_id_conflict"] == data["description"] |
138 | 139 |
|
139 | 140 |
|
| 141 | +def test_api_post_deleted_new_customer(dbsession, client): |
| 142 | + """A new customer who starts out deleted is skipped.""" |
| 143 | + stripe_id = fake_stripe_id("cus", "new_but_deleted") |
| 144 | + data = {"deleted": True, "id": stripe_id, "object": "customer"} |
| 145 | + with capture_logs() as caplog: |
| 146 | + resp = client.post("/stripe", json=data) |
| 147 | + assert resp.status_code == 200 |
| 148 | + assert resp.json() == {"status": "OK"} |
| 149 | + assert len(caplog) == 1 |
| 150 | + log = caplog[0] |
| 151 | + assert log["ingest_actions"] == { |
| 152 | + "skipped": [f"customer:{stripe_id}"], |
| 153 | + } |
| 154 | + |
| 155 | + |
140 | 156 | def test_api_post_stripe_from_pubsub_customer( |
141 | 157 | dbsession, pubsub_client, example_contact |
142 | 158 | ): |
@@ -304,3 +320,18 @@ def test_api_post_pubsub_conflicting_fxa_id( |
304 | 320 | "deleted": [f"customer:{old_id}"], |
305 | 321 | } |
306 | 322 | assert log["fxa_id_conflict"] == data["description"] |
| 323 | + |
| 324 | + |
| 325 | +def test_api_post_stripe_from_pubsub_deleted_new_customer(dbsession, pubsub_client): |
| 326 | + """A new customer who starts out deleted is skipped.""" |
| 327 | + stripe_id = fake_stripe_id("cus", "new_but_deleted") |
| 328 | + data = {"deleted": True, "id": stripe_id, "object": "customer"} |
| 329 | + with capture_logs() as caplog: |
| 330 | + resp = pubsub_client.post("/stripe_from_pubsub", json=pubsub_wrap(data)) |
| 331 | + assert resp.status_code == 200 |
| 332 | + assert resp.json() == {"status": "OK", "count": 1} |
| 333 | + assert len(caplog) == 1 |
| 334 | + log = caplog[0] |
| 335 | + assert log["ingest_actions"] == { |
| 336 | + "skipped": [f"customer:{stripe_id}"], |
| 337 | + } |
0 commit comments