Merge branch 'develop' into feature/humphries/INSR-10100
This commit is contained in:
commit
40caf90ed3
7 changed files with 228 additions and 171 deletions
|
|
@ -22,4 +22,3 @@ npm run test:unit
|
||||||
|
|
||||||
### Customize configuration
|
### Customize configuration
|
||||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
See [Configuration Reference](https://cli.vuejs.org/config/).
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import settleAllPromises from '@/helpers/layout-helper.js';
|
||||||
import { fetchCmsContentForPage } from '@/helpers/cms-content-helper';
|
import { fetchCmsContentForPage } from '@/helpers/cms-content-helper';
|
||||||
import coverageStatuses from '@/constants/coverage-statuses';
|
import coverageStatuses from '@/constants/coverage-statuses';
|
||||||
import coverageType from '@/constants/coverage-type';
|
import coverageType from '@/constants/coverage-type';
|
||||||
|
import { saveSession } from '@/helpers/order-helper';
|
||||||
|
|
||||||
// Mock fetchCmsContentForPage
|
// Mock fetchCmsContentForPage
|
||||||
jest.mock('@/helpers/cms-content-helper', () => ({
|
jest.mock('@/helpers/cms-content-helper', () => ({
|
||||||
|
|
@ -22,6 +23,9 @@ jest.mock('@/helpers/cms-content-helper', () => ({
|
||||||
|
|
||||||
// Mock our module for promises.
|
// Mock our module for promises.
|
||||||
jest.mock('@/helpers/layout-helper.js', () => jest.fn());
|
jest.mock('@/helpers/layout-helper.js', () => jest.fn());
|
||||||
|
jest.mock('@/helpers/order-helper', () => ({
|
||||||
|
saveSession: jest.fn().mockResolvedValue({})
|
||||||
|
}));
|
||||||
|
|
||||||
function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRunAfterInitializingStore = () => {}) {
|
function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRunAfterInitializingStore = () => {}) {
|
||||||
const mountOptions = getMountOptions({
|
const mountOptions = getMountOptions({
|
||||||
|
|
@ -135,15 +139,11 @@ describe('duplicateCheck.vue', () => {
|
||||||
vehicleYear: null,
|
vehicleYear: null,
|
||||||
vehicleMake: getRandomString(5, 5),
|
vehicleMake: getRandomString(5, 5),
|
||||||
vehicleModel: getRandomString(5, 5),
|
vehicleModel: getRandomString(5, 5),
|
||||||
|
referralDate: '1990-09-23T01:12:34',
|
||||||
referralNumber,
|
referralNumber,
|
||||||
correlationId: getRandomString(5, 5)
|
correlationId: getRandomString(5, 5)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
order: {
|
|
||||||
policy: {
|
|
||||||
dateOfLoss: '1990-09-23'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -168,15 +168,11 @@ describe('duplicateCheck.vue', () => {
|
||||||
vehicleYear: getRandomString(6, 6),
|
vehicleYear: getRandomString(6, 6),
|
||||||
vehicleMake: null,
|
vehicleMake: null,
|
||||||
vehicleModel: getRandomString(5, 5),
|
vehicleModel: getRandomString(5, 5),
|
||||||
|
referralDate: '2004-11-01T01:12:34',
|
||||||
referralNumber,
|
referralNumber,
|
||||||
correlationId: getRandomString(6, 6)
|
correlationId: getRandomString(6, 6)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
order: {
|
|
||||||
policy: {
|
|
||||||
dateOfLoss: '2004-11-01'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -201,15 +197,11 @@ describe('duplicateCheck.vue', () => {
|
||||||
vehicleYear: getRandomString(6, 6),
|
vehicleYear: getRandomString(6, 6),
|
||||||
vehicleMake: getRandomString(6, 6),
|
vehicleMake: getRandomString(6, 6),
|
||||||
vehicleModel: null,
|
vehicleModel: null,
|
||||||
|
referralDate: '1999-01-15T01:12:34',
|
||||||
referralNumber,
|
referralNumber,
|
||||||
correlationId: getRandomString(6, 6)
|
correlationId: getRandomString(6, 6)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
order: {
|
|
||||||
policy: {
|
|
||||||
dateOfLoss: '1999-01-15'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -234,15 +226,11 @@ describe('duplicateCheck.vue', () => {
|
||||||
vehicleYear: 'YEAR',
|
vehicleYear: 'YEAR',
|
||||||
vehicleMake: 'make',
|
vehicleMake: 'make',
|
||||||
vehicleModel: 'MoDel',
|
vehicleModel: 'MoDel',
|
||||||
|
referralDate: '2018-03-01T01:12:34',
|
||||||
referralNumber,
|
referralNumber,
|
||||||
correlationId: getRandomString(6, 6)
|
correlationId: getRandomString(6, 6)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
order: {
|
|
||||||
policy: {
|
|
||||||
dateOfLoss: '2018-03-01'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -278,6 +266,37 @@ describe('duplicateCheck.vue', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('forwardButtonAction', () => {
|
describe('forwardButtonAction', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('No selected duplicate => calls saveSession and getCoveragePolicyInfo, not loadSessionFromDuplicate', async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = getMountedComponent({
|
||||||
|
applicationUser: {
|
||||||
|
duplicateOrders: [
|
||||||
|
{
|
||||||
|
referralDate: '2004-11-01T01:12:34',
|
||||||
|
referralNumber: getRandomString(6, 6),
|
||||||
|
correlationId: getRandomString(6, 6)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
wrapper.vm.mainStore.loadSessionFromDuplicate = jest.fn().mockResolvedValue({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(saveSession).toHaveBeenCalledTimes(1);
|
||||||
|
expect(wrapper.vm.mainStore.loadSessionFromDuplicate).not.toHaveBeenCalled();
|
||||||
|
expect(wrapper.vm.mainStore.getCoveragePolicyInfo).toHaveBeenCalledTimes(1);
|
||||||
|
expect(saveSession.mock.invocationCallOrder[0]).toBeLessThan(
|
||||||
|
wrapper.vm.mainStore.getCoveragePolicyInfo.mock.invocationCallOrder[0]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('Selected duplicate => load session called', async () => {
|
test('Selected duplicate => load session called', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const selectedAnswer = getRandomString(6, 6);
|
const selectedAnswer = getRandomString(6, 6);
|
||||||
|
|
@ -288,6 +307,7 @@ describe('duplicateCheck.vue', () => {
|
||||||
vehicleYear: 'YEAR',
|
vehicleYear: 'YEAR',
|
||||||
vehicleMake: 'make',
|
vehicleMake: 'make',
|
||||||
vehicleModel: 'MoDel',
|
vehicleModel: 'MoDel',
|
||||||
|
referralDate: '2018-03-01T01:12:34',
|
||||||
responseDate: '2018-03-01T01:12:34',
|
responseDate: '2018-03-01T01:12:34',
|
||||||
referralNumber: getRandomString(6, 6),
|
referralNumber: getRandomString(6, 6),
|
||||||
correlationId: selectedAnswer
|
correlationId: selectedAnswer
|
||||||
|
|
@ -296,17 +316,49 @@ describe('duplicateCheck.vue', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
wrapper.setData({ selectedAnswer });
|
await wrapper.setData({ selectedAnswer });
|
||||||
useMainStore().loadSessionFromDuplicate = jest.fn().mockImplementation(() => Promise.resolve({}));
|
wrapper.vm.mainStore.loadSessionFromDuplicate = jest.fn().mockResolvedValue({});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await wrapper.vm.forwardButtonAction();
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.mainStore.loadSessionFromDuplicate).toHaveBeenCalledTimes(1);
|
expect(wrapper.vm.mainStore.loadSessionFromDuplicate).toHaveBeenCalledTimes(1);
|
||||||
|
expect(saveSession).not.toHaveBeenCalled();
|
||||||
|
expect(wrapper.vm.mainStore.getCoveragePolicyInfo).toHaveBeenCalledTimes(1);
|
||||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
test('Selected new order => load session not called', async () => {
|
test('Selected NewClaim => calls saveSession, not loadSessionFromDuplicate', async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = getMountedComponent({
|
||||||
|
applicationUser: {
|
||||||
|
duplicateOrders: [
|
||||||
|
{
|
||||||
|
vehicleYear: 'YEAR',
|
||||||
|
vehicleMake: 'make',
|
||||||
|
vehicleModel: 'MoDel',
|
||||||
|
responseDate: '2018-03-01T01:12:34',
|
||||||
|
referralDate: '2018-03-01T01:12:34',
|
||||||
|
referralNumber: getRandomString(6, 6),
|
||||||
|
correlationId: getRandomString(6, 6)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await wrapper.setData({ selectedAnswer: 'NewClaim' });
|
||||||
|
wrapper.vm.mainStore.loadSessionFromDuplicate = jest.fn().mockResolvedValue({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(saveSession).toHaveBeenCalledTimes(1);
|
||||||
|
expect(wrapper.vm.mainStore.loadSessionFromDuplicate).toHaveBeenCalledTimes(0);
|
||||||
|
expect(wrapper.vm.mainStore.getCoveragePolicyInfo).toHaveBeenCalledTimes(1);
|
||||||
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
test('Unmatched selection => calls saveSession, not loadSessionFromDuplicate', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const newOrderSelectionName = getRandomString(6, 6);
|
const newOrderSelectionName = getRandomString(6, 6);
|
||||||
const { wrapper } = getMountedComponent({
|
const { wrapper } = getMountedComponent({
|
||||||
|
|
@ -317,6 +369,7 @@ describe('duplicateCheck.vue', () => {
|
||||||
vehicleMake: 'make',
|
vehicleMake: 'make',
|
||||||
vehicleModel: 'MoDel',
|
vehicleModel: 'MoDel',
|
||||||
responseDate: '2018-03-01T01:12:34',
|
responseDate: '2018-03-01T01:12:34',
|
||||||
|
referralDate: '2018-03-01T01:12:34',
|
||||||
referralNumber: getRandomString(6, 6),
|
referralNumber: getRandomString(6, 6),
|
||||||
correlationId: getRandomString(6, 6)
|
correlationId: getRandomString(6, 6)
|
||||||
}
|
}
|
||||||
|
|
@ -324,49 +377,19 @@ describe('duplicateCheck.vue', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
wrapper.setData({ selectedAnswer: newOrderSelectionName });
|
await wrapper.setData({ selectedAnswer: newOrderSelectionName });
|
||||||
useMainStore().loadSessionFromDuplicate = jest.fn().mockImplementation(() => Promise.resolve({}));
|
wrapper.vm.mainStore.loadSessionFromDuplicate = jest.fn().mockResolvedValue({});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await wrapper.vm.forwardButtonAction();
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
// When selection doesn't match any duplicate, saveSession should be called to create a new referral
|
||||||
|
expect(saveSession).toHaveBeenCalledTimes(1);
|
||||||
expect(wrapper.vm.mainStore.loadSessionFromDuplicate).toHaveBeenCalledTimes(0);
|
expect(wrapper.vm.mainStore.loadSessionFromDuplicate).toHaveBeenCalledTimes(0);
|
||||||
|
expect(wrapper.vm.mainStore.getCoveragePolicyInfo).toHaveBeenCalledTimes(1);
|
||||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
test('Load session throws error => still navigate forward', async () => {
|
|
||||||
// Arrange
|
|
||||||
const selectedAnswer = getRandomString(6, 6);
|
|
||||||
const { wrapper } = getMountedComponent({
|
|
||||||
applicationUser: {
|
|
||||||
duplicateOrders: [
|
|
||||||
{
|
|
||||||
vehicleYear: 'YEAR',
|
|
||||||
vehicleMake: 'make',
|
|
||||||
vehicleModel: 'MoDel',
|
|
||||||
responseDate: '2018-03-01T01:12:34',
|
|
||||||
referralNumber: getRandomString(6, 6),
|
|
||||||
correlationId: selectedAnswer
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
wrapper.setData({ selectedAnswer });
|
|
||||||
const error = 'load session error';
|
|
||||||
useMainStore().loadSessionFromDuplicate = jest.fn().mockImplementation(() => Promise.reject(error));
|
|
||||||
|
|
||||||
// Act
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect.assertions(2);
|
|
||||||
try {
|
|
||||||
await wrapper.vm.forwardButtonAction();
|
|
||||||
} catch (e) {
|
|
||||||
expect(e).toMatch(error);
|
|
||||||
}
|
|
||||||
expect(wrapper.vm.mainStore.loadSessionFromDuplicate).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
test('coverageType deductible and policy vehicles returned => CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES', async () => {
|
test('coverageType deductible and policy vehicles returned => CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = getMountedComponent({
|
const { wrapper } = getMountedComponent({
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,8 @@ import BaseFormMixin from '@/mixins/base-form-mixin.js';
|
||||||
import { useMainStore } from '@/store/index.js';
|
import { useMainStore } from '@/store/index.js';
|
||||||
import globalRules from '@/constants/global-rules.js';
|
import globalRules from '@/constants/global-rules.js';
|
||||||
import { formatDate, toTitleCase } from '@/helpers/text-helper.js';
|
import { formatDate, toTitleCase } from '@/helpers/text-helper.js';
|
||||||
|
import { saveSession } from '@/helpers/order-helper';
|
||||||
|
import showIssLoadingModal from '@/helpers/loading-modal-helper';
|
||||||
|
|
||||||
const dupeCheckDateFormatter = new Intl.DateTimeFormat('en-US', { timeZone: 'UTC', month: '2-digit', day: '2-digit', year: 'numeric' });
|
const dupeCheckDateFormatter = new Intl.DateTimeFormat('en-US', { timeZone: 'UTC', month: '2-digit', day: '2-digit', year: 'numeric' });
|
||||||
|
|
||||||
|
|
@ -114,10 +116,10 @@ export default {
|
||||||
const vehicle = !!o.vehicleYear && !!o.vehicleMake && !!o.vehicleModel
|
const vehicle = !!o.vehicleYear && !!o.vehicleMake && !!o.vehicleModel
|
||||||
? `${o.vehicleYear} ${o.vehicleMake} ${o.vehicleModel}`
|
? `${o.vehicleYear} ${o.vehicleMake} ${o.vehicleModel}`
|
||||||
: null;
|
: null;
|
||||||
const dateOfLoss = formatDate(new Date(useMainStore().order.policy.dateOfLoss), dupeCheckDateFormatter);
|
const referralDate = formatDate(new Date(o.referralDate), dupeCheckDateFormatter);
|
||||||
const subtext = vehicle
|
const subtext = vehicle
|
||||||
? `${vehicle}, ${dateOfLoss}`
|
? `${vehicle}, ${referralDate}`
|
||||||
: (vehicle ?? '').concat(dateOfLoss);
|
: (vehicle ?? '').concat(referralDate);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Text: duplicateOrderText,
|
Text: duplicateOrderText,
|
||||||
|
|
@ -134,23 +136,74 @@ export default {
|
||||||
* @summary Steps to perform when forward button clicked.
|
* @summary Steps to perform when forward button clicked.
|
||||||
*/
|
*/
|
||||||
async forwardButtonAction() {
|
async forwardButtonAction() {
|
||||||
// If user clicked foward without selecting an option or user click on "start a new claim" button.
|
showIssLoadingModal(true);
|
||||||
|
|
||||||
|
let callSaveSession = false;
|
||||||
|
|
||||||
|
// If user clicked forward without selecting an option or user click on "start a new claim" button.
|
||||||
if (this.selectedAnswer == null || this.selectedAnswer === 'NewClaim') {
|
if (this.selectedAnswer == null || this.selectedAnswer === 'NewClaim') {
|
||||||
this.navigateForward();
|
// User did not pick a duplicate, so call SaveSession to create referral.
|
||||||
return;
|
callSaveSession = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const selectedReferral =
|
||||||
|
this.mainStore.applicationUser.duplicateOrders.find((o) => o.correlationId === this.selectedAnswer);
|
||||||
|
|
||||||
|
if (selectedReferral) {
|
||||||
|
// LoadSession will bailout on error.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await this.mainStore.loadSessionFromDuplicate(selectedReferral);
|
||||||
|
}
|
||||||
|
catch (error)
|
||||||
|
{
|
||||||
|
// No error handling here needed. Error is already logged.
|
||||||
|
// If LoadSession fails, user gets redirected to bailout page. No need to call save session.
|
||||||
|
// Return here to stop current navigation.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// If duplicate not found in list (unable to load), then call SaveSession to create referral.
|
||||||
|
callSaveSession = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedReferral =
|
try
|
||||||
this.mainStore.applicationUser.duplicateOrders.find((o) => o.correlationId === this.selectedAnswer);
|
{
|
||||||
|
// Call SaveSession to create referral.
|
||||||
|
if (callSaveSession) {
|
||||||
|
// SaveSession will bailout on error.
|
||||||
|
await saveSession({ shouldAwaitSaveSessionQueue: true, bailoutOnError: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// No error handling here needed. Error is already logged.
|
||||||
|
// Return here to stop current navigation.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call getCoveragePolicyInfo to get the policy info.
|
||||||
|
// GetCoveragePolicyInfo handles exception / error internally. We do not care if it fails, user continues in unverified path.
|
||||||
|
await this.mainStore.getCoveragePolicyInfo();
|
||||||
|
|
||||||
|
this.pushEventToGA("policy_search", "policy_found", this.mainStore.isPolicyLookupSuccessful ? "Yes" : "No", true);
|
||||||
|
|
||||||
if (selectedReferral) {
|
if (this.mainStore.isPolicyLookupSuccessful) {
|
||||||
await this.mainStore.loadSessionFromDuplicate(selectedReferral);
|
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();
|
this.navigateForward();
|
||||||
},
|
},
|
||||||
navigateForward() {
|
navigateForward() {
|
||||||
this.mainStore.updateDuplicateCheckVisited(true);
|
this.mainStore.updateDuplicateCheckVisited(true);
|
||||||
|
|
||||||
if (!this.mainStore.isPolicyLookupSuccessful) {
|
if (!this.mainStore.isPolicyLookupSuccessful) {
|
||||||
this.$router.navigate(
|
this.$router.navigate(
|
||||||
this.navigationScenarios.CLICKED_FORWARD_POLICY_UNVERIFIED,
|
this.navigationScenarios.CLICKED_FORWARD_POLICY_UNVERIFIED,
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { useMainStore } from '@/store';
|
||||||
import navigationScenarios from '@/router/router-constants/navigation-scenarios';
|
import navigationScenarios from '@/router/router-constants/navigation-scenarios';
|
||||||
import routerParams from '@/router/router-constants/router-params';
|
import routerParams from '@/router/router-constants/router-params';
|
||||||
import coverageType from '@/constants/coverage-type';
|
import coverageType from '@/constants/coverage-type';
|
||||||
|
import { saveSession } from '@/helpers/order-helper';
|
||||||
|
|
||||||
// Mock our module for promises.
|
// Mock our module for promises.
|
||||||
jest.mock('@/helpers/layout-helper.js', () => jest.fn());
|
jest.mock('@/helpers/layout-helper.js', () => jest.fn());
|
||||||
|
|
@ -23,6 +24,9 @@ jest.mock('@/helpers/cms-content-helper', () => ({
|
||||||
jest.mock('@/global-methods', () => ({
|
jest.mock('@/global-methods', () => ({
|
||||||
callHttpClient: jest.fn()
|
callHttpClient: jest.fn()
|
||||||
}));
|
}));
|
||||||
|
jest.mock('@/helpers/order-helper', () => ({
|
||||||
|
saveSession: jest.fn().mockResolvedValue({})
|
||||||
|
}));
|
||||||
|
|
||||||
/** @ignore */
|
/** @ignore */
|
||||||
function setupMocks({
|
function setupMocks({
|
||||||
|
|
@ -133,6 +137,10 @@ describe('welcome-page.vue', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('navigation', () => {
|
describe('navigation', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe('When zip code check fails', () => {
|
describe('When zip code check fails', () => {
|
||||||
test('Navigation should not happen', async () => {
|
test('Navigation should not happen', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -255,6 +263,51 @@ describe('navigation', () => {
|
||||||
{ [routerParams.SKIP_SAVE_SESSION]: true }
|
{ [routerParams.SKIP_SAVE_SESSION]: true }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
test('if no duplicates, calls saveSession and getCoveragePolicyInfo', async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
useMainStore().getDuplicateReferrals = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||||
|
useMainStore().applicationUser.duplicateOrders = [];
|
||||||
|
useMainStore().order.loadedFromCookie = false;
|
||||||
|
useMainStore().order.visitedDuplicateCheckPage = false;
|
||||||
|
|
||||||
|
wrapper.vm.mainStore.validateZip = jest.fn().mockImplementation(() => Promise.resolve({
|
||||||
|
data: {
|
||||||
|
isValid: true
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(saveSession).toHaveBeenCalledTimes(1);
|
||||||
|
expect(wrapper.vm.mainStore.getCoveragePolicyInfo).toHaveBeenCalledTimes(1);
|
||||||
|
expect(saveSession.mock.invocationCallOrder[0]).toBeLessThan(
|
||||||
|
wrapper.vm.mainStore.getCoveragePolicyInfo.mock.invocationCallOrder[0]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test('if duplicates found, does not call saveSession or getCoveragePolicyInfo', async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
useMainStore().getDuplicateReferrals = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||||
|
useMainStore().applicationUser.duplicateOrders = [{ test: 'duplicate-order' }];
|
||||||
|
useMainStore().order.loadedFromCookie = false;
|
||||||
|
useMainStore().order.visitedDuplicateCheckPage = false;
|
||||||
|
|
||||||
|
wrapper.vm.mainStore.validateZip = jest.fn().mockImplementation(() => Promise.resolve({
|
||||||
|
data: {
|
||||||
|
isValid: true
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(saveSession).not.toHaveBeenCalled();
|
||||||
|
expect(wrapper.vm.mainStore.getCoveragePolicyInfo).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
test('if policy is found, but no vehicles and no duplicates, navigate to vehicle-selection page', async () => {
|
test('if policy is found, but no vehicles and no duplicates, navigate to vehicle-selection page', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
|
|
|
||||||
|
|
@ -359,24 +359,41 @@ export default {
|
||||||
this.mainStore.clearDuplicateOrders();
|
this.mainStore.clearDuplicateOrders();
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises = [
|
await this.mainStore.getBillToInfo();
|
||||||
this.mainStore.getBillToInfo()
|
|
||||||
];
|
|
||||||
// Skip duplicate check if loaded from cookie or already visited duplicate check page.
|
// Skip duplicate check if loaded from cookie or already visited duplicate check page.
|
||||||
if (!this.mainStore.order.loadedFromCookie && !this.mainStore.order.visitedDuplicateCheckPage) {
|
if (!this.mainStore.order.loadedFromCookie && !this.mainStore.order.visitedDuplicateCheckPage) {
|
||||||
promises.push(this.mainStore.getDuplicateReferrals());
|
// getDuplicateReferrals handles exception / error internally. We do not care if it fails, user continues with creating new referral.
|
||||||
}
|
await this.mainStore.getDuplicateReferrals();
|
||||||
promises.push(this.mainStore.getCoveragePolicyInfo());
|
|
||||||
await Promise.all(promises);
|
|
||||||
|
|
||||||
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) {
|
||||||
|
try {
|
||||||
|
// SaveSession will bailout on error.
|
||||||
|
await saveSession({ shouldAwaitSaveSessionQueue: true, bailoutOnError: true });
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// No error handling here needed. Error is already logged.
|
||||||
|
// Return here to stop current navigation.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( this.mainStore.isPolicyLookupSuccessful) {
|
// Call getCoveragePolicyInfo to get the policy info.
|
||||||
this.pushEventToGA("zip_validation", "success", "N/A", true);
|
// GetCoveragePolicyInfo handles exception / error internally. We do not care if it fails, user continues in unverified path.
|
||||||
}
|
await this.mainStore.getCoveragePolicyInfo();
|
||||||
else {
|
|
||||||
if ( this.mainStore.order.policy.policyLookupErrorCode === 2) {
|
this.pushEventToGA("policy_search", "policy_found", this.mainStore.isPolicyLookupSuccessful ? "Yes" : "No", true);
|
||||||
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);
|
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 toQueryPage = to.query?.issPage;
|
||||||
const notToPayInAdvanceReturn = toQueryPage !== issPageValues.PAYMENT_RETURN;
|
const notToPayInAdvanceReturn = toQueryPage !== issPageValues.PAYMENT_RETURN;
|
||||||
const isInIframe = window !== window.top || fromQueryPage === issPageValues.PAYMENT_PAGE;
|
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