From cf621394ad6845d37c66c68c35da384ab8e471b8 Mon Sep 17 00:00:00 2001 From: credelinghuys Date: Wed, 8 Jul 2026 13:51:33 -0400 Subject: [PATCH] CASH-2934: Normalize phone number --- .../save-progress-popup-question.spec.js | 2 +- src/helpers/save-progress-popup-contact-helper.js | 14 +++++++++++++- .../save-progress-popup-contact-helper.spec.js | 14 +++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/fmg-components/save-progress-popup-question/save-progress-popup-question.spec.js b/src/fmg-components/save-progress-popup-question/save-progress-popup-question.spec.js index ad42fa617..9979a4162 100644 --- a/src/fmg-components/save-progress-popup-question/save-progress-popup-question.spec.js +++ b/src/fmg-components/save-progress-popup-question/save-progress-popup-question.spec.js @@ -210,7 +210,7 @@ describe("save-progress-popup-question ", () => { expect(dispatchStoreAction).toHaveBeenCalledWith( storeActions.SAVE_PHONE_NUMBER, - "555-123-4567", + "5551234567", false ); expect(dispatchStoreAction).not.toHaveBeenCalledWith( diff --git a/src/helpers/save-progress-popup-contact-helper.js b/src/helpers/save-progress-popup-contact-helper.js index 2853d8c8e..d19d1611f 100644 --- a/src/helpers/save-progress-popup-contact-helper.js +++ b/src/helpers/save-progress-popup-contact-helper.js @@ -10,12 +10,24 @@ export function isPhoneContactMethod(contactMethod) { return contactMethod === saveProgressPopupContactMethods.PHONE; } +export function normalizePhoneNumberForStore(phoneNumber) { + if (!phoneNumber) { + return phoneNumber; + } + + return String(phoneNumber).replace(/\D/g, ""); +} + export async function saveProgressPopupContactToStore( dispatchStoreAction, { contactMethod, userInput, smsConsent, pageName } ) { if (isPhoneContactMethod(contactMethod)) { - await dispatchStoreAction(storeActions.SAVE_PHONE_NUMBER, userInput, false); + await dispatchStoreAction( + storeActions.SAVE_PHONE_NUMBER, + normalizePhoneNumberForStore(userInput), + false + ); await dispatchStoreAction(storeActions.SAVE_IS_SMS_OPT_IN, smsConsent.transactional, false); const existingPageData = store.getters.pageData(pageName) ?? {}; diff --git a/src/helpers/save-progress-popup-contact-helper.spec.js b/src/helpers/save-progress-popup-contact-helper.spec.js index 5935874d9..a2a252c01 100644 --- a/src/helpers/save-progress-popup-contact-helper.spec.js +++ b/src/helpers/save-progress-popup-contact-helper.spec.js @@ -2,6 +2,7 @@ import { storeActions } from "@/constants/store-actions"; import store from "@/store"; import { isPhoneContactMethod, + normalizePhoneNumberForStore, saveProgressPopupContactMethods, saveProgressPopupContactToStore, } from "./save-progress-popup-contact-helper"; @@ -28,6 +29,17 @@ describe("save-progress-popup-contact-helper", () => { }); }); + describe("normalizePhoneNumberForStore", () => { + it("should strip non-digit characters from a formatted phone number", () => { + expect(normalizePhoneNumberForStore("555-123-4567")).toBe("5551234567"); + }); + + it("should return empty values unchanged", () => { + expect(normalizePhoneNumberForStore("")).toBe(""); + expect(normalizePhoneNumberForStore(null)).toBe(null); + }); + }); + describe("saveProgressPopupContactToStore", () => { it("should save phone number and persist sms consent on phone tab", async () => { const dispatchStoreAction = jest.fn().mockResolvedValue(undefined); @@ -42,7 +54,7 @@ describe("save-progress-popup-contact-helper", () => { expect(dispatchStoreAction).toHaveBeenCalledWith( storeActions.SAVE_PHONE_NUMBER, - "555-123-4567", + "5551234567", false ); expect(dispatchStoreAction).not.toHaveBeenCalledWith(