diff --git a/src/helpers/order-helper.js b/src/helpers/order-helper.js index 97b685cd..f96b8a2a 100644 --- a/src/helpers/order-helper.js +++ b/src/helpers/order-helper.js @@ -34,15 +34,12 @@ export async function saveSession({ shouldAwaitSaveSessionQueue = false, submitA Will determine if to submitWorkOrder. TODO: Add more description to this */ -export async function submitWorkOrder({ - pageNameToLog, - submitAfterSave = false, - createDeleteStatusWorkOrderForPia = false -}) { +export async function submitWorkOrder({ submitType }) { + const store = useMainStore(); + store.resetSubmittedOrder(); await saveSession({ - pageNameToLog, shouldAwaitSaveSessionQueue: true, - submitAfterSave, - createDeleteStatusWorkOrderForPia + submitAfterSave: true }); + store.createSubmittedOrder(submitType); } diff --git a/src/layouts/bailout-page/bailout-page.spec.js b/src/layouts/bailout-page/bailout-page.spec.js index c3feda2c..5b0c68ee 100644 --- a/src/layouts/bailout-page/bailout-page.spec.js +++ b/src/layouts/bailout-page/bailout-page.spec.js @@ -436,19 +436,19 @@ describe('Bailout page', () => { }); }); describe('forwardButtonAction', () => { - test('should navigate to the next route', () => { + test('should navigate to the next route', async () => { // Arrange const { wrapper } = getMountedComponent(); // Act - wrapper.vm.forwardButtonAction(); + await wrapper.vm.forwardButtonAction(); // Assert expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith( wrapper.vm.navigationScenarios.CLICKED_FORWARD, wrapper.vm.$route, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); }); }); diff --git a/src/layouts/bailout-page/bailout-page.vue b/src/layouts/bailout-page/bailout-page.vue index 41ab3614..f13d9ba4 100644 --- a/src/layouts/bailout-page/bailout-page.vue +++ b/src/layouts/bailout-page/bailout-page.vue @@ -91,6 +91,7 @@ import canBailoutNavigateBack from '@/helpers/bailout-helper'; import BailoutCode from '@/constants/bailoutCode'; import issPageValues from '@/router/router-constants/issPage-values'; import MaskaFormattedMasks from '@/constants/maska-masks'; +import { saveSession } from '@/helpers/order-helper'; export default { name: 'bailout-page', @@ -200,13 +201,14 @@ export default { this.$route ); }, - forwardButtonAction() { + async forwardButtonAction() { this.mainStore.setBailoutContactInfo(this.bailoutPageModel); + await saveSession({ shouldAwaitSaveSessionQueue: true }); this.$router.navigate( this.navigationScenarios.CLICKED_FORWARD, this.$route, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); }, getBailoutPageModelFromStore() { diff --git a/src/layouts/entry-page/entry-page.vue b/src/layouts/entry-page/entry-page.vue index 29475742..8c4cfba3 100644 --- a/src/layouts/entry-page/entry-page.vue +++ b/src/layouts/entry-page/entry-page.vue @@ -38,7 +38,7 @@ export default { this.unauthorized = !isAuthorized; if (isAuthorized) { - await this.populateISSConfigValues(clientData); + this.populateISSConfigValues(clientData); if (clientData.parameters?.length > 0) { const finalParams = this.combineClientParameters(clientData.parameters, queryStringParams); @@ -100,7 +100,7 @@ export default { return { isAuthorized: authorized, clientData }; }, - async populateISSConfigValues(data) { + populateISSConfigValues(data) { this.mainStore.issConfig.clientName = data.accountName; this.mainStore.issConfig.clientDisplayName = data.accountName; // Defaults to use the client name. this.mainStore.issConfig.parentAccountNumber = data.parentAccountNumber; diff --git a/src/layouts/order-confirmation/order-confirmation.vue b/src/layouts/order-confirmation/order-confirmation.vue index 589dd87b..de1c896e 100644 --- a/src/layouts/order-confirmation/order-confirmation.vue +++ b/src/layouts/order-confirmation/order-confirmation.vue @@ -120,7 +120,6 @@ export default { }, mixins: [BaseFormMixin], async beforeRouteEnter(to, from, next) { - useMainStore().createSubmittedOrder(submitType.SAFELITE); // Call APIs const cmsContentPromise = fetchCmsContentForPage(to.query.issPage); diff --git a/src/layouts/payment-method/payment-method.vue b/src/layouts/payment-method/payment-method.vue index 589f6986..8f69cab3 100644 --- a/src/layouts/payment-method/payment-method.vue +++ b/src/layouts/payment-method/payment-method.vue @@ -91,6 +91,7 @@ import { AppointmentTypeStrings } from '@/constants/schedule-constants'; import VehicleBanner from '@/iss-components/vehicle-banner/vehicle-banner.vue'; import { submitWorkOrder } from '@/helpers/order-helper.js'; import { experimentSettings } from '@/constants/experiments'; +import submitType from '@/constants/submit-type'; export default { name: 'payment-method', @@ -300,12 +301,7 @@ export default { if (this.paymentMethod === paymentMethods.PAY_AT_TIME_OF_SERVICE) { try { - await submitWorkOrder({ - pageNameToLog: 'payment-method', - submitAfterSave: true - }).then(() => { - useMainStore().resetSubmittedOrder(); - + await submitWorkOrder({ submitType: submitType.SAFELITE }).then(() => { this.$router.navigate( this.navigationScenarios.CLICKED_FORWARD, this.$route diff --git a/src/layouts/payment-return/payment-return.vue b/src/layouts/payment-return/payment-return.vue index c7814569..b4df4190 100644 --- a/src/layouts/payment-return/payment-return.vue +++ b/src/layouts/payment-return/payment-return.vue @@ -124,12 +124,8 @@ export default { }, async saveAndSubmitWorkOrder() { // Final work order submit after returning from pay in advance. - useMainStore().resetSubmittedOrder(); try { - await submitWorkOrder({ - pageNameToLog: 'payment-return', - submitAfterSave: true - }); + await submitWorkOrder({ submitType: submitType.SAFELITE }); } catch (error) { console.error(`error: response from submit work order:${error.message}`); this.navigateOnPayInAdvanceError(); @@ -138,7 +134,6 @@ export default { } showIssLoadingModal(false); - useMainStore().createSubmittedOrder(submitType.SAFELITE); this.$router.navigate( this.navigationScenarios.PAY_IN_ADVANCE_SUCCESS, this.$route diff --git a/src/layouts/tpa-submit/tpa-submit.vue b/src/layouts/tpa-submit/tpa-submit.vue index 0c1593a5..200b92b1 100644 --- a/src/layouts/tpa-submit/tpa-submit.vue +++ b/src/layouts/tpa-submit/tpa-submit.vue @@ -354,11 +354,7 @@ export default { }, async forwardButtonAction() { try { - await submitWorkOrder({ - pageNameToLog: 'tpa-submit', - submitAfterSave: true - }).then(() => { - useMainStore().createSubmittedOrder(submitType.TPA); + await submitWorkOrder({ submitType: submitType.TPA }).then(() => { this.navigate(this.navigationScenarios.CLICKED_FORWARD); }).catch((submitError) => { useMainStore().setBailout(bailoutMessage.saveSessionError(submitError.data)); diff --git a/src/layouts/welcome-page/welcome-page.spec.js b/src/layouts/welcome-page/welcome-page.spec.js index b36edb9f..1fd64cfd 100644 --- a/src/layouts/welcome-page/welcome-page.spec.js +++ b/src/layouts/welcome-page/welcome-page.spec.js @@ -180,7 +180,6 @@ describe('navigation', () => { await wrapper.vm.forwardButtonAction(); // Assert - expect(wrapper.vm.mainStore.getDuplicateReferrals).toHaveBeenCalledTimes(0); expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(0); }); }); @@ -206,7 +205,7 @@ describe('navigation', () => { navigationScenarios.CLICKED_FORWARD_WITH_DUPLICATES, undefined, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); }); test('if policy and vehicles are found but no duplicates, navigate to policy-vehicle page', async () => { @@ -234,7 +233,7 @@ describe('navigation', () => { navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES, undefined, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); }); test('if policy is found, but no vehicles and no duplicates, navigate to vehicle-selection page', async () => { @@ -259,7 +258,7 @@ describe('navigation', () => { navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_NO_VEHICLES, undefined, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); }); test('if policy is found, but null vehicles and no duplicates, navigate to vehicle-selection page', async () => { @@ -285,7 +284,7 @@ describe('navigation', () => { navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED_NO_VEHICLES, undefined, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); }); test('if policy is not found and no duplicates, navigate to policy-holder-details page', async () => { @@ -310,7 +309,7 @@ describe('navigation', () => { navigationScenarios.CLICKED_FORWARD_POLICY_UNVERIFIED, undefined, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); }); test('getDuplicateReferrals throws rejected promise => navigate called', async () => { diff --git a/src/layouts/welcome-page/welcome-page.vue b/src/layouts/welcome-page/welcome-page.vue index 454e6734..0298a45c 100644 --- a/src/layouts/welcome-page/welcome-page.vue +++ b/src/layouts/welcome-page/welcome-page.vue @@ -174,6 +174,8 @@ import states from '@/constants/states'; import globalRules from '@/constants/global-rules'; import routerParams from '@/router/router-constants/router-params'; import MaskaFormattedMasks from '@/constants/maska-masks'; +import { saveSession } from '@/helpers/order-helper'; +import bailoutMessage from '@/constants/bailoutMessage'; // define validation rules defineRule( @@ -299,17 +301,22 @@ export default { methods: { async forwardButtonAction() { try { - await this.configureZip(); this.mainStore.updatePolicyData(this.welcomePageModel); - await this.mainStore.getBillToInfo(); - await this.mainStore.getDuplicateReferrals(); - await this.mainStore.getCoveragePolicyInfo(); + await Promise.allSettled([ + this.configureZip().then(async () => await this.mainStore.getBillToInfo()), + this.mainStore.getDuplicateReferrals(), + this.mainStore.getCoveragePolicyInfo() + ]); } catch (e) { console.error(e); // TODO: Bailout? } finally { if (!this.displayInvalidZipAlert) { - this.navigateForward(); + await saveSession({ shouldAwaitSaveSessionQueue: true }) + .catch((error) => { + this.mainStore.setBailout(bailoutMessage.saveSessionError(error.data)); + }) + .finally(() => this.navigateForward()); } } }, @@ -324,12 +331,19 @@ export default { } }, navigateForward() { - if (this.mainStore.applicationUser.duplicateOrders?.length > 0 ?? false) { + if (this.mainStore.isBailout) { + this.$router.navigate( + this.navigationScenarios.SAVE_SESSION_FAILED, + this.$route, + {}, + { [routerParams.SKIP_SAVE_SESSION]: true } + ); + } else if (this.mainStore.applicationUser.duplicateOrders?.length > 0 ?? false) { this.$router.navigate( this.navigationScenarios.CLICKED_FORWARD_WITH_DUPLICATES, this.$route, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); } else if (this.mainStore.isPolicyLookupSuccessful) { if (this.mainStore.order.policy.vehicles?.length > 0 ?? false) { @@ -339,7 +353,7 @@ export default { .CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES, this.$route, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); } else { // navigate to vehicle-selection page (manual entry) @@ -348,7 +362,7 @@ export default { .CLICKED_FORWARD_POLICY_VERIFIED_NO_VEHICLES, this.$route, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); } } else { @@ -357,7 +371,7 @@ export default { this.navigationScenarios.CLICKED_FORWARD_POLICY_UNVERIFIED, this.$route, {}, - { [routerParams.SAVE_SESSION_SYNCHRONOUS]: true } + { [routerParams.SKIP_SAVE_SESSION]: true } ); } }, diff --git a/src/router/index.js b/src/router/index.js index 7bd1c4e0..53dfb91f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -171,17 +171,9 @@ router.afterEach(async (to, from) => { store.clearSaveSessionPromise(); } - if (to.query.issPage !== issPageValues.TPA_CONFIRMATION && to.query.issPage !== issPageValues.ORDER_CONFIRMATION) { - const saveSessionSynchronous = !!router.options.history.state[routerParams.SAVE_SESSION_SYNCHRONOUS]; - await saveSession({ shouldAwaitSaveSessionQueue: saveSessionSynchronous }).catch((error) => { - if (from.name === issPageValues.WELCOME_PAGE) { - store.setBailout(bailoutMessage.saveSessionError(error.data)); - router.navigate( - navigationScenarios.SAVE_SESSION_FAILED, - { query: { issPage: issPageValues.WELCOME_PAGE } } - ); - } - }); + const skipSaveSession = !!router.options.history.state[routerParams.SKIP_SAVE_SESSION]; + if (!skipSaveSession && !store.hasSubmittedOrder()) { + await saveSession({}); } if (to.query.issPage !== issPageValues.ENTRY_PAGE) { @@ -203,7 +195,6 @@ router.navigateWithoutSaving = ( optionalParams = {}, optionalPageData = {} ) => { - // TODO does not save session navigate(scenario, currentRoute, optionalQuery, optionalParams, optionalPageData); }; diff --git a/src/router/router-constants/router-params.js b/src/router/router-constants/router-params.js index 2465f965..2eb3fe76 100644 --- a/src/router/router-constants/router-params.js +++ b/src/router/router-constants/router-params.js @@ -1,6 +1,6 @@ const routerParams = Object.freeze({ DISPLAY_VEHICLE_CHANGE_ALERT: 'displayVehicleChangeAlert', - SAVE_SESSION_SYNCHRONOUS: 'saveSessionSynchronous' + SKIP_SAVE_SESSION: 'skipSaveSession' }); export default routerParams; diff --git a/src/router/router.spec.js b/src/router/router.spec.js index adce98dc..c221dbf0 100644 --- a/src/router/router.spec.js +++ b/src/router/router.spec.js @@ -21,4 +21,19 @@ describe('Router', () => { router.navigate(scenario, currentRoute); expect(router.push.mock.calls[0][0].query.issPage).toBe(issPageValues.POLICY_HOLDER_DETAILS); }); + + it('Should set state as expected', () => { + // Arrange + const scenario = navigationScenarios.CLICKED_FORWARD; + const currentRoute = { query: { issPage: issPageValues.WELCOME_PAGE } }; + const parameters = {saveSync: true}; + + router.push = jest.fn(); + + // Act + router.navigate(scenario, currentRoute, {}, parameters); + + // Assert + expect(router.push.mock.calls[0][0].state).toBe(parameters); + }); });