Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref #548: make basket_token field optional in contact responses body #551

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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