diff --git a/src/layouts/welcome-page/welcome-page.spec.js b/src/layouts/welcome-page/welcome-page.spec.js index ae934705..2b858cec 100644 --- a/src/layouts/welcome-page/welcome-page.spec.js +++ b/src/layouts/welcome-page/welcome-page.spec.js @@ -62,13 +62,21 @@ describe("navigation", () => { ]; const { wrapper } = setupMocks({ - policies: [{}] + policies: [{ + vehicles: [ + { + vin: "TEST_VIN" + }, + { + vin: "TEST_VIN2" + } + ] + }] }); await wrapper.setData({ isCoverageEnabled: true, - vehiclesCount: 2, - vehiclesFound: mockvehicles, + zipCodeMatch: true, }); useMainStore().order.policy.policyNumber = "p_0001"; @@ -97,6 +105,7 @@ describe("navigation", () => { isCoverageEnabled: true, vehiclesCount: 0, vehiclesFound: null, + zipCodeMatch: true, }); useMainStore().order.policy.policyNumber = "p_0001"; @@ -116,11 +125,11 @@ describe("navigation", () => { test("if policy is not found, navigate to policy-holder-details page", async () => { // Arrange const { wrapper } = setupMocks({ - policies: undefined + policies: null }); await wrapper.setData({ - isCoverageEnabled : true, + isCoverageEnabled: true, }); useMainStore().order.policy.policyNumber = "p_0001"; @@ -128,7 +137,7 @@ describe("navigation", () => { useMainStore().order.accountNumber = "00000"; // Act - await wrapper.vm.forwardButtonAction(); + await wrapper.vm.navigateForward(); // Assert expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith( @@ -136,6 +145,31 @@ describe("navigation", () => { undefined ); }); + test("if zip code entered does not match zip on policy, navigate to policy-holder-details page", async () => { + // Arrange + const { wrapper } = setupMocks({ + policies: [{}] + }); + + await wrapper.setData({ + isCoverageEnabled: true, + zipCodeMatch: false, + }); + + useMainStore().order.policy.policyNumber = "p_0001"; + useMainStore().order.policy.dateOfLoss = "2022-01-28"; + useMainStore().order.accountNumber = "00000"; + + // Act + await wrapper.vm.navigateForward(); + + // Assert + expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith( + navigationScenarios.CLICKED_FORWARD_WITH_NO_POLICY, + undefined + ); + }); + }); function setupMocks({ @@ -143,15 +177,20 @@ function setupMocks({ pageFooterWidgetCmsContent = {}, mountOptionsMockData = {}, policies = [], - lookupPolicyResponse + getCoveragePolicyInfoResponse }) { useMainStore().getCoveragePolicyInfo = jest.fn().mockImplementation(() => { return Promise.resolve({ - data: lookupPolicyResponse - ? lookupPolicyResponse + data: getCoveragePolicyInfoResponse + ? getCoveragePolicyInfoResponse : { policies: [ { + insureds: [ + { + customerId: "TEST_ID" + }, + ], vehicles: [ { vin: "TEST_VIN" diff --git a/src/layouts/welcome-page/welcome-page.vue b/src/layouts/welcome-page/welcome-page.vue index 07f06fcb..9af3d612 100644 --- a/src/layouts/welcome-page/welcome-page.vue +++ b/src/layouts/welcome-page/welcome-page.vue @@ -205,6 +205,7 @@ export default { return { welcomePageModel: this.getWelcomePageModelFromStore(), vehiclesFound: [], + zipCodeMatch: false, }; }, setup() { @@ -259,13 +260,18 @@ export default { const policyLookupResultMap = await settleAllPromises(promisePolicyLookupResultMap); const policyInfo = policyLookupResultMap.policyLookupResponse; - // if policy lookup fails, move the user forward + // if policy lookup fails, navigate to policy-holder-details page if (!policyInfo) { this.navigateForward(); } const policy = policyInfo.policies?.[0]; - if (policy) { + // get the first 5 digits of the policy zip code + const policyZip = (policy.insureds?.[0]?.zipCode).slice(0, 5); + // check if policy zip enters matches zip on policy + this.zipCodeMatch = policyZip == this.welcomePageModel.policyZipCode; + + if (policy && this.zipCodeMatch) { //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; @@ -277,14 +283,29 @@ export default { //populate vehicles this.vehiclesFound = policy.vehicles; } - return this.navigateForward(policy); + return this.navigateForward(policy, this.zipCodeMatch); } return this.navigateForward(); }, - navigateForward(policy) { + navigateForward(policy, zipCodeMatch) { + // if policy lookup is unsuccessful, navigate to policy-holder-details page + if (!policy || !zipCodeMatch) { + this.$router.navigate( + this.navigationScenarios.CLICKED_FORWARD_WITH_NO_POLICY, + this.$route + ); + } + // if policy lookup is successful, but no vehicles are associated with the policy + // navigate to vehicle-selection page (manual entry) + else if (policy && zipCodeMatch && !this.vehiclesFound) { + this.$router.navigate( + this.navigationScenarios.CLICKED_FORWARD_WITH_POLICY_AND_NO_VEHICLES, + this.$route + ); + } // if policy lookup is successful and vehicles are found, navigate to policy-vehicles page - if (policy && this.vehiclesFound) { + else if (policy && zipCodeMatch && this.vehiclesFound) { this.$router.navigate( this.navigationScenarios.CLICKED_FORWARD_WITH_POLICY_AND_VEHICLES, this.$route, @@ -293,21 +314,6 @@ export default { this.vehiclesFound ); } - // if policy lookup is successful, but no vehicles are associated with the policy - // navigate to vehicle-selection page (manual entry) - else if (policy && !this.vehiclesFound) { - this.$router.navigate( - this.navigationScenarios.CLICKED_FORWARD_WITH_POLICY_AND_NO_VEHICLES, - this.$route - ); - } - // if policy lookup is unsuccessful, navigate to policy-holder-details page - else { - this.$router.navigate( - this.navigationScenarios.CLICKED_FORWARD_WITH_NO_POLICY, - this.$route - ); - } }, getWelcomePageModelFromStore() {