diff --git a/src/helpers/heritage-integration/navigation-helper.js b/src/helpers/heritage-integration/navigation-helper.js index 22d984530..8d46f6e4e 100644 --- a/src/helpers/heritage-integration/navigation-helper.js +++ b/src/helpers/heritage-integration/navigation-helper.js @@ -3,10 +3,8 @@ import { externalUrls } from "@/router/router-constants/externalUrl-values"; import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js"; import { saveOrder } from "@/helpers/heritage-integration/order-helper.js"; import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; -import { storeActions } from "@/constants/store-actions"; import store from "@/store"; import router from "@/router"; -import baseMixin from "@/mixins/base-mixin.js"; /* If the user has visited the funnel before this method will determine the bets place to @@ -54,21 +52,6 @@ export async function navigateToHeritageFunnel() { ); } -export async function navigateAfterSaveToHeritageFunnel(currentRoute) { - const currentComponent = currentRoute.matched[0].components; - - // Create the order (or save existing order) when navigating to Heritage Funnel. - await saveOrder(); - - router.navigateToExternalUrl( - externalUrls.HERITAGE_FUNNEL, - { - corid: store.getters.order.referralCorrelationId, - src: "concept-funnel" - } - ); -} - /* Logic for getting the last "valid" page a user visited. */ diff --git a/src/layouts/address-lookup/address-lookup.spec.js b/src/layouts/address-lookup/address-lookup.spec.js index b9e790576..569a6b145 100644 --- a/src/layouts/address-lookup/address-lookup.spec.js +++ b/src/layouts/address-lookup/address-lookup.spec.js @@ -8,7 +8,7 @@ import { storeActions } from "@/constants/store-actions"; import { storeMutations } from "@/constants/store-mutations"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import store from "@/store"; -import { navigateAfterSaveToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; +import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; jest.mock("@/helpers/damage-helper", () => ({ @@ -17,7 +17,7 @@ jest.mock("@/helpers/damage-helper", () => ({ })); jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({ - navigateAfterSaveToHeritageFunnel: jest.fn() + navigateToHeritageFunnel: jest.fn() })); describe("address-lookup.vue", () => { @@ -262,7 +262,7 @@ describe("address-lookup.vue", () => { // Assert expect(wrapper.vm.updateVehicleInfo).toHaveBeenCalled(); - expect(navigateAfterSaveToHeritageFunnel).toHaveBeenCalled(); + expect(navigateToHeritageFunnel).toHaveBeenCalled(); }); test("if the car entered does not match any of the multiple vehicles found, navigate to address-vehicles page", async () => { diff --git a/src/layouts/address-lookup/address-lookup.vue b/src/layouts/address-lookup/address-lookup.vue index 7e74a9e4c..f3029842f 100644 --- a/src/layouts/address-lookup/address-lookup.vue +++ b/src/layouts/address-lookup/address-lookup.vue @@ -132,17 +132,13 @@ export default { isSelectedGlassAvailableForVehicle: false, customAlertData: {}, showServiceZipField: this.getServiceZipFromStore(), - isZipServicable: false, + isZipServiceable: false, } }, methods: { arePagePrerequisitesValid() { return store.getters.vehicle.carId !== null; }, - resetDependentState() { - store.commit(storeMutations.UPDATE_REGISTRATION_LICENSE_PLATE, null); - store.dispatch(storeActions.RESET_PARTS_STATE_AND_DEPENDENCIES); - }, backButtonAction() { // route to move backwards this.$router.navigate( @@ -187,50 +183,69 @@ export default { async forwardButtonAction() { this.resetWarningsAndErrors(); - // Lookup VIN(s) with the provided address - const vinLookupPromise = this.lookupVin( - this.customerQuestions.lastName, - this.customerQuestions.addressQuestions.streetAddress, - this.customerQuestions.addressQuestions.zipCode, - this.customerQuestions.addressQuestions.state - ); + let vehicleInfoToCommit = {}; + let registrationInfoToCommit = {}; + + const vinLookupResponse = this.dispatchStoreAction( + storeActions.LOOKUP_VIN_BY_ADDRESS, + { + licenseLastName: this.customerQuestions.lastName, + licenseStreetAddress: this.customerQuestions.addressQuestions.streetAddress, + licenseZip: this.customerQuestions.addressQuestions.zipCode, + licenseState: this.customerQuestions.addressQuestions.state + }, false); + + // Settle promises and get results + const promiseResultMap = [ + { + resultKey: "vinLookupResponse", + promise: vinLookupResponse + }, + { + resultKey: "serviceZipValidationResponse", + promise: this.serviceZipCode ? + this.dispatchStoreAction(storeActions.VALIDATE_ZIP, {zip: this.serviceZipCode }) : + this.dispatchStoreAction(storeActions.VALIDATE_ZIP, {zip: this.customerQuestions.addressQuestions.zipCode }) + } + ]; + + const resultMap = await settleAllPromises(promiseResultMap); // Verify if the service zip code or registration zip code provided is serviceable - const serviceZipValidationPromise = this.serviceZipCode ? this.validateZip(this.serviceZipCode) : this.validateZip(this.customerQuestions.addressQuestions.zipCode); - - const vinLookupResponse = await vinLookupPromise; - const serviceZipValidationResponse = await serviceZipValidationPromise; - - if (!vinLookupResponse.data.isStatePermissible) { + if (!resultMap.vinLookupResponse.isStatePermissible) { // State Restrictions forbid lookup by address this.displayVinLookupByHomeAddressNotAllowedAlert = true; - this.$refs.funnelFooter.removeLoader(); - return; + return this.$refs.funnelFooter.removeLoader(); } // if the neither the registration zip code or service zip code are not serviceable - this.isZipServicable = serviceZipValidationResponse.data.isServiceable; - if (!this.isZipServicable) { + this.isZipServiceable = resultMap.serviceZipValidationResponse.isServiceable; + + if (!this.isZipServiceable) { this.displayNonServiceableZipAlert = true; this.showServiceZipField = true; - this.$refs.funnelFooter.removeLoader(); - } else if (!this.serviceZipCode) { - // if the registration zip code is servicable and nothing was entered for the service zip code - // then set the service zip code to the registration zip code + return this.$refs.funnelFooter.removeLoader(); + } + + // if the registration zip code is serviceable and nothing was entered for the service zip code + // then set the service zip code to the registration zip code + if (!this.serviceZipCode) { this.serviceZipCode = this.customerQuestions.addressQuestions.zipCode; } - const carEntered = store.getters.vehicle; - const carsFound = vinLookupResponse.data.vinVehicles; + //const carEntered = store.getters.vehicle; + const vinsFound = resultMap.vinLookupResponse.vinVehicles; - if (carsFound.length == 0) { - // No VINs found + // No VINs found + if (vinsFound.length == 0) { this.displayVinNotFoundAlert = true; - this.$refs.funnelFooter.removeLoader(); - return; - } else if (carsFound.length == 1) { - const carFound = carsFound[0].vehicle; - this.isCarIdDifferent = carFound.carId !== carEntered.carId; + return this.$refs.funnelFooter.removeLoader(); + } + + // Single VIN found + if (vinsFound.length == 1) { + const carFound = vinsFound[0].vehicle; + this.isCarIdDifferent = carFound.carId !== this.$store.getters.vehicle.carId; if (this.isCarIdDifferent && carFound.carId !== this.previouslyEnteredCarId) { // Display Alert @@ -242,49 +257,93 @@ export default { // Update button "Continue with..." this.$refs.funnelFooter.updateButtonText(`Continue with ${carFound.year} ${carFound.make} ${carFound.model}`); - this.$refs.funnelFooter.removeLoader(); + return this.$refs.funnelFooter.removeLoader(); + } + if (!this.isZipServiceable) { return; } - if (!this.isZipServicable) { - return; - } + // update data if the zip or service zip is serviceable - // update data if the zip or service zip is servicable - this.updateVehicleInfo(carsFound[0].vin, carFound); - this.updateCustomerInfo(serviceZipValidationResponse.data.state); + // --> New Save Method - } else if (carsFound.length > 1) { - if (!this.isZipServicable) { + // state.order.vehicle.registration.licensePlate = registrationInfo?.licensePlate; + // state.order.vehicle.registration.address = registrationInfo?.address; + // state.order.vehicle.registration.city = registrationInfo?.city; + // state.order.vehicle.registration.state = registrationInfo?.state; + // state.order.vehicle.registration.zipCode = registrationInfo?.zipCode; + // state.order.vehicle.registration.firstName = registrationInfo?.firstName; + // state.order.vehicle.registration.lastName = registrationInfo?.lastName; + + vehicleInfoToCommit = Object.assign(carFound, { vin: vinsFound[0].vin}); + registrationInfoToCommit = { + firstName: this.customerQuestions.firstName, + lastName: this.customerQuestions.lastName, + address: this.customerQuestions.addressQuestions.streetAddress, + city: this.customerQuestions.addressQuestions.city, + state: this.customerQuestions.addressQuestions.state, + zipCode: this.customerQuestions.addressQuestions.zipCode + }; + + this.updateVehicleInfo(vinsFound[0].vin, carFound); + this.updateCustomerInfo(resultMap.serviceZipValidationResponse.state); + + } + + // Found more than one VIN. + if (vinsFound.length > 1) { + if (!this.isZipServiceable) { return; } // if multiple cars were found - let matchingCars = carsFound.filter(car => car.vehicle.carId === carEntered.carId); + const matchingCars = vinsFound.filter(vin => vin.vehicle.carId === this.$store.getters.vehicle.carId); + + // and one and only one of them matches the carId entered, save the vehicle info + // so we can go to the Heritage Funnel directly if (matchingCars.length === 1) { - // and one and only one of them matches the carId entered, save the vehicle info - // so we can go to the Heritage Funnel directly - const matchingCar = matchingCars[0]; - this.updateVehicleInfo(matchingCar.vin, matchingCar.vehicle); + + this.updateVehicleInfo(matchingCars[0].vin, matchingCars[0].vehicle); } - // update data if the zip or service zip is servicable - this.updateCustomerInfo(serviceZipValidationResponse.data.state); + // update data if the zip or service zip is serviceable. + this.updateCustomerInfo(resultMap.serviceZipValidationResponse.state); } - this.navigateForward(carEntered, carsFound); + // store.commit(storeMutations.UPDATE_REGISTRATION_ADDRESS, this.customerQuestions.addressQuestions.streetAddress); + // store.commit(storeMutations.UPDATE_REGISTRATION_CITY, this.customerQuestions.addressQuestions.city); + // store.commit(storeMutations.UPDATE_REGISTRATION_STATE, this.customerQuestions.addressQuestions.state); + // store.commit(storeMutations.UPDATE_REGISTRATION_ZIP_CODE, this.customerQuestions.addressQuestions.zipCode); + // store.commit(storeMutations.UPDATE_REGISTRATION_FIRST_NAME, this.customerQuestions.firstName); + // store.commit(storeMutations.UPDATE_REGISTRATION_LAST_NAME, this.customerQuestions.lastName); + // store.commit(storeMutations.UPDATE_SERVICE_LOCATION_ZIP_CODE, this.serviceZipCode); + // store.commit(storeMutations.UPDATE_SERVICE_LOCATION_STATE, serviceState); + // store.commit(storeMutations.UPDATE_CUSTOMER_EMAIL_ADDRESS, this.customerQuestions.emailAddress); + + // Save vin, vehicle, customer, service and registration information + await this.dispatchStoreAction(storeActions.SAVE_REGISTRATION_LICENSE_PLATE_LOOKUP, { + isCarIdDifferent: this.isCarIdDifferent, + isSelectedGlassAvailableForVehicle: this.isSelectedGlassAvailableForVehicle, + vehicleInfo: Object.assign(vinLookup.data.vehicle, { vin: vinLookup.data.vin }), + serviceLocationInfo: { + zipCode: this.serviceZip, + state: resultMap.serviceZipValidationResponse.state, + }, + registrationInfo: { + licensePlate: this.licensePlate, + state: resultMap.registrationZipValidationResponse.state, + zipCode: this.registrationZip, + }, + customerEmail: this.email, + }, false); + + return await this.navigateForward(carEntered, vinsFound); }, - resetWarningsAndErrors() { - this.displayVinNotFoundAlert = false; - this.displayNonServiceableZipAlert = false; - this.displayMatchedDifferentVehicleAlert = false; - this.displayVinLookupByHomeAddressNotAllowedAlert = false; - }, - navigateForward(carEntered, carsFound) { + async navigateForward(carEntered, vinsFound) { this.updateServiceLocationIfNecessary(); - if (carsFound.length == 1) { + if (vinsFound.length == 1) { // if a different vehicle is found than the one entered and the selected glass // is not available for that vehicle if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) { @@ -298,11 +357,11 @@ export default { ); } else { // otherwise - this.navigateForwardWithSingleCarMatch(); + await this.navigateForwardWithSingleCarMatch(); } - } else if (carsFound.length > 1) { + } else if (vinsFound.length > 1) { // if multiple cars were found - let matchingCars = carsFound.filter(car => car.vehicle.carId === carEntered.carId); + let matchingCars = vinsFound.filter(car => car.vehicle.carId === carEntered.carId); if (matchingCars.length === 1) { // and one and only of them matches the car id entered const matchingCar = matchingCars[0]; @@ -310,39 +369,18 @@ export default { this.navigateForwardWithSingleCarMatch(); } else { // if there are no matches or there are multiple matches, navigate to "address-vehicles" page - this.$router.navigate(this.navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, this.$route, {}, {}, carsFound); + this.$router.navigate(this.navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, this.$route, {}, {}, vinsFound); } } }, - validateZip(zip) { - return this.dispatchStoreAction( - storeActions.VALIDATE_ZIP, - { zip }); - }, - lookupVin(lastName, streetAddress, zip, state) { - return this.dispatchStoreAction( - storeActions.LOOKUP_VIN_BY_ADDRESS, - { - licenseLastName: lastName, - licenseStreetAddress: streetAddress, - licenseZip: zip, - licenseState: state - }, false - ); - }, - updateVehicleInfo(vin, vehicleInfo) { - store.commit(storeMutations.UPDATE_VEHICLE_VIN, vin); - store.commit(storeMutations.UPDATE_YEAR, vehicleInfo.year); - store.commit(storeMutations.UPDATE_MAKE, vehicleInfo.make); - store.commit(storeMutations.UPDATE_MODEL, vehicleInfo.model); - store.commit(storeMutations.UPDATE_STYLE, vehicleInfo.style); - store.commit(storeMutations.UPDATE_CAR_ID, vehicleInfo.carId); - store.commit(storeMutations.UPDATE_VEHICLE_CATEGORY, vehicleInfo.category); - store.commit(storeMutations.UPDATE_VEHICLE_IMAGE_URL, vehicleInfo.imageUrl); - store.commit(storeMutations.UPDATE_VEHICLE_IMAGE_VIF_NUMBER, vehicleInfo.imageVifNumber); - store.commit(storeMutations.UPDATE_VEHICLE_IMAGE_COLOR, vehicleInfo.imageColor); + resetWarningsAndErrors() { + this.displayVinNotFoundAlert = false; + this.displayNonServiceableZipAlert = false; + this.displayMatchedDifferentVehicleAlert = false; + this.displayVinLookupByHomeAddressNotAllowedAlert = false; }, + updateCustomerInfo(serviceState) { store.commit(storeMutations.UPDATE_REGISTRATION_ADDRESS, this.customerQuestions.addressQuestions.streetAddress); store.commit(storeMutations.UPDATE_REGISTRATION_CITY, this.customerQuestions.addressQuestions.city); diff --git a/src/layouts/address-vehicles/address-vehicles.spec.js b/src/layouts/address-vehicles/address-vehicles.spec.js index fcccb1d94..8dcadae22 100644 --- a/src/layouts/address-vehicles/address-vehicles.spec.js +++ b/src/layouts/address-vehicles/address-vehicles.spec.js @@ -230,7 +230,7 @@ describe("addressVehicles.vue", () => { const { wrapper } = setupMocks({}); wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn(); wrapper.vm.$refs.loadingModal.showModal = jest.fn(); - navigateToHeritage.navigateAfterSaveToHeritageFunnel = jest.fn(); + navigateToHeritage.navigateToHeritageFunnel = jest.fn(); // Act await wrapper.setData({ diff --git a/src/layouts/license-plate-lookup/license-plate-lookup.spec.js b/src/layouts/license-plate-lookup/license-plate-lookup.spec.js index 3ae226fca..ea89df224 100644 --- a/src/layouts/license-plate-lookup/license-plate-lookup.spec.js +++ b/src/layouts/license-plate-lookup/license-plate-lookup.spec.js @@ -246,7 +246,7 @@ describe("license-plate-lookup.vue", () => { expect(wrapper.vm.$router.navigateAfterSave).toHaveBeenCalled(); }); - test("navigateAfterSaveToHeritageFunnel should be called if isCarIdDifferent is false or isSelectedGlassAvailableForVehicle is true when navigateForward is called", async () => { + test("navigateToHeritageFunnel should be called if isCarIdDifferent is false or isSelectedGlassAvailableForVehicle is true when navigateForward is called", async () => { // Arrange const { wrapper } = setupMocks({}); @@ -258,11 +258,11 @@ describe("license-plate-lookup.vue", () => { wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => { return ''; }); - navigateToHeritage.navigateAfterSaveToHeritageFunnel = jest.fn(); + navigateToHeritage.navigateToHeritageFunnel = jest.fn(); await wrapper.vm.navigateForward(); //Assert - expect(navigateToHeritage.navigateAfterSaveToHeritageFunnel).toHaveBeenCalled(); + expect(navigateToHeritage.navigateToHeritageFunnel).toHaveBeenCalled(); }); test("carId matches returned vehicle => navigateForwardWithSingleCarMatch", async () => { @@ -366,7 +366,7 @@ describe("license-plate-lookup.vue", () => { wrapper.vm.lookupVin = jest.fn().mockImplementation(() => new Promise(resolve => resolve(vinLookup))); await wrapper.setData({ registrationZip: "00000" }); - navigateToHeritage.navigateAfterSaveToHeritageFunnel = jest.fn(); + navigateToHeritage.navigateToHeritageFunnel = jest.fn(); // Act await wrapper.vm.forwardButtonAction(); @@ -385,7 +385,7 @@ describe("license-plate-lookup.vue", () => { }); await wrapper.setData({ registrationZip: "00000" }); - navigateToHeritage.navigateAfterSaveToHeritageFunnel = jest.fn(); + navigateToHeritage.navigateToHeritageFunnel = jest.fn(); // Act await wrapper.vm.forwardButtonAction(); @@ -404,7 +404,7 @@ describe("license-plate-lookup.vue", () => { }); await wrapper.setData({ registrationZip: "00000" }); - navigateToHeritage.navigateAfterSaveToHeritageFunnel = jest.fn(); + navigateToHeritage.navigateToHeritageFunnel = jest.fn(); await wrapper.vm.forwardButtonAction(); wrapper.vm.$router.navigateAfterSave = jest.fn(); // At this point, serviceZip field is shown @@ -417,7 +417,7 @@ describe("license-plate-lookup.vue", () => { const serviceZipField = wrapper.findComponent("[cmsWidgetName='ServiceZip']"); expect(serviceZipField.exists()).toBe(true); expect(serviceZipField.isVisible()).toBe(true); 3 - expect(navigateToHeritage.navigateAfterSaveToHeritageFunnel).not.toHaveBeenCalled(); + expect(navigateToHeritage.navigateToHeritageFunnel).not.toHaveBeenCalled(); expect(wrapper.vm.$router.navigateAfterSave).not.toHaveBeenCalled(); }); diff --git a/src/layouts/license-plate-lookup/license-plate-lookup.vue b/src/layouts/license-plate-lookup/license-plate-lookup.vue index dbce9f3fc..c92dda00b 100644 --- a/src/layouts/license-plate-lookup/license-plate-lookup.vue +++ b/src/layouts/license-plate-lookup/license-plate-lookup.vue @@ -50,13 +50,13 @@ class="my-3" :manualHeadline="NoServiceZipHeader" :manualCopy="NoServiceZipBody" - v-if="!isRegistrationZipServicable && isVinValid && !isCarIdDifferent" + v-if="!isRegistrationZipServiceable && isVinValid && !isCarIdDifferent" alertClass="alert-danger" />