Merge pull request #784 from Safelite/defect/digital/SSR-1411
SSR-1411 rework save session to be awaitable
This commit is contained in:
commit
828864887d
13 changed files with 66 additions and 62 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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 () => {
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const routerParams = Object.freeze({
|
||||
DISPLAY_VEHICLE_CHANGE_ALERT: 'displayVehicleChangeAlert',
|
||||
SAVE_SESSION_SYNCHRONOUS: 'saveSessionSynchronous'
|
||||
SKIP_SAVE_SESSION: 'skipSaveSession'
|
||||
});
|
||||
|
||||
export default routerParams;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue