Finishing unit tests
This commit is contained in:
parent
270d26dc51
commit
044a2c2798
8 changed files with 542 additions and 360 deletions
|
|
@ -1,27 +0,0 @@
|
|||
import { useMainStore } from '@/store';
|
||||
import { coverageStatuses } from '@/constants/coverage-statuses';
|
||||
|
||||
export async function getRegisterClaimResponse() {
|
||||
const registerClaimResponse = await useMainStore().registerClaim();
|
||||
const promiseResultMap = [
|
||||
{
|
||||
resultKey: 'registerClaimResponse',
|
||||
promise: registerClaimResponse
|
||||
},
|
||||
];
|
||||
|
||||
const resultMap = await settleAllPromises(promiseResultMap);
|
||||
return resultMap.registerClaimResponse;
|
||||
}
|
||||
|
||||
export function setInsuranceCoverageValues(registerClaimResponse) {
|
||||
const registerClaimFailed = registerClaimResponse.isError;
|
||||
if (useMainStore().isClaimRegistrationRequired) {
|
||||
useMainStore().payment.insuranceCoverage.isVerified = !registerClaimFailed;
|
||||
useMainStore().payment.insuranceCoverage.coverageStatus = registerClaimFailed
|
||||
? coverageStatuses.PENDING
|
||||
: useMainStore().policy.noCoverage
|
||||
? coverageStatuses.NO_COMP
|
||||
: coverageStatuses.VERIFIED;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { randomUUID } from "node:crypto";
|
||||
|
||||
export function getRandomString(minLength = 1, maxLength = 100) {
|
||||
const length = getRandomInt(minLength, maxLength);
|
||||
const length = getRandomInt(minLength, maxLength + 1);
|
||||
let result = '';
|
||||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
const charactersLength = characters.length;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin";
|
|||
import { applicationConfig } from "@/constants/application-config";
|
||||
import { fetchCmsContentForPage, setupModalLinks } from "@/helpers/cms-content-helper";
|
||||
import { settleAllPromises } from "@/helpers/layout-helper.js";
|
||||
import { createTestingPinia } from '@pinia/testing';
|
||||
import { getRandomString } from '@/helpers/data-generation.js';
|
||||
|
||||
jest.mock("@/helpers/damage-helper", () => ({
|
||||
getDamageString: jest.fn(),
|
||||
|
|
@ -31,7 +33,8 @@ describe("coverage-statement.vue...", () => {
|
|||
test("Should return true for valid page requisites if vin exists", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
useMainStore().order.vehicle.vin = getRandomString(5,20);
|
||||
|
||||
// Act
|
||||
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
|
|
@ -76,7 +79,7 @@ describe("coverage-statement.vue...", () => {
|
|||
useMainStore().order.damage.isRepair = true;
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.unverifiedNonADASRepairBodyText).toEqual("NonADASRepairTestReturn");
|
||||
expect(wrapper.vm.bodyText).toEqual("NonADASRepairTestReturn");
|
||||
})
|
||||
|
||||
test("If damage is NonADAS Replace, display NonADASReplace coverage statement", async () => {
|
||||
|
|
@ -85,8 +88,16 @@ describe("coverage-statement.vue...", () => {
|
|||
mixins: [mockMixin],
|
||||
});
|
||||
|
||||
useMainStore().lineItems.glassParts =
|
||||
[
|
||||
{
|
||||
requiresRecalibration: false,
|
||||
}
|
||||
];
|
||||
useMainStore().order.damage.isRepair = false;
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.unverifiedNonADASNextStepsBodyText).toEqual("NonADASReplaceTestReturn");
|
||||
expect(wrapper.vm.bodyText).toEqual("NonADASReplaceTestReturn");
|
||||
})
|
||||
|
||||
test("If damage is ADAS Replace, display ADASReplace coverage statement", async () => {
|
||||
|
|
@ -94,12 +105,55 @@ describe("coverage-statement.vue...", () => {
|
|||
const wrapper = shallowMount(coverageStatement, {
|
||||
mixins: [mockMixin],
|
||||
});
|
||||
|
||||
useMainStore().order.lineItems.requiresRecalibration = true;
|
||||
useMainStore().lineItems.glassParts = [
|
||||
{
|
||||
requiresRecalibration: true,
|
||||
}
|
||||
];
|
||||
useMainStore().order.damage.isRepair = false;
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.unverifiedADASNextStepsBodyText).toEqual("ADASReplaceTestReturn");
|
||||
expect(wrapper.vm.bodyText).toEqual("ADASReplaceTestReturn");
|
||||
})
|
||||
});
|
||||
describe("claim registration api call", () => {
|
||||
it("claim registration not required => method not called", async () => {
|
||||
// Arrange
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
const store = useMainStore();
|
||||
store.isClaimRegistrationRequired = false;
|
||||
|
||||
const to = {
|
||||
query: { issPage: getRandomString(4,10) }
|
||||
};
|
||||
const next = jest.fn();
|
||||
|
||||
// SUT
|
||||
coverageStatement.beforeRouteEnter.call(wrapper.vm, to, undefined, next)
|
||||
|
||||
// Assert
|
||||
expect(store.registerClaim).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("claim registration required => register claim method called", async () => {
|
||||
// Arrange
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
const store = useMainStore();
|
||||
store.isClaimRegistrationRequired = true;
|
||||
|
||||
const to = {
|
||||
query: { issPage: getRandomString(4,10) }
|
||||
};
|
||||
const next = jest.fn();
|
||||
|
||||
// SUT
|
||||
coverageStatement.beforeRouteEnter.call(wrapper.vm, to, undefined, next)
|
||||
|
||||
// Assert
|
||||
expect(store.registerClaim).toHaveBeenCalled();
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
|
|
@ -142,30 +196,6 @@ mountOptionsMockData = {},
|
|||
},
|
||||
};
|
||||
|
||||
useMainStore().order = {
|
||||
vehicle: {
|
||||
vin: "TESTVIN",
|
||||
},
|
||||
lineItems: {
|
||||
glassParts: [
|
||||
{
|
||||
canSafeliteRecalibrate: false,
|
||||
childParts: null,
|
||||
color: "Green Tint",
|
||||
description: "solar, driver side, encap",
|
||||
partNumber: "DQ12204GTYNOEM",
|
||||
partType: "DRIVER REAR QUARTER GLASS",
|
||||
recalibrationType: null,
|
||||
requiresCapabilityQuestions: false,
|
||||
requiresRecalibration: false,
|
||||
}
|
||||
]
|
||||
},
|
||||
damage: {
|
||||
isRepair: false,
|
||||
}
|
||||
};
|
||||
|
||||
const apiPromise = Promise.resolve(apiResponses);
|
||||
|
||||
settleAllPromises.mockImplementation(() => apiPromise);
|
||||
|
|
@ -174,12 +204,14 @@ mountOptionsMockData = {},
|
|||
const mountOptions = getMountOptions({});
|
||||
|
||||
mountOptions.mixins = [baseMixin, vehicleQuestionsMixin];
|
||||
mountOptions.global = {
|
||||
plugins: [createTestingPinia()]
|
||||
}
|
||||
|
||||
const wrapper = shallowMount(coverageStatement, mountOptions);
|
||||
|
||||
wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent;
|
||||
|
||||
return { wrapper };
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ import { settleAllPromises } from '@/helpers/layout-helper';
|
|||
import { getDamageString } from '@/helpers/damage-helper.js';
|
||||
import { useMainStore } from "@/store";
|
||||
import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin";
|
||||
import { getRegisterClaimResponse, setInsuranceCoverageValues } from '@/helpers/coverage-statement-helper';
|
||||
|
||||
export default {
|
||||
name: 'coverage-statement',
|
||||
|
|
@ -84,7 +83,7 @@ export default {
|
|||
let parts = useMainStore().lineItems.glassParts;
|
||||
|
||||
// if ADAS, display ADASNextSteps
|
||||
if (parts.filter(part => part.requiresRecalibration).length > 0) {
|
||||
if (parts != null && parts.filter(part => part.requiresRecalibration).length > 0) {
|
||||
return this.unverifiedADASNextStepsBodyText;
|
||||
}
|
||||
// if non-ADAS, display NonADASNextSteps
|
||||
|
|
@ -122,17 +121,19 @@ export default {
|
|||
},
|
||||
];
|
||||
|
||||
if (useMainStore().isClaimRegistrationRequired){
|
||||
const registerClaimResponse = await useMainStore().registerClaim();
|
||||
promiseResultMap.push({
|
||||
resultKey: 'registerClaim',
|
||||
promise: registerClaimResponse,
|
||||
});
|
||||
}
|
||||
|
||||
const resultMap = await settleAllPromises(promiseResultMap);
|
||||
|
||||
next((vm) => {
|
||||
vm.setCmsContent(resultMap.cmsContent);
|
||||
});
|
||||
|
||||
let registerClaimResponse = null;
|
||||
if (useMainStore().isClaimRegistrationRequired){
|
||||
registerClaimResponse = await getRegisterClaimResponse();
|
||||
}
|
||||
setInsuranceCoverageValues(registerClaimResponse);
|
||||
},
|
||||
methods: {
|
||||
arePagePrerequisitesValid() {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ import { useMainStore } from "@/store";
|
|||
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
||||
import {vehicleSelectionOptions} from "@/constants/vehicle-selection-options";
|
||||
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
|
||||
import baseMixin from "@/mixins/base-mixin";
|
||||
import { getRandomString, getRandomInt } from '@/helpers/data-generation.js';
|
||||
import { endorsementOptions } from '@/constants/endorsement-options.js';
|
||||
import { createTestingPinia } from '@pinia/testing';
|
||||
|
||||
// Mock fetchCmsContentForPage
|
||||
jest.mock("@/helpers/cms-content-helper", () => ({
|
||||
|
|
@ -44,116 +48,357 @@ describe("policy-vehicles.vue", () => {
|
|||
expect(wrapper.vm.$router.navigate).toBeCalled();
|
||||
});
|
||||
|
||||
test("Selected vehicle VIN do match vehicles listed in our system (CarIDs) found then navigate forward to vehicle-damage page.", async () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
await wrapper.setData({
|
||||
selectedVehicleVin: "5NMS3CADXLH233004"
|
||||
});
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
describe("forwardButtonAction", () => {
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||
navigationScenarios.CLICKED_FORWARD_LISTED_VEHICLE,
|
||||
undefined,
|
||||
{},
|
||||
{}
|
||||
);
|
||||
});
|
||||
test("Selected vehicle VIN do not match vehicles listed in our system (CarIDs) found then navigate forward to bailout page.", async () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
test("Selected VIN matches vehicle listed in system => update vehicle and navigate forward with CLICKED_FORWARD_LISTED_VEHICLE scenario.", async () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
await wrapper.setData({
|
||||
selectedVehicleVin: "5NMS3CADXLH233004",
|
||||
bailout: true
|
||||
const vin = getRandomString(17,17);
|
||||
await wrapper.setData({
|
||||
selectedVehicleVin: vin,
|
||||
policyVehicles: [
|
||||
{ vin: vin },
|
||||
],
|
||||
bailout: false
|
||||
});
|
||||
|
||||
const year = getRandomInt(1998, 2023);
|
||||
const lookupVehicleResponse = {
|
||||
data: {
|
||||
year: year,
|
||||
}
|
||||
};
|
||||
const store = useMainStore();
|
||||
store.lookupVehicleByVin.mockReturnValue(Promise.resolve(lookupVehicleResponse));
|
||||
|
||||
const expectedInput = {
|
||||
year: year,
|
||||
vin: vin,
|
||||
noCompensation: true,
|
||||
deductible: 0,
|
||||
repairWaived: false
|
||||
}
|
||||
|
||||
// Act
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.bailout).toBeFalsy();
|
||||
expect(store.updateVehicle).toHaveBeenCalledWith(expectedInput);
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||
navigationScenarios.CLICKED_FORWARD_LISTED_VEHICLE,
|
||||
undefined,
|
||||
{},
|
||||
{}
|
||||
);
|
||||
});
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||
navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT,
|
||||
undefined,
|
||||
{},
|
||||
{}
|
||||
);
|
||||
});
|
||||
test("if user select vehicle not listed option then navigate forward to vehicle-selection page.", async () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
test("Error in lookupVehicleByVin call => bailout true and navigate forward with CLICKED_FORWARD_WITH_BAILOUT scenario.", async () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
await wrapper.setData({
|
||||
selectedVehicleVin: vehicleSelectionOptions.VEHICLE_NOT_LISTED,
|
||||
});
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
const vin = getRandomString(17,17);
|
||||
await wrapper.setData({
|
||||
selectedVehicleVin: vin,
|
||||
bailout: false
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||
navigationScenarios.CLICKED_FORWARD_NON_LISTED_VEHICLE,
|
||||
undefined,
|
||||
{},
|
||||
{}
|
||||
);
|
||||
});
|
||||
});
|
||||
const store = useMainStore();
|
||||
store.lookupVehicleByVin.mockReturnValue(Promise.reject());
|
||||
|
||||
function setupMocks({
|
||||
route = null,
|
||||
lookupVehicleByVinResponse
|
||||
})
|
||||
{
|
||||
useMainStore().applicationUser = {
|
||||
pageData: {
|
||||
"policy-vehicles":
|
||||
[
|
||||
{
|
||||
vehicleMake: "Hyundai",
|
||||
vehicleModel: "Santa Fe",
|
||||
vehicleStyle: "4 door utility",
|
||||
vehicleYear: 2020,
|
||||
vin: "5NMS3CADXLH233004",
|
||||
// Act
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.bailout).toBeTruthy();
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||
navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT,
|
||||
undefined,
|
||||
{},
|
||||
{}
|
||||
);
|
||||
});
|
||||
|
||||
test("vehicle not listed => navigate forward with CLICKED_FORWARD_NON_LISTED_VEHICLE scenario.", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
await wrapper.setData({
|
||||
selectedVehicleVin: vehicleSelectionOptions.VEHICLE_NOT_LISTED,
|
||||
});
|
||||
|
||||
// Act
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
|
||||
navigationScenarios.CLICKED_FORWARD_NON_LISTED_VEHICLE,
|
||||
undefined,
|
||||
{},
|
||||
{}
|
||||
);
|
||||
});
|
||||
})
|
||||
|
||||
describe("noCompensationForSelectedVehicle computed property", () => {
|
||||
it("No vehicle match => returns true", async () => {
|
||||
// Arrange
|
||||
const selectedVin = getRandomString(17,17);
|
||||
const otherVin = getRandomString(17,17);
|
||||
const testValues = {
|
||||
selectedVehicleVin: selectedVin,
|
||||
policyVehicles: [
|
||||
{
|
||||
vin: otherVin,
|
||||
},
|
||||
],
|
||||
}
|
||||
};
|
||||
useMainStore().lookupVehicleByVin = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: lookupVehicleByVinResponse
|
||||
? lookupVehicleByVinResponse : {
|
||||
vehicle: {
|
||||
carId: "CARID"
|
||||
},
|
||||
},
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = policyVehicles.computed.noCompensationForSelectedVehicle.call(testValues);
|
||||
|
||||
// Assert
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Coverages list empty => true", () => {
|
||||
// Arrange
|
||||
const vin = getRandomString(17,17);
|
||||
const testValues = {
|
||||
selectedVehicleVin: vin,
|
||||
policyVehicles: [
|
||||
{
|
||||
vin: vin,
|
||||
coverages: []
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = policyVehicles.computed.noCompensationForSelectedVehicle.call(testValues);
|
||||
|
||||
// Assert
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Coverages list non-empty => false", () => {
|
||||
// Arrange
|
||||
const vin = getRandomString(17,17);
|
||||
const testValues = {
|
||||
selectedVehicleVin: vin,
|
||||
policyVehicles: [
|
||||
{
|
||||
vin: vin,
|
||||
coverages: [
|
||||
{
|
||||
deductible: 0
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = policyVehicles.computed.noCompensationForSelectedVehicle.call(testValues);
|
||||
|
||||
// Assert
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
})
|
||||
|
||||
describe("deductibleForSelectedVehicle computed property", () => {
|
||||
|
||||
it("No vehicle match => undefined returned", () => {
|
||||
// Arrange
|
||||
const selectedVin = getRandomString(17,17);
|
||||
const otherVin = getRandomString(17,17);
|
||||
const testValues = {
|
||||
selectedVehicleVin: selectedVin,
|
||||
policyVehicles: [
|
||||
{
|
||||
vin: otherVin,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = policyVehicles.computed.deductibleForSelectedVehicle.call(testValues);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(undefined);
|
||||
});
|
||||
|
||||
it("Vehicle match with empty coverages list => 0 returned", () => {
|
||||
// Arrange
|
||||
const vin = getRandomString(17,17);
|
||||
const testValues = {
|
||||
selectedVehicleVin: vin,
|
||||
policyVehicles: [
|
||||
{
|
||||
vin: vin,
|
||||
coverages: []
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = policyVehicles.computed.deductibleForSelectedVehicle.call(testValues);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(0);
|
||||
});
|
||||
|
||||
it("Coverages list non empty => deductible from first coverage returned", () => {
|
||||
// Arrange
|
||||
const vin = getRandomString(17,17);
|
||||
const firstDeductible = getRandomInt(1,1000);
|
||||
const secondDeductible = getRandomInt(1,1000);
|
||||
const testValues = {
|
||||
selectedVehicleVin: vin,
|
||||
policyVehicles: [
|
||||
{
|
||||
vin: vin,
|
||||
coverages: [
|
||||
{
|
||||
deductible: firstDeductible
|
||||
},
|
||||
{
|
||||
deductible: secondDeductible
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = policyVehicles.computed.deductibleForSelectedVehicle.call(testValues);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(firstDeductible);
|
||||
});
|
||||
})
|
||||
|
||||
describe("repairWaivedForSelectedVehicle computed property", () => {
|
||||
|
||||
it("No vehicle match => false returned", () => {
|
||||
// Arrange
|
||||
const selectedVin = getRandomString(17,17);
|
||||
const otherVin = getRandomString(17,17);
|
||||
const testValues = {
|
||||
selectedVehicleVin: selectedVin,
|
||||
policyVehicles: [
|
||||
{
|
||||
vin: otherVin,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = policyVehicles.computed.repairWaivedForSelectedVehicle.call(testValues);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("Endorsements list empty => false returned", () => {
|
||||
// Arrange
|
||||
const vin = getRandomString(17,17);
|
||||
const testValues = {
|
||||
selectedVehicleVin: vin,
|
||||
policyVehicles: [
|
||||
{
|
||||
vin: vin,
|
||||
endorsements: []
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = policyVehicles.computed.repairWaivedForSelectedVehicle.call(testValues);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("Endorsements list non-empty, not containing repair waived => false returned", () => {
|
||||
// Arrange
|
||||
const vin = getRandomString(17,17);
|
||||
const testValues = {
|
||||
selectedVehicleVin: vin,
|
||||
policyVehicles: [
|
||||
{
|
||||
vin: vin,
|
||||
endorsements: [ endorsementOptions.EDUCATOR, endorsementOptions.PARKING_GUARD ]
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = policyVehicles.computed.repairWaivedForSelectedVehicle.call(testValues);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("Endorsements list contains repair waived => true returned", () => {
|
||||
// Arrange
|
||||
const vin = getRandomString(17,17);
|
||||
const testValues = {
|
||||
selectedVehicleVin: vin,
|
||||
policyVehicles: [
|
||||
{
|
||||
vin: vin,
|
||||
endorsements: [
|
||||
endorsementOptions.EDUCATOR,
|
||||
endorsementOptions.REPAIR_WAIVED,
|
||||
endorsementOptions.PARKING_GUARD
|
||||
]
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = policyVehicles.computed.repairWaivedForSelectedVehicle.call(testValues);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
const mockMixin = {
|
||||
methods: {
|
||||
getCmsContent: jest.fn(),
|
||||
},
|
||||
computed: {
|
||||
dynamicStrings() {
|
||||
return { ROUTER_LINK: "routerLink:" };
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
function setupMocks()
|
||||
{
|
||||
const mountOptions = getMountOptions({
|
||||
route: route ? route : undefined,
|
||||
router: {
|
||||
navigate: jest.fn(),
|
||||
},
|
||||
mainStore: {
|
||||
order: {
|
||||
vehicle: {
|
||||
carId: "CR00069309",
|
||||
category: "SUV",
|
||||
imageUrl:
|
||||
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
||||
imageVifColor: "white",
|
||||
imageVifNumber: "13769",
|
||||
make: "Hyundai",
|
||||
model: "Santa Fe",
|
||||
style: "4 door utility",
|
||||
year: 2020,
|
||||
mixins: [mockMixin],
|
||||
global: {
|
||||
mocks: {
|
||||
$route: {
|
||||
params: {
|
||||
id: 1
|
||||
}
|
||||
},
|
||||
vin: "5NMS3CADXLH233004",
|
||||
$router: {
|
||||
navigate: jest.fn()
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
plugins: [createTestingPinia()]
|
||||
}
|
||||
});
|
||||
|
||||
const apiResponses = {
|
||||
cmsContent: {},
|
||||
|
|
@ -161,24 +406,11 @@ function setupMocks({
|
|||
|
||||
settleAllPromises.mockImplementation(() => apiResponses);
|
||||
fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
|
||||
|
||||
|
||||
//Mock props
|
||||
const mockMixin = {
|
||||
methods: {
|
||||
getCmsContent: jest.fn(),
|
||||
},
|
||||
computed: {
|
||||
dynamicStrings() {
|
||||
return { ROUTER_LINK: "routerLink:" };
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
mountOptions.mixins = [mockMixin];
|
||||
const wrapper = shallowMount(policyVehicles,mountOptions);
|
||||
const wrapper = shallowMount(policyVehicles, mountOptions);
|
||||
wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => "");
|
||||
wrapper.vm.setCmsContent = jest.fn();
|
||||
wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent;
|
||||
wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn();
|
||||
wrapper.vm.$refs.siteFooter.removeLoader = jest.fn();
|
||||
return { wrapper };
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ export default {
|
|||
const policyVehicles = useMainStore().pageData(issPageValues.POLICY_VEHICLES);
|
||||
return {
|
||||
policyVehicles: policyVehicles,
|
||||
selectedVehicleVin: policyVehicles.length == 0 ? "" : policyVehicles[0].vin,
|
||||
selectedVehicleVin: (policyVehicles?.length ?? 0) == 0
|
||||
? ""
|
||||
: policyVehicles[0].vin,
|
||||
bailout: false
|
||||
}
|
||||
},
|
||||
|
|
@ -77,28 +79,25 @@ export default {
|
|||
methods:
|
||||
{
|
||||
backButtonAction() {
|
||||
this.mainStore.issConfig.disabledFields.policyNumber = true;
|
||||
useMainStore().issConfig.disabledFields.policyNumber = true;
|
||||
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
|
||||
},
|
||||
async forwardButtonAction() {
|
||||
if(this.selectedVehicleVin != vehicleSelectionOptions.VEHICLE_NOT_LISTED){
|
||||
async forwardButtonAction() {
|
||||
if (this.selectedVehicleVin != vehicleSelectionOptions.VEHICLE_NOT_LISTED){
|
||||
const vehicleLookupResponse = await this.lookupVehicleByVin(this.selectedVehicleVin);
|
||||
if (vehicleLookupResponse.error) {
|
||||
this.bailout = true;
|
||||
this.bailout = true;
|
||||
return this.navigateForward();
|
||||
}
|
||||
|
||||
this.vehicleFromLookup = Object.assign(vehicleLookupResponse.data, {
|
||||
vin: this.selectedVehicleVin,
|
||||
noCoverage: this.noCoverageForSelectedVehicle,
|
||||
noCompensation: this.noCompensationForSelectedVehicle,
|
||||
deductible: this.deductibleForSelectedVehicle,
|
||||
repairWaived: this.repairWaivedForSelectedVehicle
|
||||
});
|
||||
// Update that verified
|
||||
// If they go backwards select vehicle => forward => one deductible => back to vehicle selection => forward again => right info
|
||||
// backwards => vehicle unverified => clear coverage info
|
||||
// keep this in mind
|
||||
this.mainStore.updateVehicle(this.vehicleFromLookup);
|
||||
});
|
||||
|
||||
useMainStore().updateVehicle(this.vehicleFromLookup);
|
||||
}
|
||||
return this.navigateForward();
|
||||
},
|
||||
|
|
@ -126,16 +125,14 @@ export default {
|
|||
);
|
||||
},
|
||||
async lookupVehicleByVin(vin) {
|
||||
try {
|
||||
return await this.mainStore.lookupVehicleByVin(vin);
|
||||
}
|
||||
catch (responseError) {
|
||||
return {
|
||||
error: {
|
||||
status: responseError.status,
|
||||
},
|
||||
};
|
||||
}
|
||||
try {
|
||||
return await useMainStore().lookupVehicleByVin(vin);
|
||||
}
|
||||
catch (responseError) {
|
||||
return {
|
||||
error: true,
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
|
|
@ -143,7 +140,7 @@ export default {
|
|||
VehiclesForQuestions() {
|
||||
// Map API result data, to address-vehicles data structure
|
||||
const vehicles = this.policyVehicles;
|
||||
const mappedData = vehicles.map((v) => {
|
||||
const mappedData = vehicles?.map((v) => {
|
||||
const maskSymbol = "X";
|
||||
const vinStart = maskSymbol.repeat(v.vin.length - 6);
|
||||
const vinEnd = v.vin.substring(v.vin.length - 6);
|
||||
|
|
@ -154,29 +151,26 @@ export default {
|
|||
Name: v.vin,
|
||||
SubText: "VIN " + vinStart + vinEnd,
|
||||
};
|
||||
});
|
||||
}) ?? [];
|
||||
return mappedData;
|
||||
},
|
||||
noCoverageForSelectedVehicle() {
|
||||
noCompensationForSelectedVehicle() {
|
||||
const vehicle = this.policyVehicles.find((vehicle) => { return vehicle.vin == this.selectedVehicleVin; });
|
||||
return vehicle.coverages?.length == 0 ?? true;
|
||||
return (vehicle?.coverages?.length ?? 0) == 0;
|
||||
},
|
||||
deductibleForSelectedVehicle() {
|
||||
const vehicle = this.policyVehicles.find((vehicle) => { return vehicle?.vin == this.selectedVehicleVin; });
|
||||
if (!vehicle){
|
||||
return undefined;
|
||||
}
|
||||
// return 0 in (vehicle.coverages ?? [])
|
||||
// ? vehicle?.coverages[0].deductible
|
||||
// : 0;
|
||||
|
||||
|
||||
return vehicle.coverages?.length ?? false
|
||||
? vehicle?.coverages[0].deductible
|
||||
: 0;
|
||||
},
|
||||
repairWaivedForSelectedVehicle() {
|
||||
const vehicle = this.policyVehicles.find((vehicle) => { return vehicle.vin == this.selectedVehicleVin; });
|
||||
return vehicle.endorsements?.includes(endorsementOptions.REPAIR_WAIVED) ?? false;
|
||||
return vehicle?.endorsements?.includes(endorsementOptions.REPAIR_WAIVED) ?? false;
|
||||
}
|
||||
},
|
||||
components: {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ const getDefaultState = () => {
|
|||
damageState: null,
|
||||
damageCity: null,
|
||||
isDamageGlassOnly: null,
|
||||
noCoverage: null,
|
||||
noCompensation: null,
|
||||
deductible: {
|
||||
repair: null, // numerical value; how much customer owes on deductible in repair case
|
||||
replace: null // numerical value; how much customer owes on deductible in replace case,
|
||||
|
|
@ -362,63 +362,67 @@ export const useMainStore = defineStore({
|
|||
}
|
||||
},
|
||||
registerClaim() {
|
||||
try {
|
||||
// TODO: replace place holder correlationId with the real thing
|
||||
const placeHolderCorrelationId = "00000000-0000-0000-0000-000000000000";
|
||||
const response = globalMethods.callHttpClient({
|
||||
method: endpoints.RegisterClaim.method,
|
||||
endpoint: endpoints.RegisterClaim.url,
|
||||
payload:
|
||||
{
|
||||
correlationId: placeHolderCorrelationId,
|
||||
accountNumber: this.issConfig.accountNumber.toString(),
|
||||
insured: {
|
||||
firstName: this.order.customer.firstName,
|
||||
lastName: this.order.customer.lastName,
|
||||
address: {
|
||||
addressLine1: this.order.customer.address.streetAddress,
|
||||
addressLine2: this.order.customer.address.streetAddress2,
|
||||
city: this.order.customer.address.city,
|
||||
state: this.order.customer.address.state,
|
||||
zipCode: this.order.customer.address.zipCode,
|
||||
country: "US" // TODO set from store
|
||||
},
|
||||
homePhone: {
|
||||
number: this.order.customer.phoneNumber
|
||||
}
|
||||
// TODO: replace place holder correlationId with the real thing
|
||||
const placeHolderCorrelationId = "00000000-0000-0000-0000-000000000000";
|
||||
globalMethods.callHttpClient({
|
||||
method: endpoints.RegisterClaim.method,
|
||||
endpoint: endpoints.RegisterClaim.url,
|
||||
payload:
|
||||
{
|
||||
correlationId: placeHolderCorrelationId,
|
||||
accountNumber: this.issConfig.accountNumber?.toString() ?? "",
|
||||
insured: {
|
||||
firstName: this.order.customer.firstName,
|
||||
lastName: this.order.customer.lastName,
|
||||
address: {
|
||||
addressLine1: this.order.customer.address.streetAddress,
|
||||
addressLine2: this.order.customer.address.streetAddress2,
|
||||
city: this.order.customer.address.city,
|
||||
state: this.order.customer.address.state,
|
||||
zipCode: this.order.customer.address.zipCode,
|
||||
country: "US" // TODO set from store
|
||||
},
|
||||
caller: {
|
||||
homePhone: {}
|
||||
homePhone: {
|
||||
number: this.order.customer.phoneNumber
|
||||
}
|
||||
},
|
||||
caller: {
|
||||
homePhone: {}
|
||||
},
|
||||
policyInfo: {
|
||||
policyNumber: this.order.policy.policyNumber,
|
||||
safelitePolicy: {
|
||||
policies: []
|
||||
}
|
||||
},
|
||||
lossInfo: {
|
||||
dateOfLoss: this.order.policy.dateOfLoss,
|
||||
location: {
|
||||
city: this.order.policy.damageCity,
|
||||
state: this.order.policy.damageState,
|
||||
country: "US" // TODO set from store
|
||||
},
|
||||
policyInfo: {
|
||||
policyNumber: this.order.policy.policyNumber,
|
||||
safelitePolicy: {
|
||||
policies: []
|
||||
}
|
||||
vehicle: {
|
||||
year: this.order.vehicle.year?.toString() ?? "",
|
||||
make: this.order.vehicle.make,
|
||||
model: this.order.vehicle.model,
|
||||
vin: this.order.vehicle.vin
|
||||
},
|
||||
lossInfo: {
|
||||
dateOfLoss: this.order.policy.dateOfLoss,
|
||||
location: {
|
||||
city: this.order.policy.damageCity,
|
||||
state: this.order.policy.damageState,
|
||||
country: "US" // TODO set from store
|
||||
},
|
||||
vehicle: {
|
||||
year: this.order.vehicle.year.toString(),
|
||||
make: this.order.vehicle.make,
|
||||
model: this.order.vehicle.model,
|
||||
vin: this.order.vehicle.vin
|
||||
},
|
||||
},
|
||||
damageDescription: this.order.policy.damageCause
|
||||
}
|
||||
});
|
||||
return response;
|
||||
} catch (responseError) {
|
||||
return Promise.resolve({
|
||||
isError: true
|
||||
})
|
||||
}
|
||||
},
|
||||
damageDescription: this.order.policy.damageCause
|
||||
}
|
||||
}).then((response) => {
|
||||
const registerClaimFailed = response.data.isError;
|
||||
this.order.payment.insuranceCoverage.isVerified = !registerClaimFailed;
|
||||
this.order.payment.insuranceCoverage.coverageStatus = registerClaimFailed
|
||||
? coverageStatuses.PENDING
|
||||
: this.policy.noCompensation
|
||||
? coverageStatuses.NO_COMP
|
||||
: coverageStatuses.VERIFIED;
|
||||
},(error) => {
|
||||
this.order.payment.insuranceCoverage.isVerified = false;
|
||||
this.order.payment.insuranceCoverage.coverageStatus = coverageStatuses.PENDING;
|
||||
});
|
||||
},
|
||||
async lookupVinByPlate(licensePlate, licenseState) {
|
||||
try {
|
||||
|
|
@ -677,18 +681,6 @@ export const useMainStore = defineStore({
|
|||
});
|
||||
},
|
||||
|
||||
setInsuranceCoverageValues(registerClaimResponse) {
|
||||
const registerClaimFailed = registerClaimResponse.isError;
|
||||
if (this.issConfig.isClaimRegistrationRequired) {
|
||||
this.order.payment.insuranceCoverage.isVerified = !registerClaimFailed;
|
||||
this.order.payment.insuranceCoverage.coverageStatus = registerClaimFailed
|
||||
? coverageStatuses.PENDING
|
||||
: useMainStore().policy.noCoverage
|
||||
? coverageStatuses.NO_COMP
|
||||
: coverageStatuses.VERIFIED;
|
||||
}
|
||||
},
|
||||
|
||||
saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, selectedWindshieldChipCount) {
|
||||
const selectedGlassPassedInSorted = selectedGlassToReplace.slice().sort();
|
||||
const isGlassToReplaceTheSame =
|
||||
|
|
@ -775,7 +767,7 @@ export const useMainStore = defineStore({
|
|||
this.order.vehicle.imageColor = vehicle.imageVifColor;
|
||||
|
||||
// These could be undefined
|
||||
this.order.policy.noCoverage = vehicle.noCoverage;
|
||||
this.order.policy.noCompensation = vehicle.noCoverage;
|
||||
this.order.policy.deductible.replace = vehicle.deductible;
|
||||
this.order.policy.deductible.repair = vehicle?.repairWaived ?? false ? 0 : vehicle.deductible;
|
||||
|
||||
|
|
|
|||
|
|
@ -156,16 +156,16 @@ describe("Store", () => {
|
|||
|
||||
it("UpdateVehicle should set policy values appropriately with repair waived", () => {
|
||||
// Arrange
|
||||
const noCoverage = getRandomBoolean();
|
||||
const noCompensation = getRandomBoolean();
|
||||
const deductible = getRandomInt(1,500);
|
||||
const vehicle = {
|
||||
noCoverage: noCoverage,
|
||||
noCompensation: noCompensation,
|
||||
deductible: deductible,
|
||||
repairWaived: true
|
||||
};
|
||||
|
||||
const expectedPolicy = {
|
||||
noCoverage: noCoverage,
|
||||
noCompensation: noCompensation,
|
||||
deductible: {
|
||||
replace: deductible,
|
||||
repair: 0
|
||||
|
|
@ -181,16 +181,16 @@ describe("Store", () => {
|
|||
|
||||
it("UpdateVehicle should set policy values appropriately with repair not waived", () => {
|
||||
// Arrange
|
||||
const noCoverage = getRandomBoolean();
|
||||
const noCompensation = getRandomBoolean();
|
||||
const deductible = getRandomInt(1,500);
|
||||
const vehicle = {
|
||||
noCoverage: noCoverage,
|
||||
noCompensation: noCompensation,
|
||||
deductible: deductible,
|
||||
repairWaived: false
|
||||
};
|
||||
|
||||
const expectedPolicy = {
|
||||
noCoverage: noCoverage,
|
||||
noCompensation: noCompensation,
|
||||
deductible: {
|
||||
replace: deductible,
|
||||
repair: deductible
|
||||
|
|
@ -240,74 +240,6 @@ describe("Store", () => {
|
|||
expect(returned).resolves.toMatchObject(response);
|
||||
});
|
||||
|
||||
describe("setInsuranceCoverageValues method", () => {
|
||||
it("claim registration not required => nothing is updated", () => {
|
||||
// Arrange
|
||||
store.issConfig.isClaimRegistrationRequired = false;
|
||||
const registerClaimResponse = {
|
||||
isError: false
|
||||
};
|
||||
const oldIsVerified = null;
|
||||
store.payment.insuranceCoverage.isVerified = oldIsVerified;
|
||||
const oldCoverageStatus = coverageStatuses.NO_COMP;
|
||||
store.payment.insuranceCoverage.coverageStatus = oldCoverageStatus;
|
||||
|
||||
// Act
|
||||
store.setInsuranceCoverageValues(registerClaimResponse);
|
||||
|
||||
// Assert
|
||||
expect(store.payment.insuranceCoverage.isVerified).toBe(oldIsVerified);
|
||||
expect(store.payment.insuranceCoverage.coverageStatus).toBe(oldCoverageStatus);
|
||||
})
|
||||
|
||||
it("Register Claim fails => isVerified false and coverage status pending", () =>{
|
||||
// Arrange
|
||||
store.issConfig.isClaimRegistrationRequired = true;
|
||||
const registerClaimResponse = {
|
||||
isError: true
|
||||
};
|
||||
|
||||
// Act
|
||||
store.setInsuranceCoverageValues(registerClaimResponse);
|
||||
|
||||
// Assert
|
||||
expect(store.payment.insuranceCoverage.isVerified).toBe(false);
|
||||
expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.PENDING);
|
||||
})
|
||||
|
||||
it("Register Claim success and no coverage => isVerified true and coverage status no comp", () => {
|
||||
// Arrange
|
||||
store.issConfig.isClaimRegistrationRequired = true;
|
||||
const registerClaimResponse = {
|
||||
isError: false
|
||||
};
|
||||
store.policy.noCoverage = true;
|
||||
|
||||
// Act
|
||||
store.setInsuranceCoverageValues(registerClaimResponse);
|
||||
|
||||
// Assert
|
||||
expect(store.payment.insuranceCoverage.isVerified).toBe(true);
|
||||
expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.NO_COMP);
|
||||
})
|
||||
|
||||
it("Register Claim success and coverage => isVerified true and coverage status verified", () => {
|
||||
// Arrange
|
||||
store.issConfig.isClaimRegistrationRequired = true;
|
||||
const registerClaimResponse = {
|
||||
isError: false
|
||||
};
|
||||
store.policy.noCoverage = false;
|
||||
|
||||
// Act
|
||||
store.setInsuranceCoverageValues(registerClaimResponse);
|
||||
|
||||
// Assert
|
||||
expect(store.payment.insuranceCoverage.isVerified).toBe(true);
|
||||
expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.VERIFIED);
|
||||
})
|
||||
})
|
||||
|
||||
it("saveVehicleDamage with windshield repair should update damage with number of chips not null", () => {
|
||||
// Arrange
|
||||
const glassName = getRandomString(4,10);
|
||||
|
|
@ -426,7 +358,7 @@ describe("Store", () => {
|
|||
});
|
||||
|
||||
describe("registerClaim method", () => {
|
||||
it("successful response results in expected data returned", () => {
|
||||
it("successful response with no coverage => isVerified true and coverage status no comp", async () => {
|
||||
// Arrange
|
||||
const response = {
|
||||
data: {
|
||||
|
|
@ -439,30 +371,56 @@ describe("Store", () => {
|
|||
deductible: 0
|
||||
}
|
||||
};
|
||||
store.policy.noCompensation = true;
|
||||
|
||||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response));
|
||||
|
||||
// Act
|
||||
const registerClaimPromise = store.registerClaim();
|
||||
await store.registerClaim();
|
||||
|
||||
// Asserts
|
||||
expect(globalMethods.callHttpClient).toHaveBeenCalled();
|
||||
expect(registerClaimPromise).resolves.toMatchObject(response);
|
||||
expect(registerClaimPromise).resolves.not.toHaveProperty('isError');
|
||||
expect(store.payment.insuranceCoverage.isVerified).toBe(true);
|
||||
expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.NO_COMP);
|
||||
});
|
||||
|
||||
it("Call to client returns exception, resulting in object with error property being returned", () => {
|
||||
it("successful response with coverage => isVerified true and coverage status verified", async () => {
|
||||
// Arrange
|
||||
globalMethods.callHttpClient = jest.fn().mockImplementation(() => {
|
||||
throw new Error('Register claim call failed');
|
||||
});
|
||||
const response = {
|
||||
data: {
|
||||
claimantId: null,
|
||||
claimNumber: getRandomString(9, 9),
|
||||
correlationId: getRandomGuid(),
|
||||
isSuccess: true,
|
||||
isError: false,
|
||||
successMessage: getRandomString(9, 9),
|
||||
deductible: 0
|
||||
}
|
||||
};
|
||||
store.policy.noCompensation = false;
|
||||
|
||||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response));
|
||||
|
||||
// Act
|
||||
const registerClaimPromise = store.registerClaim();
|
||||
await store.registerClaim();
|
||||
|
||||
// Asserts
|
||||
expect(globalMethods.callHttpClient).toHaveBeenCalled();
|
||||
expect(registerClaimPromise).resolves.toHaveProperty('isError');
|
||||
expect(store.payment.insuranceCoverage.isVerified).toBe(true);
|
||||
expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.VERIFIED);
|
||||
})
|
||||
|
||||
it("Call to client returns exception, resulting in object with error property being returned", async () => {
|
||||
// Arrange
|
||||
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject());
|
||||
|
||||
// Act
|
||||
await store.registerClaim();
|
||||
|
||||
// Asserts
|
||||
expect(globalMethods.callHttpClient).toHaveBeenCalled();
|
||||
expect(store.payment.insuranceCoverage.isVerified).toBe(false);
|
||||
expect(store.payment.insuranceCoverage.coverageStatus).toBe(coverageStatuses.PENDING);
|
||||
});
|
||||
})
|
||||
});
|
||||
Loading…
Reference in a new issue