Skip to content

Commit

Permalink
Ref #548: make basket_token field optional in contact responses body (#…
Browse files Browse the repository at this point in the history
…551)

* fix: fix IdentityResponse fields

* feat: test deleting contacts that set nothing but a primary_email
  • Loading branch information
ahoneiser authored Feb 17, 2023
1 parent d69a90a commit 23bf392
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ctms/schemas/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_api_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 23bf392

Please sign in to comment.