Skip to content

fix(submit): normalize SMS opt-in so SFDC Mobile Opt Out isn't flipped - #86

Merged
dylandepass merged 1 commit into
mainfrom
fix-sms-optin-normalization
Aug 23, 2026
Merged

fix(submit): normalize SMS opt-in so SFDC Mobile Opt Out isn't flipped#86
dylandepass merged 1 commit into
mainfrom
fix-sms-optin-normalization

Conversation

@dylandepass

Copy link
Copy Markdown
Contributor

Problem

SFDC's Mobile Opt Out flag was flip-flopped for SMS consent (defects 30 and 20, aemsites/vitamix#828):

  • Defect 30 ($25 newsletter popup): opting in left Mobile Opt Out checked; leaving it unchecked left it blank — both backwards.
  • Defect 20 (product registration): a checked SMS opt-in box still produced Mobile Opt Out checked.

Root cause

callNewsletterApi mapped the SMS flag with logic that didn't match what the forms actually submit:

  • An HTML checkbox only appears in the payload when ticked, and its value is the checkbox's value attribute. Registration sends smsOptIn: "yes"; the newsletter popup sends its entire consent sentence as the value.
  • The old code only honored typeof smsOptIn === 'boolean' (so the string values were dropped and SMSOptIn stayed false) and, when the flag was absent, defaulted to opted-in (SMSOptIn = true). Net effect: checked → false, unchecked → true.

Since EBS treats SMSOptIn as opt-in and SFDC stores its inverse as Mobile Opt Out, the flag came out inverted.

Fix

  • Add isOptedIn() that normalizes the flag by checkbox semantics: any present, non-empty, non-negative value (string or true) counts as opt-in; absent/empty/false/no/0/off count as not opted in. Consent is never inferred — an absent flag is treated as opted out.
  • Set payload.SMSOptIn = isOptedIn(data.smsOptIn) unconditionally (outside the mobile block) so product registrations — which send phone, not mobile — still carry the correct flag.

Backend-only; no storefront change is required because isOptedIn is robust to whatever encoding the frontend sends today.

Testing

  • npm run lint — pass
  • npm test — 260 passed. New coverage for the SMS path (previously untested): the newsletter popup's full consent-sentence value → SMSOptIn: true; "yes"/"on"/"true"/"1" → true; absent/empty/no/false/0/off → false; booleans honored; and the registration side-effect forwarding "yes" → true / unchecked → false.

Notes

  • Out of scope: if a user checks SMS opt-in but leaves the email-marketing box unchecked on registration, the SMS preference never reaches EBS (the subscribe only fires on marketingOptIn). That's a separate "never sent" gap, not the flip-flop these defects describe.

The newsletter and product-registration SMS checkbox arrives as a string (the $25 popup submits its entire consent sentence as the value) or is absent when unchecked, but callNewsletterApi only honored booleans and defaulted a missing flag to opted-in. That inverted SFDC's Mobile Opt Out: opting in wrote SMSOptIn false (opt-out checked) and leaving it unchecked wrote true. Normalize the flag through isOptedIn and set SMSOptIn unconditionally so registrations (which send phone, not mobile) also carry it, fixing the flip-flop reported in defects 30 and 20 (aemsites/vitamix#828).
@dylandepass
dylandepass merged commit 49f52c3 into main Aug 23, 2026
3 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.3.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant