From ad4b53a4b752a105cefeb07f18ab4afa97a7472a Mon Sep 17 00:00:00 2001 From: CarlNation <32103961+CarlNation@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:38:32 -0400 Subject: [PATCH 1/2] CSR-1654 only save customer name on address lookup if it's not already in the store --- src/layouts/address-lookup/address-lookup.vue | 2 +- src/store/index.js | 29 ++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/layouts/address-lookup/address-lookup.vue b/src/layouts/address-lookup/address-lookup.vue index 48ab0dd08..f0bf91325 100644 --- a/src/layouts/address-lookup/address-lookup.vue +++ b/src/layouts/address-lookup/address-lookup.vue @@ -320,7 +320,7 @@ export default { Object.keys(vehicleInfoToCommit).length === 0 ? this.$store.getters.vehicle : vehicleInfoToCommit, - registrationInfo: { + customerInfo: { firstName: this.customerQuestions.firstName, lastName: this.customerQuestions.lastName, }, diff --git a/src/store/index.js b/src/store/index.js index 976ef0d2e..95a028aae 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -234,8 +234,6 @@ export const mutations = { }, updateRegistration(state, registrationInfo) { state.order.vehicle.registration.licensePlate = registrationInfo?.licensePlate; - state.order.customer.firstName = registrationInfo?.firstName; - state.order.customer.lastName = registrationInfo?.lastName; }, updateServiceZip(state, serviceZipInfo) { state.order.serviceLocation.state = serviceZipInfo.state; @@ -1662,15 +1660,25 @@ export const actions = { context.dispatch(storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES); } - //Save new values context.commit(storeMutations.UPDATE_VEHICLE, vehicleInfo); - context.commit(storeMutations.UPDATE_REGISTRATION, registrationInfo); + + if (registrationInfo) { + context.commit(storeMutations.UPDATE_REGISTRATION, registrationInfo); + + // only update name information if there isn't a value in state already + if (!context.getters.order.customer.firstName) { + context.commit(storeMutations.UPDATE_CUSTOMER_DETAILS, { + firstName: registrationInfo.firstName, + lastName: registrationInfo.lastName, + }); + } + } } }, saveRegistrationAddressLookup( context, - { isSelectedGlassAvailableForVehicle, vehicleInfo, registrationInfo } + { isSelectedGlassAvailableForVehicle, vehicleInfo, customerInfo } ) { //Reset dependent state when changing if (vehicleInfo.vin !== context.state.order.vehicle.vin) { @@ -1681,9 +1689,14 @@ export const actions = { } } - if (registrationInfo) { - context.commit(storeMutations.UPDATE_VEHICLE, vehicleInfo); - context.commit(storeMutations.UPDATE_REGISTRATION, registrationInfo); + context.commit(storeMutations.UPDATE_VEHICLE, vehicleInfo); + + // only update name information if there isn't a value in state already + if (!context.getters.order.customer.firstName && customerInfo) { + context.commit(storeMutations.UPDATE_CUSTOMER_DETAILS, { + firstName: customerInfo.firstName, + lastName: customerInfo.lastName, + }); } }, From cd1354bc6dbada3a684e62ccd70d89a0e03b818d Mon Sep 17 00:00:00 2001 From: CarlNation Date: Wed, 13 Sep 2023 13:37:51 -0400 Subject: [PATCH 2/2] CSR-1564 tests --- src/store/store.spec.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/store/store.spec.js b/src/store/store.spec.js index ded194ba8..947299ff8 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -1492,9 +1492,18 @@ describe("Actions", () => { licensePlate: "ABC123", }, }, + customer: { + firstName: "test", + lastName: "test", + }, }, }; + context.getters = { + ...getters, + order: getters.order(context), + }; + const commit = jest.fn(); const dispatch = jest.fn(); @@ -1538,9 +1547,18 @@ describe("Actions", () => { address: "123 Main St", }, }, + customer: { + firstName: "test", + lastName: "test", + }, }, }; + context.getters = { + ...getters, + order: getters.order(context), + }; + const commit = jest.fn(); const dispatch = jest.fn(); @@ -1552,7 +1570,7 @@ describe("Actions", () => { isCarIdDifferent: true, isSelectedGlassAvailableForVehicle: false, vehicleInfo: { carId: "C010101", vin: "XXXXX" }, - registrationInfo: { firstName: "abc", lastName: "123" }, + customerInfo: { firstName: "abc", lastName: "123" }, serviceLocationInfo: { state: "CO" }, customerEmail: "test@safelite.com", }; @@ -1570,7 +1588,6 @@ describe("Actions", () => { ); expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE, payload.vehicleInfo); - expect(commit).toBeCalledWith(storeMutations.UPDATE_REGISTRATION, payload.registrationInfo); }); it("saveVehicle, should save vehicle info", () => {