test: add automated tests for newsletter logic - #689
Draft
wpf500 wants to merge 4 commits into
Draft
Conversation
Keep contacts in memory and apply add/remove/replace group changes the way Mailchimp does, so partial updates no longer wipe or overwrite the locally stored groups. Unknown group IDs are rejected like Mailchimp's invalid interest ID response. Generated with AI Co-Authored-By: An LLM
Add API tests for the contact newsletter-groups endpoints, callout opt-in and admin group updates, plus a browser test for the account subscriptions tab. Generated with AI Co-Authored-By: An LLM
The client's cookie store is shared between all instances in a process, so logging in as several contacts invalidated each other's sessions. Generated with AI Co-Authored-By: An LLM
The account subscriptions tab only exists in the new frontend, which the router serves behind the beabee_frontend cookie. Generated with AI Co-Authored-By: An LLM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds automated coverage for the newsletter group subscribe/unsubscribe paths introduced in #679, and fixes the test newsletter provider so those paths can be tested against it.
Why
#679 changes how newsletter groups are synced: groups are only sent to the provider when an update explicitly includes them, and a new
add/removemode sends partial group updates so the provider's state isn't overwritten. Only the Mailchimp payload builder had unit tests; none of the service-level paths (self-service unsubscribe, callout opt-in, admin replace, retry limits, authorization) were covered end to end.Changes
fix(core): statefulTestProviderThe provider returned
contact.groups ?? []as the contact's new group state, so with thetestprovider aremoveof group X set the contact's groups to exactly[X], and a name change wiped all groups. It now keeps contacts in memory and appliesadd/remove/replacethe way Mailchimp does, including rejecting unknown group IDs withCantUpdateNewsletterGroupsError.NoneProvideris untouched since it has no groups.test: API tests (apps/e2e-api-tests, 13 tests)me) and as admin, empty list for a contact without groupsNone→ 500 instead of silent successContacts are created per test file and act via the admin API key plus
x-contact-idheader rather than cookie login: the client's cookie store is a static shared between all instances in a process, so multiple logins invalidate each other's sessions.test: browser test (apps/browser-tests)Member opens Account → Subscriptions, unsubscribes from one group, sees the notification, the list shrinks and stays shrunk after reload; an aborted
DELETEshows the error notification and keeps the group.ci:frontend-newindocker-compose.test.ymlThe test stack only built
apps/frontend-old. The subscriptions tab lives in the new frontend, which the router serves behind thebeabee_frontend=newcookie. The service is added to the test compose file and the new test sets the cookie; existing browser tests keep running against the old frontend. This adds one image build to the browser test job. Can be split out if you'd rather merge the infrastructure change separately.Not covered
Paths that depend on real Mailchimp behaviour still need a manual check against a test audience: the
profile updatewebhook round trip, email change keeping interests, and the compliance-state retry. Two provider-level edge cases (a group unknown locally surviving an update; a stale cached ID being healed by the refresh-and-retry onreplace) need the/dev/newsletter-groupsendpoint, which the existing integrations test already mutates globally, so they're left out to avoid cross-file races.Test runs
🤖 Generated with Claude Code