Skip to content

Commit

Permalink
Fix #605: Adjust Basket integration test and workflow docs (#753)
Browse files Browse the repository at this point in the history
* Fix #605: Adjust Basket integration test and workflow docs

* Add note about legacy fields
  • Loading branch information
leplatrem authored Jul 12, 2023
1 parent 3e010db commit ee66b2d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
27 changes: 17 additions & 10 deletions docs/diagrams/bedrock_basket_ctms_acoustic.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ sequenceDiagram
%% https://github.com/mozilla/bedrock/blob/ecba76406ed35c04d35532c3ed7562b09d65fabe/bedrock/products/views.py#L68-L87
Basket->>Basket Task: Spawn task
%% https://github.com/mozmeao/basket/blob/77f98bb63c70cecbb3ec8d69b512df67abce8c63/basket/news/views.py#L681
%% https://github.com/mozmeao/basket/blob/2023-07-06/basket/news/views.py#L681
Basket-->>Bedrock: [status]
Bedrock-->>Visitor: .
rect rgb(240,240,240)
Basket Task->>Basket Task: Process data
%% https://github.com/mozmeao/basket/blob/77f98bb63c70cecbb3ec8d69b512df67abce8c63/basket/news/backends/ctms.py#L199
%% https://github.com/mozmeao/basket/blob/2023-07-06/basket/news/backends/ctms.py#L263
Basket Task->>CTMS: update(token, email_id, newsletters, fpn_platform, fpn_country)
%% https://github.com/mozmeao/basket/blob/77f98bb63c70cecbb3ec8d69b512df67abce8c63/basket/news/tasks.py#L654
%% https://github.com/mozilla-it/ctms-api/blob/6f903aeb90b65c170f34485e1cc4b3755839daaf/ctms/crud.py#L563
%% https://github.com/mozmeao/basket/blob/2023-07-06/basket/news/tasks.py#L401
%% https://github.com/mozilla-it/ctms-api/blob/v2.1.0/ctms/crud.py#L579
CTMS-->>Basket Task: .
end
rect rgb(240,240,240)
CTMS Sync->>CTMS Sync: Flatten fields
%% https://github.com/mozilla-it/ctms-api/blob/cde9694e2992c2c9d8315ba9c6954c50a6facf37/ctms/acoustic_service.py#L62
%% https://github.com/mozilla-it/ctms-api/blob/v2.1.0/ctms/acoustic_service.py#L141
CTMS Sync->>Acoustic: sync_records()
%% https://github.com/mozilla-it/ctms-api/blob/cde9694e2992c2c9d8315ba9c6954c50a6facf37/ctms/bin/acoustic_sync.py
%% https://github.com/mozilla-it/ctms-api/blob/v2.1.0/ctms/bin/acoustic_sync.py
end
```

Expand Down Expand Up @@ -119,10 +119,17 @@ CTMS create contact ([`POST /ctms`](https://github.com/mozilla-it/ctms-api/blob/
"lang": "fr",
}
],
"vpn_waitlist": {
"geo": "fr",
"platform": "ios,mac",
},
"waitlist": [
{
"name": "vpn",
"subscribed": True,
"source": "https://vpn.mozilla.org/fr",
"fields": {
"geo": "fr",
"platform": "ios,mac"
}
}
]
}
```

Expand Down
25 changes: 18 additions & 7 deletions tests/integration/test_basket_waitlist_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def fetch_created():
"unsub_reason": None,
}
]
# Legacy (read-only) fields.
assert contact_details["vpn_waitlist"] == {
"geo": "us",
"platform": "ios,android",
Expand All @@ -150,17 +151,18 @@ def fetch_created():
f"{settings.ctms_server_url}/ctms/{email_id}",
headers=ctms_headers,
json={
"vpn_waitlist": {"geo": "fr", "platform": "linux"},
"waitlists": [
{
"name": "vpn",
"fields": {"geo": "fr", "platform": "linux"},
}
],
},
)
resp.raise_for_status()
# Request the full contact details again.
contact_details = ctms_fetch(email, ctms_headers)
assert contact_details["newsletters"] == []
assert contact_details["vpn_waitlist"] == {
"geo": "fr",
"platform": "linux",
}
assert contact_details["waitlists"] == [
{
"name": "vpn",
Expand All @@ -173,6 +175,11 @@ def fetch_created():
"unsub_reason": None,
}
]
# Legacy (read-only) fields.
assert contact_details["vpn_waitlist"] == {
"geo": "fr",
"platform": "linux",
}

# 4. Unsubscribe via Basket
basket_token = contact_details["email"]["basket_token"]
Expand All @@ -185,6 +192,7 @@ def check_updated():
contact_details = ctms_fetch(email, ctms_headers)
assert contact_details["newsletters"] == []
assert not contact_details["waitlists"][0]["subscribed"]
# Legacy (read-only) fields.
assert contact_details["vpn_waitlist"] == {
"geo": None,
"platform": None,
Expand Down Expand Up @@ -225,6 +233,7 @@ def fetch_created():
"unsub_reason": None,
}
]
# Legacy (read-only) fields.
assert contact_details["relay_waitlist"] == {
"geo": "es",
}
Expand Down Expand Up @@ -267,9 +276,9 @@ def check_subscribed():
"unsub_reason": None,
},
]
# Legacy (read-only) fields.
# If multiple `relay-` waitlists are present, the `geo` field of the
# first waitlist is set as the value of `relay_waitlist["geo"]`. This
# property is intended for legacy consumers
# first waitlist is set as the value of `relay_waitlist["geo"]`.
assert contact_details["relay_waitlist"] == {
"geo": "es",
}
Expand Down Expand Up @@ -307,6 +316,7 @@ def check_unsubscribed():
"unsub_reason": None,
},
]
# Legacy (read-only) fields.
# relay_waitlist geo is pulled from the remaining waitlist.
assert contact_details["relay_waitlist"] == {
"geo": "fr",
Expand All @@ -325,5 +335,6 @@ def check_unsubscribed_last():

contact_details = check_unsubscribed_last()
assert contact_details["newsletters"] == []
# Legacy (read-only) fields.
# Relay attribute is now empty
assert contact_details["relay_waitlist"] == {"geo": None}

0 comments on commit ee66b2d

Please sign in to comment.