Moved policy lookup to behind save session on both no-duplicate and duplicate paths.
This commit is contained in:
parent
16f589fe26
commit
e650ac9666
4 changed files with 43 additions and 108 deletions
|
|
@ -62,6 +62,7 @@ import BaseFormMixin from '@/mixins/base-form-mixin.js';
|
|||
import { useMainStore } from '@/store/index.js';
|
||||
import globalRules from '@/constants/global-rules.js';
|
||||
import { formatDate, toTitleCase } from '@/helpers/text-helper.js';
|
||||
import { saveSession } from '@/helpers/order-helper';
|
||||
|
||||
const dupeCheckDateFormatter = new Intl.DateTimeFormat('en-US', { timeZone: 'UTC', month: '2-digit', day: '2-digit', year: 'numeric' });
|
||||
|
||||
|
|
@ -136,21 +137,38 @@ export default {
|
|||
async forwardButtonAction() {
|
||||
// If user clicked foward without selecting an option or user click on "start a new claim" button.
|
||||
if (this.selectedAnswer == null || this.selectedAnswer === 'NewClaim') {
|
||||
this.navigateForward();
|
||||
return;
|
||||
// Call SaveSession to create referral.
|
||||
await saveSession({ shouldAwaitSaveSessionQueue: true, bailoutOnError: true });
|
||||
}
|
||||
else
|
||||
{
|
||||
const selectedReferral =
|
||||
this.mainStore.applicationUser.duplicateOrders.find((o) => o.correlationId === this.selectedAnswer);
|
||||
|
||||
const selectedReferral =
|
||||
this.mainStore.applicationUser.duplicateOrders.find((o) => o.correlationId === this.selectedAnswer);
|
||||
if (selectedReferral) {
|
||||
await this.mainStore.loadSessionFromDuplicate(selectedReferral);
|
||||
}
|
||||
}
|
||||
|
||||
// Call getCoveragePolicyInfo to get the policy info.
|
||||
await this.mainStore.getCoveragePolicyInfo();
|
||||
|
||||
this.pushEventToGA("policy_search", "policy_found", this.mainStore.isPolicyLookupSuccessful ? "Yes" : "No", true);
|
||||
|
||||
if (selectedReferral) {
|
||||
await this.mainStore.loadSessionFromDuplicate(selectedReferral);
|
||||
if ( this.mainStore.isPolicyLookupSuccessful) {
|
||||
this.pushEventToGA("zip_validation", "success", "N/A", true);
|
||||
}
|
||||
else {
|
||||
if ( this.mainStore.order.policy.policyLookupErrorCode === 2) {
|
||||
this.pushEventToGA("zip_validation", "fail", "N/A", true);
|
||||
}
|
||||
}
|
||||
|
||||
this.navigateForward();
|
||||
},
|
||||
navigateForward() {
|
||||
this.mainStore.updateDuplicateCheckVisited(true);
|
||||
|
||||
if (!this.mainStore.isPolicyLookupSuccessful) {
|
||||
this.$router.navigate(
|
||||
this.navigationScenarios.CLICKED_FORWARD_POLICY_UNVERIFIED,
|
||||
|
|
|
|||
|
|
@ -350,24 +350,29 @@ export default {
|
|||
this.mainStore.clearDuplicateOrders();
|
||||
}
|
||||
|
||||
const promises = [
|
||||
this.mainStore.getBillToInfo()
|
||||
];
|
||||
await this.mainStore.getBillToInfo();
|
||||
|
||||
// Skip duplicate check if loaded from cookie or already visited duplicate check page.
|
||||
if (!this.mainStore.order.loadedFromCookie && !this.mainStore.order.visitedDuplicateCheckPage) {
|
||||
promises.push(this.mainStore.getDuplicateReferrals());
|
||||
}
|
||||
promises.push(this.mainStore.getCoveragePolicyInfo());
|
||||
await Promise.all(promises);
|
||||
await this.mainStore.getDuplicateReferrals();
|
||||
|
||||
this.pushEventToGA("policy_search", "policy_found", this.mainStore.isPolicyLookupSuccessful ? "Yes" : "No", true);
|
||||
// If we do not have any duplicates.
|
||||
// Call SaveSession to create referral.
|
||||
// Then call getCoveragePolicyInfo to get the policy info.
|
||||
if ( this.mainStore.applicationUser.duplicateOrders?.length == 0 ) {
|
||||
await saveSession({ shouldAwaitSaveSessionQueue: true, bailoutOnError: true });
|
||||
await this.mainStore.getCoveragePolicyInfo();
|
||||
|
||||
this.pushEventToGA("policy_search", "policy_found", this.mainStore.isPolicyLookupSuccessful ? "Yes" : "No", true);
|
||||
|
||||
if ( this.mainStore.isPolicyLookupSuccessful) {
|
||||
this.pushEventToGA("zip_validation", "success", "N/A", true);
|
||||
}
|
||||
else {
|
||||
if ( this.mainStore.order.policy.policyLookupErrorCode === 2) {
|
||||
this.pushEventToGA("zip_validation", "fail", "N/A", true);
|
||||
if ( this.mainStore.isPolicyLookupSuccessful) {
|
||||
this.pushEventToGA("zip_validation", "success", "N/A", true);
|
||||
}
|
||||
else {
|
||||
if ( this.mainStore.order.policy.policyLookupErrorCode === 2) {
|
||||
this.pushEventToGA("zip_validation", "fail", "N/A", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,23 +157,6 @@ router.beforeEach(async (to, from) => {
|
|||
showIssLoadingModal(true);
|
||||
}
|
||||
|
||||
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.
|
||||
// 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.
|
||||
// Therefore, we want to force a bailout here if it errors out.
|
||||
showIssLoadingModal(true);
|
||||
try {
|
||||
await saveSession({ shouldAwaitSaveSessionQueue: true, bailoutOnError: true });
|
||||
}
|
||||
catch (error) {
|
||||
// Only remove spinner on error. Successfull new page load will remove it by default.
|
||||
showIssLoadingModal(false);
|
||||
}
|
||||
}
|
||||
|
||||
const toQueryPage = to.query?.issPage;
|
||||
const notToPayInAdvanceReturn = toQueryPage !== issPageValues.PAYMENT_RETURN;
|
||||
const isInIframe = window !== window.top || fromQueryPage === issPageValues.PAYMENT_PAGE;
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
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(result).toBe(true);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue