From 270d26dc5187c839b26b5c25cb6fb1cf73c51223 Mon Sep 17 00:00:00 2001 From: brydon1 Date: Mon, 26 Jun 2023 15:07:05 -0400 Subject: [PATCH] Moving setInsuranceCoverageValues to store --- src/store/index.js | 12 +++++++ src/store/store.spec.js | 76 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 4b2a0f69..bf5b1d0b 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -677,6 +677,18 @@ 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 = diff --git a/src/store/store.spec.js b/src/store/store.spec.js index e8d9a3b2..311b235d 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -4,7 +4,7 @@ import { setActivePinia, createPinia } from "pinia"; import globalMethods from "@/global-methods"; import App from '@/App.vue'; import { getRandomString, getRandomGuid, getRandomInt, getRandomBoolean } from '../helpers/data-generation'; - +import { coverageStatuses } from "@/constants/coverage-statuses.js"; describe("Store", () => { @@ -240,6 +240,74 @@ 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); @@ -249,7 +317,7 @@ describe("Store", () => { glassName: glassName, glassLocation: glassLocation }]; - const chipCount = getRandomInt(0,3).toString(); + const chipCount = getRandomInt(0,3); // Act store.saveVehicleDamage(isWindshieldRepair, selectedGlassToReplace, chipCount); @@ -380,7 +448,7 @@ describe("Store", () => { // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalled(); expect(registerClaimPromise).resolves.toMatchObject(response); - expect(registerClaimPromise).resolves.not.toHaveProperty('error'); + expect(registerClaimPromise).resolves.not.toHaveProperty('isError'); }); it("Call to client returns exception, resulting in object with error property being returned", () => { @@ -394,7 +462,7 @@ describe("Store", () => { // Asserts expect(globalMethods.callHttpClient).toHaveBeenCalled(); - expect(registerClaimPromise).resolves.toHaveProperty('error'); + expect(registerClaimPromise).resolves.toHaveProperty('isError'); }); }) }); \ No newline at end of file