diff --git a/ctms/schemas/contact.py b/ctms/schemas/contact.py index ffc71f0c..383924c6 100644 --- a/ctms/schemas/contact.py +++ b/ctms/schemas/contact.py @@ -282,7 +282,7 @@ class IdentityResponse(BaseModel): email_id: UUID primary_email: str - basket_token: UUID + basket_token: Optional[UUID] = None sfdc_id: Optional[str] = None mofo_contact_id: Optional[str] = None mofo_email_id: Optional[str] = None diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index df2aa1fb..f93b3279 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -45,7 +45,11 @@ StripeSubscriptionCreateSchema, StripeSubscriptionItemCreateSchema, ) -from tests.unit.sample_data import SAMPLE_CONTACTS, SAMPLE_STRIPE_DATA +from tests.unit.sample_data import ( + SAMPLE_CONTACTS, + SAMPLE_MOST_MINIMAL, + SAMPLE_STRIPE_DATA, +) MY_FOLDER = os.path.dirname(__file__) TEST_FOLDER = os.path.dirname(MY_FOLDER) @@ -127,6 +131,20 @@ def end_savepoint(session, transaction): transaction.rollback() +@pytest.fixture +def most_minimal_contact(dbsession): + email_id = UUID("62d8d3c6-95f3-4ed6-b176-7f69acff22f6") + contact = SAMPLE_MOST_MINIMAL + assert contact.amo is None + assert contact.fxa is None + assert contact.mofo is None + assert len(contact.waitlists) == 0 + assert contact.email.basket_token is None + create_contact(dbsession, email_id, contact, get_metrics()) + dbsession.commit() + return contact + + @pytest.fixture def minimal_contact(dbsession): email_id = UUID("93db83d4-4119-4e0c-af87-a713786fa81d") diff --git a/tests/unit/sample_data.py b/tests/unit/sample_data.py index f5aca344..7ea605cf 100644 --- a/tests/unit/sample_data.py +++ b/tests/unit/sample_data.py @@ -15,6 +15,14 @@ WaitlistSchema, ) +# A contact that only sets primary_email +SAMPLE_MOST_MINIMAL = ContactSchema( + email=EmailSchema( + email_id=UUID("62d8d3c6-95f3-4ed6-b176-7f69acff22f6"), + primary_email="ctms-most-minimal-user@example.com", + ), +) + # A contact that has just some of the fields entered SAMPLE_MINIMAL = ContactSchema( email=EmailSchema( diff --git a/tests/unit/test_api_delete.py b/tests/unit/test_api_delete.py index 0607c2a5..876af282 100644 --- a/tests/unit/test_api_delete.py +++ b/tests/unit/test_api_delete.py @@ -12,3 +12,11 @@ def test_delete_contact_by_primary_email(client, maximal_contact): assert resp.status_code == 200 resp = client.delete(f"/ctms/{primary_email}") assert resp.status_code == 404 + + +def test_delete_contact_by_primary_email_with_basket_token_unset( + client, most_minimal_contact +): + primary_email = most_minimal_contact.email.primary_email + resp = client.delete(f"/ctms/{primary_email}") + assert resp.status_code == 200