SSR-600 Load Session Changes

This commit is contained in:
Josh Dassinger 2024-04-22 08:02:58 -05:00
parent c7ace8557d
commit 23503cd040
4 changed files with 150 additions and 220 deletions

View file

@ -9,6 +9,49 @@ import { getMountOptions } from '@/helpers/unit-test-helper.js';
import navigationScenarios from '@/router/router-constants/navigation-scenarios.js';
import { getRandomString } from '@/helpers/data-generation.js';
import { useMainStore } from '@/store';
import settleAllPromises from '@/helpers/layout-helper.js';
import { fetchCmsContentForPage } from '@/helpers/cms-content-helper';
// Mock fetchCmsContentForPage
jest.mock('@/helpers/cms-content-helper', () => ({
fetchCmsContentForPage: jest.fn(),
doesCopyContainRouterLink: jest.fn()
}));
// Mock our module for promises.
jest.mock('@/helpers/layout-helper.js', () => jest.fn());
function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRunAfterInitializingStore = () => {}) {
const mountOptions = getMountOptions({
router: {
navigate: jest.fn()
}
});
const testingPinia = createTestingPinia({
initialState: {
main: mainInitialState
}
});
useMainStore(testingPinia);
methodToRunAfterInitializingStore();
mountOptions.global.plugins = [testingPinia];
mountOptions.data = () => (initialData);
const apiResponses = { cmsContent: {} };
settleAllPromises.mockImplementation(() => apiResponses);
fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
const wrapper = shallowMount(duplicateCheck, mountOptions);
wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => {});
wrapper.vm.setCmsContent = jest.fn();
wrapper.vm.$router.navigateWithSpinner = jest.fn();
wrapper.vm.navigateBack = baseMixin.methods.navigateBack;
return { wrapper };
}
const duplicateOrderText = 'Finish Existing Claim';
@ -60,56 +103,30 @@ describe('duplicateCheck.vue', () => {
describe('duplicateOrders computed', () => {
test('duplicateOrders in store undefined => returns empty list', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const mainInitialState = {
const { wrapper } = getMountedComponent({
applicationUser: {
duplicateOrders: undefined
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(duplicateCheck, mountOptions);
});
// Assert
expect(wrapper.vm.duplicateOrders.length).toBe(0);
});
test('duplicateOrders in store empty => returns empty list', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const mainInitialState = {
const { wrapper } = getMountedComponent({
applicationUser: {
duplicateOrders: []
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(duplicateCheck, mountOptions);
});
// Assert
expect(wrapper.vm.duplicateOrders.length).toBe(0);
});
test('duplicateOrder in store with null vehicle year => returns order with only date in subtext', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const referralNumber = getRandomString(6, 6);
const mainInitialState = {
const { wrapper } = getMountedComponent({
applicationUser: {
duplicateOrders: [
{
@ -117,19 +134,14 @@ describe('duplicateCheck.vue', () => {
vehicleMake: getRandomString(5, 5),
vehicleModel: getRandomString(5, 5),
responseDate: '1990-09-23T01:12:34',
referralNumber
referralNumber,
correlationId: getRandomString(5, 5)
}
]
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const expectedSubtext = '9/23/1990';
});
const wrapper = shallowMount(duplicateCheck, mountOptions);
const expectedSubtext = '9/23/1990';
// Assert
expect(wrapper.vm.duplicateOrders.length).toBe(1);
@ -137,17 +149,13 @@ describe('duplicateCheck.vue', () => {
Text: duplicateOrderText,
Name: referralNumber,
SubText: expectedSubtext,
value: useMainStore().applicationUser.duplicateOrders[0]
value: useMainStore().applicationUser.duplicateOrders[0].correlationId
});
});
test('duplicateOrder in store with null vehicle make => returns order with only date subtext', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const referralNumber = getRandomString(6, 6);
const mainInitialState = {
const { wrapper } = getMountedComponent({
applicationUser: {
duplicateOrders: [
{
@ -155,19 +163,14 @@ describe('duplicateCheck.vue', () => {
vehicleMake: null,
vehicleModel: getRandomString(5, 5),
responseDate: '2004-11-01T01:12:34',
referralNumber
referralNumber,
correlationId: getRandomString(6, 6)
}
]
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const expectedSubtext = '11/1/2004';
});
const wrapper = shallowMount(duplicateCheck, mountOptions);
const expectedSubtext = '11/1/2004';
// Assert
expect(wrapper.vm.duplicateOrders.length).toBe(1);
@ -175,17 +178,13 @@ describe('duplicateCheck.vue', () => {
Text: duplicateOrderText,
Name: referralNumber,
SubText: expectedSubtext,
value: useMainStore().applicationUser.duplicateOrders[0]
value: useMainStore().applicationUser.duplicateOrders[0].correlationId
});
});
test('duplicateOrder in store with null vehicle model => returns order with only date subtext', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const referralNumber = getRandomString(6, 6);
const mainInitialState = {
const { wrapper } = getMountedComponent({
applicationUser: {
duplicateOrders: [
{
@ -193,19 +192,14 @@ describe('duplicateCheck.vue', () => {
vehicleMake: getRandomString(6, 6),
vehicleModel: null,
responseDate: '1999-01-15T01:12:34',
referralNumber
referralNumber,
correlationId: getRandomString(6, 6)
}
]
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const expectedSubtext = '1/15/1999';
});
const wrapper = shallowMount(duplicateCheck, mountOptions);
const expectedSubtext = '1/15/1999';
// Assert
expect(wrapper.vm.duplicateOrders.length).toBe(1);
@ -213,17 +207,13 @@ describe('duplicateCheck.vue', () => {
Text: duplicateOrderText,
Name: referralNumber,
SubText: expectedSubtext,
value: useMainStore().applicationUser.duplicateOrders[0]
value: useMainStore().applicationUser.duplicateOrders[0].correlationId
});
});
test('duplicateOrder in store with all vehicle info => returns order with year, make, model and date in subtext', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const referralNumber = getRandomString(6, 6);
const mainInitialState = {
const { wrapper } = getMountedComponent({
applicationUser: {
duplicateOrders: [
{
@ -231,28 +221,23 @@ describe('duplicateCheck.vue', () => {
vehicleMake: 'make',
vehicleModel: 'MoDel',
responseDate: '2018-03-01T01:12:34',
referralNumber
referralNumber,
correlationId: getRandomString(6, 6)
}
]
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
});
const expectedVehicle = 'Year Make Model';
const expectedDate = '3/1/2018';
const wrapper = shallowMount(duplicateCheck, mountOptions);
// Assert
expect(wrapper.vm.duplicateOrders.length).toBe(1);
expect(wrapper.vm.duplicateOrders[0]).toStrictEqual({
Text: duplicateOrderText,
Name: referralNumber,
SubText: `${expectedVehicle}, ${expectedDate}`,
value: useMainStore().applicationUser.duplicateOrders[0]
value: useMainStore().applicationUser.duplicateOrders[0].correlationId
});
});
});
@ -336,11 +321,8 @@ describe('duplicateCheck.vue', () => {
describe('Navigation', () => {
test('Back button clicked triggers navigation', () => {
// Arrange
const wrapper = shallowMount(duplicateCheck, getMountOptions({
router: {
navigateWithSpinner: jest.fn()
}
}));
const { wrapper } = getMountedComponent({});
wrapper.vm.navigateBack = baseMixin.methods.navigateBack;
// Act
@ -355,21 +337,22 @@ describe('duplicateCheck.vue', () => {
describe('forwardButtonAction', () => {
test('Selected duplicate => load session called', async () => {
// Arrange
const newOrderSelectionName = getRandomString(6, 6);
const selectedAnswer = {};
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
mountOptions.mixins = [{
methods: {
getCmsContent: jest.fn().mockImplementation((_, label) => (label === 'Answers'
? [{ Name: newOrderSelectionName }]
: ''))
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
}
]
}
}];
});
const wrapper = shallowMount(duplicateCheck, mountOptions);
wrapper.setData({ selectedAnswer });
useMainStore().loadSession = jest.fn().mockImplementation(() => Promise.resolve({}));
@ -383,19 +366,21 @@ describe('duplicateCheck.vue', () => {
test('Selected new order => load session not called', async () => {
// Arrange
const newOrderSelectionName = getRandomString(6, 6);
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
mountOptions.mixins = [{
methods: {
getCmsContent: jest.fn().mockImplementation((_, label) => (label === 'Answers'
? [{ Name: newOrderSelectionName }]
: ''))
const { wrapper } = getMountedComponent({
applicationUser: {
duplicateOrders: [
{
vehicleYear: 'YEAR',
vehicleMake: 'make',
vehicleModel: 'MoDel',
responseDate: '2018-03-01T01:12:34',
referralNumber: getRandomString(6, 6),
correlationId: getRandomString(6, 6)
}
]
}
}];
});
const wrapper = shallowMount(duplicateCheck, mountOptions);
wrapper.setData({ selectedAnswer: newOrderSelectionName });
useMainStore().loadSession = jest.fn().mockImplementation(() => Promise.resolve({}));
@ -408,21 +393,22 @@ describe('duplicateCheck.vue', () => {
});
test('Load session throws error => still navigate forward', async () => {
// Arrange
const newOrderSelectionName = getRandomString(6, 6);
const selectedAnswer = {};
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
mountOptions.mixins = [{
methods: {
getCmsContent: jest.fn().mockImplementation((_, label) => (label === 'Answers'
? [{ Name: newOrderSelectionName }]
: ''))
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
}
]
}
}];
});
const wrapper = shallowMount(duplicateCheck, mountOptions);
wrapper.setData({ selectedAnswer });
const error = 'load session error';
useMainStore().loadSession = jest.fn().mockImplementation(() => Promise.reject(error));
@ -436,25 +422,14 @@ describe('duplicateCheck.vue', () => {
});
test('policyLookupSuccessful true and policy vehicles returned => CLICKED_FORWARD_POLICY_VERIFIED_WITH_VEHICLES', async () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const mainInitialState = {
const { wrapper } = getMountedComponent({
order: {
policy: {
policyLookupSuccessful: true,
vehicles: [{ test: 'a' }]
}
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(duplicateCheck, mountOptions);
});
// Act
await wrapper.vm.forwardButtonAction();
@ -466,25 +441,14 @@ describe('duplicateCheck.vue', () => {
});
test('policyLookupSuccessful true and no policy vehicles returned => CLICKED_FORWARD_POLICY_VERIFIED_NO_VEHICLES', async () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const mainInitialState = {
const { wrapper } = getMountedComponent({
order: {
policy: {
policyLookupSuccessful: true,
vehicles: []
}
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(duplicateCheck, mountOptions);
});
// Act
await wrapper.vm.forwardButtonAction();
@ -496,24 +460,13 @@ describe('duplicateCheck.vue', () => {
});
test('policyLookupSuccessful false => CLICKED_FORWARD_POLICY_UNVERIFIED', async () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const mainInitialState = {
const { wrapper } = getMountedComponent({
order: {
policy: {
policyLookupSuccessful: false
}
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(duplicateCheck, mountOptions);
});
// Act
await wrapper.vm.forwardButtonAction();
@ -523,14 +476,11 @@ describe('duplicateCheck.vue', () => {
expect(wrapper.vm.$router.navigate)
.toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_POLICY_UNVERIFIED, undefined);
});
// eslint-disable-next-line max-len
test('policyLookupSuccessful true and loaded duplicate with policy vehicle => CLICKED_FORWARD_LOADED_DUPLICATE_WITH_POLICY_VEHICLE', async () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const vin = getRandomString(17, 17);
const mainInitialState = {
const { wrapper } = getMountedComponent({
order: {
policy: {
policyLookupSuccessful: true,
@ -541,14 +491,7 @@ describe('duplicateCheck.vue', () => {
},
loadedFromDupeCheck: true
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(duplicateCheck, mountOptions);
});
// Act
await wrapper.vm.forwardButtonAction();
@ -558,14 +501,11 @@ describe('duplicateCheck.vue', () => {
expect(wrapper.vm.$router.navigate)
.toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_LOADED_DUPLICATE_WITH_POLICY_VEHICLE, undefined);
});
// eslint-disable-next-line max-len
test('policyLookupSuccessful true and loaded duplicate with non policy vehicle => CLICKED_FORWARD_LOADED_DUPLICATE_WITH_NON_POLICY_VEHICLE', async () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const vin = getRandomString(17, 17);
const mainInitialState = {
const { wrapper } = getMountedComponent({
order: {
policy: {
policyLookupSuccessful: true,
@ -576,14 +516,7 @@ describe('duplicateCheck.vue', () => {
},
loadedFromDupeCheck: true
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(duplicateCheck, mountOptions);
});
// Act
await wrapper.vm.forwardButtonAction();
@ -593,13 +526,10 @@ describe('duplicateCheck.vue', () => {
expect(wrapper.vm.$router.navigate)
.toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_LOADED_DUPLICATE_WITH_NON_POLICY_VEHICLE, undefined);
});
// eslint-disable-next-line max-len
test('policyLookupSuccessful true and loaded duplicate with no policy vehicles => CLICKED_FORWARD_LOADED_DUPLICATE_WITH_NO_POLICY_VEHICLES', async () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const mainInitialState = {
const { wrapper } = getMountedComponent({
order: {
policy: {
policyLookupSuccessful: true,
@ -610,14 +540,7 @@ describe('duplicateCheck.vue', () => {
},
loadedFromDupeCheck: true
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(duplicateCheck, mountOptions);
});
// Act
await wrapper.vm.forwardButtonAction();

View file

@ -73,6 +73,10 @@ export default {
vm.setCmsContent(cmsContent);
});
},
setup() {
const mainStore = useMainStore();
return { mainStore };
},
data() {
return {
selectedAnswer: null,
@ -99,7 +103,7 @@ export default {
},
duplicateOrders() {
const duplicateOrderText = 'Finish Existing Claim';
const orders = useMainStore().applicationUser.duplicateOrders;
const orders = this.mainStore.applicationUser.duplicateOrders;
return orders?.map((o) => {
const vehicle = !!o.vehicleYear && !!o.vehicleMake && !!o.vehicleModel
? `${o.vehicleYear} ${o.vehicleMake} ${o.vehicleModel}`
@ -114,7 +118,7 @@ export default {
Text: duplicateOrderText,
Name: o.referralNumber,
SubText: toTitleCase(subtext),
value: o
value: o.correlationId
};
}) ?? [];
},
@ -127,13 +131,16 @@ export default {
* @summary Steps to perform when forward button clicked.
*/
async forwardButtonAction() {
if (this.selectedAnswer !== null && typeof this.selectedAnswer === 'object') {
await useMainStore().loadSession(this.selectedAnswer)
.catch(() => {})
.finally(() => {
this.navigateForward();
});
return;
if (this.selectedAnswer !== null) {
const selectedReferral = this.mainStore.applicationUser.duplicateOrders.find((o) => o.correlationId === this.selectedAnswer);
if (selectedReferral) {
await this.mainStore.loadSession(selectedReferral)
.catch(() => {})
.finally(() => {
this.navigateForward();
});
return;
}
}
this.navigateForward();

View file

@ -1342,7 +1342,7 @@ export const useMainStore = defineStore({
},
async loadSession(duplicate) {
const { applicationUser, order, issConfig } = this;
const { order, issConfig } = this;
try {
const response = await globalMethods.callHttpClient({
method: endpoints.LoadSession.method,
@ -1351,7 +1351,7 @@ export const useMainStore = defineStore({
referralNumber: duplicate.referralNumber,
referralDate: duplicate.responseDate,
parentAccountNumber: issConfig.parentAccountNumber,
referralCorrelationId: duplicate.referralCorrelationId
referralCorrelationId: duplicate.correlationId
}
});
const { data } = response;
@ -1374,8 +1374,8 @@ export const useMainStore = defineStore({
order.contactInfo.firstName = data?.customer?.firstName;
order.contactInfo.lastName = data?.customer?.lastName;
order.contactInfo.emailAddress = data?.customer?.emailAddress;
order.contactInfo.homePhone = data?.customer?.phoneNumber;
order.contactInfo.servicephone = data?.customer?.phoneNumber;
order.contactInfo.homePhone = data?.customer?.homePhone;
order.contactInfo.servicephone = data?.customer?.homePhone;
order.contactInfo.requestTextUpdates = data?.customer?.isSmsOptIn;
order.payment.insuranceCoverage.isVerified = data?.payment?.insuranceCoverage?.isVerified;

View file

@ -1149,7 +1149,7 @@ describe('Store', () => {
expect(store.order.customer.firstName).toBe(customer.firstName);
expect(store.order.customer.lastName).toBe(customer.lastName);
expect(store.order.customer.emailAddress).toBe(customer.emailAddress);
expect(store.order.contactInfo.homePhone).toBe(customer.phoneNumber);
expect(store.order.contactInfo.homePhone).toBe(customer.homePhone);
});
it('sets expected remaining order data', async () => {
// Arrange