diff --git a/src/layouts/policy-holder-details/policy-holder-details.spec.js b/src/layouts/policy-holder-details/policy-holder-details.spec.js index 38fd58ea..444d5c6f 100644 --- a/src/layouts/policy-holder-details/policy-holder-details.spec.js +++ b/src/layouts/policy-holder-details/policy-holder-details.spec.js @@ -87,6 +87,14 @@ describe("navigation", () => { state: "OH", zipCode: "43215", }; + const mockvehicles = [ + { + vin: "TEST_VIN", + }, + { + vin: "TEST_VIN2", + } + ]; const { wrapper } = setupMocks(); @@ -97,22 +105,17 @@ describe("navigation", () => { addressQuestions: mockRegistrationAddress, }, isCoverageEnabled : true, + vehiclesCount:2, + vehiclesFound:mockvehicles }); - const vehiclesFound = [{ - vehicles:[ - { - vin: "TEST_VIN", - }, - { - vin: "TEST_VIN2", - } - ]}]; + useMainStore().order.policy.policyNumber = "p_0001"; useMainStore().order.policy.dateOfLoss = "2022-01-28"; useMainStore().order.accountNumber = "00000"; // Act + await wrapper.vm.forwardButtonAction(); // Assert @@ -121,7 +124,7 @@ describe("navigation", () => { undefined, {}, {}, - vehiclesFound + mockvehicles ); }); diff --git a/src/layouts/policy-holder-details/policy-holder-details.vue b/src/layouts/policy-holder-details/policy-holder-details.vue index 5ad26018..7956343a 100644 --- a/src/layouts/policy-holder-details/policy-holder-details.vue +++ b/src/layouts/policy-holder-details/policy-holder-details.vue @@ -65,7 +65,8 @@ export default { mixins: [BaseFormMixin], data() { return { - customerQuestions: this.getPolicyHolderDetailsFromStore() + customerQuestions: this.getPolicyHolderDetailsFromStore(), + vehiclesFound: [], }; }, setup() { @@ -84,13 +85,16 @@ export default { promise: cmsContentPromise, },]; - //use resultMap to populate layout content. let resultMap = await settleAllPromises(promiseResultMap); next((vm) => { vm.setCmsContent(resultMap.cmsContent); }); + + }, + created(){ + this.getVehiclesfromPolicyLookup(); }, methods: { @@ -100,36 +104,18 @@ export default { async forwardButtonAction() { - this.mainStore.updatePolicyHolderDetails(this.customerQuestions); - //call coverage policy lookup if isCoverageEnabled flag enabled - var vehiclesFound = {}; - if(this.isCoverageEnabled){ - const policyLookupResponse = this.mainStore.getCoveragePolicyInfo({ - accountNumber:this.mainStore.order.accountNumber.toString(), - policyNumber:this.mainStore.order.policy.policyNumber, - dateOfLoss:this.mainStore.order.policy.dateOfLoss}); - - // Settle promises and get results - const promisePolicyLookupResultMap = [ - { - resultKey: "policyLookupResponse", - promise: policyLookupResponse, - } - ]; - const policyLookupResultMap = await settleAllPromises(promisePolicyLookupResultMap); - vehiclesFound = policyLookupResultMap.policyLookupResponse?.policies; - } - return this.navigateForward(vehiclesFound); + this.mainStore.updatePolicyHolderDetails(this.customerQuestions); + return this.navigateForward(); }, - navigateForward(vehiclesFound) { - if(vehiclesFound?.length > 0) + navigateForward() { + if(this.vehiclesCount > 0) this.$router.navigate( this.navigationScenarios.CLICKED_FORWARD_POLICY_VERIFIED, this.$route, {}, {}, - vehiclesFound + this.vehiclesFound ); else this.$router.navigate( @@ -151,11 +137,54 @@ export default { lastName : this.mainStore.order.customer.lastName, } }, + async getPolicyLookupResponse(){ + const policyLookupResponse = this.mainStore.getCoveragePolicyInfo({ + accountNumber:this.mainStore.order.accountNumber.toString(), + policyNumber:this.mainStore.order.policy.policyNumber, + dateOfLoss:this.mainStore.order.policy.dateOfLoss}); + + // Settle promises and get results + const promisePolicyLookupResultMap = [ + { + resultKey: "policyLookupResponse", + promise: policyLookupResponse, + } + ]; + const policyLookupResultMap = await settleAllPromises(promisePolicyLookupResultMap); + return policyLookupResultMap.policyLookupResponse; + }, + async getVehiclesfromPolicyLookup() + { + //call coverage policy lookup if isCoverageEnabled flag enabled + if(this.isCoverageEnabled){ + const policyLookupResponse = await this.getPolicyLookupResponse(); + if(policyLookupResponse!=null){ + var policy = policyLookupResponse.policies?.[0]; + if(policy!=null){ + //populate policy holder details from policy lookup + this.mainStore.order.customer.address.streetAddress = policy.insureds?.[0]?.address; + this.mainStore.order.customer.address.city=policy.insureds?.[0]?.city; + this.mainStore.order.customer.address.state=policy.insureds?.[0]?.state; + this.mainStore.order.customer.address.zipCode=policy.insureds?.[0]?.zipCode; + this.mainStore.order.customer.firstName = policy.insureds?.[0]?.firstName; + this.mainStore.order.customer.lastName = policy.insureds?.[0]?.lastName; + + this.customerQuestions = this.getPolicyHolderDetailsFromStore(); + //populate vehicles + this.vehiclesFound= policy.vehicles; + } + } + } + }, + }, computed:{ isCoverageEnabled(){ return this.mainStore.issConfig.isCoverageEnabled; - } + }, + vehiclesCount(){ + return this.vehiclesFound.length; + } }, components: { siteHeader, diff --git a/src/layouts/policy-vehicles/policy-vehicles.vue b/src/layouts/policy-vehicles/policy-vehicles.vue index f86c8ced..73c0bcb8 100644 --- a/src/layouts/policy-vehicles/policy-vehicles.vue +++ b/src/layouts/policy-vehicles/policy-vehicles.vue @@ -71,7 +71,7 @@ export default { computed:{ VehiclesForQuestions() { // Map API result data, to address-vehicles data structure - const vehicles = this.VehiclesFromApi?.[0].vehicles; + const vehicles = this.VehiclesFromApi; const mappedData = vehicles.map((v) => { const maskSymbol = "X"; const vinStart = maskSymbol.repeat(v.vin.length - 6);