From 8608c689065ccb6ced90a8882f1322e4e3741227 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Wed, 9 Aug 2023 10:19:58 -0400 Subject: [PATCH 1/4] CSR-1422 - Added unit tests and other tech review changes --- src/constants/store-mutations.js | 4 +- .../customer-details/customer-details.vue | 10 ++-- src/store/index.js | 8 +-- src/store/store.spec.js | 53 ++++++++++++++++--- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/constants/store-mutations.js b/src/constants/store-mutations.js index 7b57187c2..2c249750d 100644 --- a/src/constants/store-mutations.js +++ b/src/constants/store-mutations.js @@ -35,12 +35,10 @@ const storeMutations = { UPDATE_SERVICE_ZIP: "updateServiceZip", UPDATE_SERVICE_LOCATION: "updateServiceLocation", UPDATE_SERVICE_LOCATION_TECH_NOTES: "updateServiceLocationTechNotes", - UPDATE_TECH_NOTES: "updateTechNotes", UPDATE_SCHEDULE: "updateSchedule", - UPDATE_CUSTOMER_EMAIL_ADDRESS: "updateCustomerEmailAddress", - // CUSTOMER MUTATIONS + UPDATE_CUSTOMER_EMAIL_ADDRESS: "updateCustomerEmailAddress", UPDATE_CUSTOMER_DETAILS: "updateCustomerDetails", // ORDER MUTATIONS diff --git a/src/layouts/customer-details/customer-details.vue b/src/layouts/customer-details/customer-details.vue index be533117f..e91317ca9 100644 --- a/src/layouts/customer-details/customer-details.vue +++ b/src/layouts/customer-details/customer-details.vue @@ -32,7 +32,7 @@ + v-model="isSmsOptIn" /> { lastName: null, emailAddress: null, phoneNumber: null, - isSmsOptin: null, + isSmsOptIn: null, }, damage: { isRepair: null, @@ -291,7 +291,7 @@ export const mutations = { state.order.customer.lastName = customerDetails.lastName; state.order.customer.emailAddress = customerDetails.emailAddress; state.order.customer.phoneNumber = customerDetails.phoneNumber; - state.order.customer.isSmsOptin = customerDetails.isSmsOptin; + state.order.customer.isSmsOptIn = customerDetails.isSmsOptIn; } }, @@ -493,7 +493,7 @@ export const mutations = { state.order.customer.firstName = sessionInformation.order.customer.firstName; state.order.customer.lastName = sessionInformation.order.customer.lastName; state.order.customer.phoneNumber = sessionInformation.order.customer.phoneNumber; - state.order.customer.isSmsOptin = sessionInformation.order.customer.isSmsOptin; + state.order.customer.isSmsOptIn = sessionInformation.order.customer.isSmsOptIn; state.order.existingPromoCode = sessionInformation.order.existingPromoCode; state.applicationUser.experiments = sessionInformation.applicationUser.experiments; @@ -1406,7 +1406,7 @@ export const actions = { emailAddress: order.customer.emailAddress, firstName: order.customer.firstName, lastName: order.customer.lastName, - isSmsOptin: order.customer.isSmsOptin, + isSmsOptIn: order.customer.isSmsOptIn, phoneNumber: order.customer.phoneNumber, }, damage: { diff --git a/src/store/store.spec.js b/src/store/store.spec.js index cecc0f394..626e630eb 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -335,6 +335,28 @@ describe("Mutations", () => { expect(storeState.order.serviceLocation.state).toEqual("OH"); expect(storeState.order.serviceLocation.zipCodeCtu).toEqual("01820"); }); + + it("updateCustomerDetails, should set customer details in state", () => { + // Arrange + const storeState = state; + const customerDetails = { + firstName: "foo", + lastName: "bar", + emailAddress: "foo@bar.com", + phoneNumber: "555-555-5555", + isSmsOptIn: true, + }; + + // Act + mutations.updateCustomerDetails(storeState, customerDetails); + + // Assert + expect(state.order.customer.firstName).toEqual("foo"); + expect(state.order.customer.lastName).toEqual("bar"); + expect(state.order.customer.emailAddress).toEqual("foo@bar.com"); + expect(state.order.customer.phoneNumber).toEqual("555-555-5555"); + expect(state.order.customer.isSmsOptIn).toEqual(true); + }); }); describe("Actions", () => { @@ -938,7 +960,7 @@ describe("Actions", () => { ); }); - it("saveServiceZipCodeInfo, should call mutation and save zip code to state", () => { + it("saveServiceZipCodeInfo, should call mutation", () => { // Arrange const context = state; const commit = jest.fn(); @@ -953,7 +975,6 @@ describe("Actions", () => { // Assert expect(commit).toBeCalledWith(storeMutations.UPDATE_SERVICE_LOCATION, serviceZipCodeInfo); - expect(state.order.serviceLocation.zipCode).toEqual("43212"); }); it("saveServiceZipCodeInfo, should reset if zip code is different", () => { @@ -1022,7 +1043,7 @@ describe("Actions", () => { ); }); - it("saveServiceLocation, should call mutation and save service address to state", () => { + it("saveServiceLocation, should call mutation", () => { // Arrange const context = state; const commit = jest.fn(); @@ -1041,11 +1062,6 @@ describe("Actions", () => { // Assert expect(commit).toBeCalledWith(storeMutations.UPDATE_SERVICE_LOCATION, serviceLocation); - expect(state.order.serviceLocation.address).toEqual("123 Test Lane"); - expect(state.order.serviceLocation.city).toEqual("Columbus"); - expect(state.order.serviceLocation.zipCode).toEqual("43212"); - expect(state.order.serviceLocation.state).toEqual("OH"); - expect(state.order.serviceLocation.zipCodeCtu).toEqual("01820"); }); it("saveServiceLocation, should reset if zipcode is different", () => { @@ -1292,6 +1308,27 @@ describe("Actions", () => { expect(commit).not.toHaveBeenCalledWith(storeMutations.RESET_SCHEDULE); }); + it.only("saveCustomerDetails, should call mutation", () => { + // Arrange + const context = state; + const commit = jest.fn(); + context.commit = commit; + + const customerDetails = { + firstName: "foo", + lastName: "bar", + emailAddress: "foo@bar.com", + phoneNumber: "555-555-5555", + isSmsOptIn: true, + }; + + // Act + actions.saveCustomerDetails(context, customerDetails); + + // Assert + expect(commit).toBeCalledWith(storeMutations.UPDATE_CUSTOMER_DETAILS, customerDetails); + }); + it("saveGlassParts, should call mutation", () => { // Arrange const context = { From 4322a3f370abc280aab104aff88e6d35cd607e25 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Wed, 9 Aug 2023 10:23:24 -0400 Subject: [PATCH 2/4] Removed .only and re-ran Unit tests --- src/store/store.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 626e630eb..82fa2109e 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -1308,7 +1308,7 @@ describe("Actions", () => { expect(commit).not.toHaveBeenCalledWith(storeMutations.RESET_SCHEDULE); }); - it.only("saveCustomerDetails, should call mutation", () => { + it("saveCustomerDetails, should call mutation", () => { // Arrange const context = state; const commit = jest.fn(); From e1b444ac4cf9520c87526cb520d438819bdf64f3 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Wed, 9 Aug 2023 10:24:54 -0400 Subject: [PATCH 3/4] Initial Commit --- src/store/store.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 82fa2109e..e072eb164 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -1327,7 +1327,7 @@ describe("Actions", () => { // Assert expect(commit).toBeCalledWith(storeMutations.UPDATE_CUSTOMER_DETAILS, customerDetails); - }); + }); it("saveGlassParts, should call mutation", () => { // Arrange From 2e455177ae6a3c85256de0ff3a6d2d0ac8b097cf Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Wed, 9 Aug 2023 10:24:54 -0400 Subject: [PATCH 4/4] Prettified --- src/store/store.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 82fa2109e..e072eb164 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -1327,7 +1327,7 @@ describe("Actions", () => { // Assert expect(commit).toBeCalledWith(storeMutations.UPDATE_CUSTOMER_DETAILS, customerDetails); - }); + }); it("saveGlassParts, should call mutation", () => { // Arrange