From db1222a53e64ce0faef7d2f6a43e5ad7a8519842 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 12:53:29 -0400 Subject: [PATCH 01/11] Updated logic for initial savesession call to create referral. Move it to beforeEach to make it snchronous. --- src/helpers/order-helper.js | 1 + src/router/index.js | 20 +++++++++++++++++--- src/router/router.afterEach.spec.js | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/helpers/order-helper.js b/src/helpers/order-helper.js index 449f79b6..55a12a9d 100644 --- a/src/helpers/order-helper.js +++ b/src/helpers/order-helper.js @@ -26,6 +26,7 @@ export async function saveSession({ shouldAwaitSaveSessionQueue = false, submitA // This should await anytime the referral number is not set, or the shouldAwaitSaveSessionQueue is set to true. if (!store.order.referralNumber || shouldAwaitSaveSessionQueue) { + console.log('Awaiting save session promise', store.order.referralNumber, shouldAwaitSaveSessionQueue); await saveSessionPromise; } } diff --git a/src/router/index.js b/src/router/index.js index 0c33cae4..6dfd0265 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -155,6 +155,19 @@ router.beforeEach(async (to, from) => { showIssLoadingModal(true); } + const callSaveSession = (to.name === issPageValues.VEHICLE_SELECTION || to.name === issPageValues.POLICY_VEHICLES); + if ( callSaveSession ) { + // Forcing a synchronous savesession call here to create the referral for the first time. + // AfterEach does not support synchronous calls that block navigation. Which is why this is in the beforeEach method. + // This only needs to be called once in a certain location, all other saveession calls are async in afterEach (except the last one on order submission) + // NOTE: This call should be creating the referral number. After this point in the site flow, referral number is critical for several pieces of logic and logging. + // Thereforce, we want to force a bailout here if it errors out. + console.log('Saving session with waiting coming from duplicate check page.'); + showIssLoadingModal(true); + await saveSession({ shouldAwaitSaveSessionQueue: true,bailoutOnError: true }); + showIssLoadingModal(false); + } + const toQueryPage = to.query?.issPage; const notToPayInAdvanceReturn = toQueryPage !== issPageValues.PAYMENT_RETURN; const isInIframe = window !== window.top || fromQueryPage === issPageValues.PAYMENT_PAGE; @@ -204,10 +217,11 @@ router.afterEach(async (to, from) => { to.state?.[routerParams.SKIP_SAVE_SESSION] ?? router.options.history.state?.[routerParams.SKIP_SAVE_SESSION] ); - if (from.name !== undefined && !skipSaveSession && !store.hasSubmittedOrder()) { - await saveSession({ bailoutOnError: from.name === issPageValues.ENTRY_PAGE}); - } + if (from.name !== undefined && !skipSaveSession && !store.hasSubmittedOrder()) { + await saveSession({ bailoutOnError: false}); + } + document.title = routerTitles[to.query.issPage] || 'Safelite Solutions®'; if (shouldRunExperiments) { diff --git a/src/router/router.afterEach.spec.js b/src/router/router.afterEach.spec.js index 2a2185dc..6f2aee8f 100644 --- a/src/router/router.afterEach.spec.js +++ b/src/router/router.afterEach.spec.js @@ -110,6 +110,6 @@ describe('Router afterEach skipSaveSession', () => { ); expect(saveSession).toHaveBeenCalledTimes(1); - expect(saveSession).toHaveBeenCalledWith({ bailoutOnError: true }); + expect(saveSession).toHaveBeenCalledWith({ bailoutOnError: false }); }); }); \ No newline at end of file From 585a975a9d3b451935269659a53b372239f8003e Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 13:20:25 -0400 Subject: [PATCH 02/11] Removed debugging statements. --- src/helpers/order-helper.js | 1 - src/router/index.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/helpers/order-helper.js b/src/helpers/order-helper.js index 55a12a9d..449f79b6 100644 --- a/src/helpers/order-helper.js +++ b/src/helpers/order-helper.js @@ -26,7 +26,6 @@ export async function saveSession({ shouldAwaitSaveSessionQueue = false, submitA // This should await anytime the referral number is not set, or the shouldAwaitSaveSessionQueue is set to true. if (!store.order.referralNumber || shouldAwaitSaveSessionQueue) { - console.log('Awaiting save session promise', store.order.referralNumber, shouldAwaitSaveSessionQueue); await saveSessionPromise; } } diff --git a/src/router/index.js b/src/router/index.js index 6dfd0265..60a3fbc6 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -162,7 +162,6 @@ router.beforeEach(async (to, from) => { // This only needs to be called once in a certain location, all other saveession calls are async in afterEach (except the last one on order submission) // NOTE: This call should be creating the referral number. After this point in the site flow, referral number is critical for several pieces of logic and logging. // Thereforce, we want to force a bailout here if it errors out. - console.log('Saving session with waiting coming from duplicate check page.'); showIssLoadingModal(true); await saveSession({ shouldAwaitSaveSessionQueue: true,bailoutOnError: true }); showIssLoadingModal(false); From 4ba32ac22efaec8d05f2ac222fb088bb61116edb Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 13:26:22 -0400 Subject: [PATCH 03/11] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/router/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 60a3fbc6..6e2c858f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -155,8 +155,8 @@ router.beforeEach(async (to, from) => { showIssLoadingModal(true); } - const callSaveSession = (to.name === issPageValues.VEHICLE_SELECTION || to.name === issPageValues.POLICY_VEHICLES); - if ( callSaveSession ) { +const callSaveSession = !useMainStore().order?.referralNumber && (to.name === issPageValues.VEHICLE_SELECTION || to.name === issPageValues.POLICY_VEHICLES); +if (callSaveSession) { // Forcing a synchronous savesession call here to create the referral for the first time. // AfterEach does not support synchronous calls that block navigation. Which is why this is in the beforeEach method. // This only needs to be called once in a certain location, all other saveession calls are async in afterEach (except the last one on order submission) From 93ea133d8abd332f5a238f4e1cd64ab572d03d4c Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 13:26:37 -0400 Subject: [PATCH 04/11] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/router/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/index.js b/src/router/index.js index 6e2c858f..9a130dc2 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -159,7 +159,7 @@ const callSaveSession = !useMainStore().order?.referralNumber && (to.name === is if (callSaveSession) { // Forcing a synchronous savesession call here to create the referral for the first time. // AfterEach does not support synchronous calls that block navigation. Which is why this is in the beforeEach method. - // This only needs to be called once in a certain location, all other saveession calls are async in afterEach (except the last one on order submission) + // This only needs to be called once in a certain location, all other saveSession calls are async in afterEach (except the last one on order submission) // NOTE: This call should be creating the referral number. After this point in the site flow, referral number is critical for several pieces of logic and logging. // Thereforce, we want to force a bailout here if it errors out. showIssLoadingModal(true); From 54b8ee164724a06a2c5dad143fd4e24fbe7ab9c9 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 13:27:00 -0400 Subject: [PATCH 05/11] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/router/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/index.js b/src/router/index.js index 9a130dc2..1b33bc25 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -163,7 +163,7 @@ if (callSaveSession) { // NOTE: This call should be creating the referral number. After this point in the site flow, referral number is critical for several pieces of logic and logging. // Thereforce, we want to force a bailout here if it errors out. showIssLoadingModal(true); - await saveSession({ shouldAwaitSaveSessionQueue: true,bailoutOnError: true }); + await saveSession({ shouldAwaitSaveSessionQueue: true, bailoutOnError: true }); showIssLoadingModal(false); } From 6c14ac36d03a303163b239eb4e0bb0bd9fad5c38 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 13:27:12 -0400 Subject: [PATCH 06/11] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/router/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/index.js b/src/router/index.js index 1b33bc25..a76da10a 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -161,7 +161,7 @@ if (callSaveSession) { // AfterEach does not support synchronous calls that block navigation. Which is why this is in the beforeEach method. // This only needs to be called once in a certain location, all other saveSession calls are async in afterEach (except the last one on order submission) // NOTE: This call should be creating the referral number. After this point in the site flow, referral number is critical for several pieces of logic and logging. - // Thereforce, we want to force a bailout here if it errors out. + // Therefore, we want to force a bailout here if it errors out. showIssLoadingModal(true); await saveSession({ shouldAwaitSaveSessionQueue: true, bailoutOnError: true }); showIssLoadingModal(false); From 0379010c1dd198e45af09210ebeef1c9e627dca7 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 13:27:30 -0400 Subject: [PATCH 07/11] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/router/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/index.js b/src/router/index.js index a76da10a..ec30d5dc 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -218,7 +218,7 @@ router.afterEach(async (to, from) => { ); if (from.name !== undefined && !skipSaveSession && !store.hasSubmittedOrder()) { - await saveSession({ bailoutOnError: false}); + await saveSession({ bailoutOnError: false }); } document.title = routerTitles[to.query.issPage] || 'Safelite Solutions®'; From 4cc8b1446bc7523a1b6ec0a4be828d6d2cbe8114 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 13:40:03 -0400 Subject: [PATCH 08/11] Adding some error handling. --- src/router/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index ec30d5dc..a45182d6 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -163,8 +163,12 @@ if (callSaveSession) { // NOTE: This call should be creating the referral number. After this point in the site flow, referral number is critical for several pieces of logic and logging. // Therefore, we want to force a bailout here if it errors out. showIssLoadingModal(true); - await saveSession({ shouldAwaitSaveSessionQueue: true, bailoutOnError: true }); - showIssLoadingModal(false); + try { + await saveSession({ shouldAwaitSaveSessionQueue: true, bailoutOnError: true }); + } + finally { + showIssLoadingModal(false); + } } const toQueryPage = to.query?.issPage; From 085abd1f3a8814564fb6d4ff5a4142b8b8f6f0a7 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 14:01:58 -0400 Subject: [PATCH 09/11] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/router/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index a45182d6..dcfc11af 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -155,8 +155,8 @@ router.beforeEach(async (to, from) => { showIssLoadingModal(true); } -const callSaveSession = !useMainStore().order?.referralNumber && (to.name === issPageValues.VEHICLE_SELECTION || to.name === issPageValues.POLICY_VEHICLES); -if (callSaveSession) { + const callSaveSession = !useMainStore().order?.referralNumber && (to.name === issPageValues.VEHICLE_SELECTION || to.name === issPageValues.POLICY_VEHICLES); + if (callSaveSession) { // Forcing a synchronous savesession call here to create the referral for the first time. // AfterEach does not support synchronous calls that block navigation. Which is why this is in the beforeEach method. // This only needs to be called once in a certain location, all other saveSession calls are async in afterEach (except the last one on order submission) From abdda18b4ab7394fce87078b9f5bdc83c4b4c067 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 14:06:47 -0400 Subject: [PATCH 10/11] Added unit tests for beforeEach router method. --- src/router/router.beforeEach.spec.js | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/router/router.beforeEach.spec.js diff --git a/src/router/router.beforeEach.spec.js b/src/router/router.beforeEach.spec.js new file mode 100644 index 00000000..85c9160e --- /dev/null +++ b/src/router/router.beforeEach.spec.js @@ -0,0 +1,72 @@ +import issPageValues from '@/router/router-constants/issPage-values'; + +let router; +let saveSession; +let showIssLoadingModal; +let mockBeforeEachHandler; +let mockStore; + +jest.mock('vue-router', () => ({ + createWebHistory: jest.fn(() => ({ state: {} })), + createRouter: jest.fn((options) => ({ + options, + beforeEach: jest.fn((handler) => { + mockBeforeEachHandler = handler; + }), + afterEach: jest.fn(), + addRoute: jest.fn(), + getRoutes: jest.fn(() => []), + hasRoute: jest.fn(() => true), + push: jest.fn(), + go: jest.fn(), + currentRoute: { value: { query: { issPage: 'welcome-page' } } } + })) +})); + +jest.mock('@/helpers/order-helper.js', () => ({ + saveSession: jest.fn(() => Promise.resolve()) +})); + +jest.mock('@/helpers/loading-modal-helper', () => jest.fn()); + +jest.mock('@/store', () => ({ + useMainStore: jest.fn(() => mockStore) +})); + +describe('Router beforeEach callSaveSession', () => { + beforeAll(() => { + router = require('@/router/').default; + ({ saveSession } = require('@/helpers/order-helper.js')); + const loadingModalModule = require('@/helpers/loading-modal-helper'); + showIssLoadingModal = loadingModalModule.default || loadingModalModule; + }); + + beforeEach(() => { + mockStore = { + order: {}, + isBailout: false + }; + + jest.clearAllMocks(); + }); + + it('calls saveSession synchronously when entering vehicle-selection without a referral number', async () => { + const result = await mockBeforeEachHandler( + { + name: issPageValues.VEHICLE_SELECTION, + query: { issPage: issPageValues.VEHICLE_SELECTION }, + href: '/?issPage=vehicle-selection' + }, + { + name: issPageValues.WELCOME_PAGE, + query: { issPage: issPageValues.WELCOME_PAGE } + } + ); + + expect(saveSession).toHaveBeenCalledTimes(1); + expect(saveSession).toHaveBeenCalledWith({ shouldAwaitSaveSessionQueue: true, bailoutOnError: true }); + expect(showIssLoadingModal).toHaveBeenNthCalledWith(1, true); + expect(showIssLoadingModal).toHaveBeenNthCalledWith(2, false); + expect(result).toBe(true); + }); +}); \ No newline at end of file From 5a8c2f1cd3f293ebe2ed5bbd03b6f6f191bfd5c2 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 14:09:36 -0400 Subject: [PATCH 11/11] Refactoring. --- src/router/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index dcfc11af..25400a08 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -150,12 +150,14 @@ const router = createRouter({ }); router.beforeEach(async (to, from) => { + const store = useMainStore(); const fromQueryPage = from.query?.issPage; + if (fromQueryPage === undefined) { showIssLoadingModal(true); } - const callSaveSession = !useMainStore().order?.referralNumber && (to.name === issPageValues.VEHICLE_SELECTION || to.name === issPageValues.POLICY_VEHICLES); + const callSaveSession = !store.order?.referralNumber && (to.name === issPageValues.VEHICLE_SELECTION || to.name === issPageValues.POLICY_VEHICLES); if (callSaveSession) { // Forcing a synchronous savesession call here to create the referral for the first time. // AfterEach does not support synchronous calls that block navigation. Which is why this is in the beforeEach method. @@ -188,7 +190,6 @@ router.beforeEach(async (to, from) => { return false; } - const store = useMainStore(); // Prevent navigating backwards if we enter a bailout that we are not allowed to go back on if (store.isBailout && from.name === issPageValues.BAILOUT_PAGE && to.name !== 'root' && to.name !== issPageValues.CONTACT_CONFIRMATION && !canBailoutNavigateBack()) {