fix(submit): normalize SMS opt-in so SFDC Mobile Opt Out isn't flipped - #86
Merged
Conversation
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).
|
🎉 This PR is included in version 1.3.7 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
Problem
SFDC's Mobile Opt Out flag was flip-flopped for SMS consent (defects 30 and 20, aemsites/vitamix#828):
Root cause
callNewsletterApimapped the SMS flag with logic that didn't match what the forms actually submit:valueattribute. Registration sendssmsOptIn: "yes"; the newsletter popup sends its entire consent sentence as the value.typeof smsOptIn === 'boolean'(so the string values were dropped andSMSOptInstayedfalse) and, when the flag was absent, defaulted to opted-in (SMSOptIn = true). Net effect: checked → false, unchecked → true.Since EBS treats
SMSOptInas opt-in and SFDC stores its inverse as Mobile Opt Out, the flag came out inverted.Fix
isOptedIn()that normalizes the flag by checkbox semantics: any present, non-empty, non-negative value (string ortrue) counts as opt-in; absent/empty/false/no/0/offcount as not opted in. Consent is never inferred — an absent flag is treated as opted out.payload.SMSOptIn = isOptedIn(data.smsOptIn)unconditionally (outside themobileblock) so product registrations — which sendphone, notmobile— still carry the correct flag.Backend-only; no storefront change is required because
isOptedInis robust to whatever encoding the frontend sends today.Testing
npm run lint— passnpm 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
marketingOptIn). That's a separate "never sent" gap, not the flip-flop these defects describe.