From 74af79a8f3e2cd26d09dada93e7bfa88efbce258 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Tue, 20 Jun 2023 16:11:51 -0400 Subject: [PATCH] Add tests for serviceZipCodeInfo and serviceLocation save methods --- src/store/store.spec.js | 314 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 314 insertions(+) diff --git a/src/store/store.spec.js b/src/store/store.spec.js index e35e463c6..8bb15311a 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -936,6 +936,84 @@ describe("Actions", () => { ); }); + it("saveServiceZipCodeInfo, should call mutation and save zip code to state", () => { + // Arrange + const context = state; + const commit = jest.fn(); + context.commit = commit; + + const serviceZipCodeInfo = { + zipCode: "43212", + }; + + // Act + actions.saveServiceLocation(context, serviceZipCodeInfo); + + // 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", () => { + // Arrange + const context = { + state: { + order: { + serviceLocation: { + zipCode: "43212", + }, + }, + }, + }; + + const commit = jest.fn(); + const dispatch = jest.fn(); + + context.commit = commit; + context.dispatch = dispatch; + + const serviceZipCodeInfo = { + zipCode: "43202", + }; + + // Act + actions.saveServiceZipCodeInfo(context, serviceZipCodeInfo); + + // Assert + expect(dispatch).toHaveBeenCalledWith(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES); + expect(commit).toHaveBeenCalledWith(storeMutations.RESET_SERVICE_LOCATION_MOBILE_ADDRESS); + }); + + it("saveServiceZipCodeInfo, should not reset if zip code is the same", () => { + // Arrange + const context = { + state: { + order: { + serviceLocation: { + zipCode: "43212", + }, + }, + }, + }; + + const commit = jest.fn(); + const dispatch = jest.fn(); + + context.commit = commit; + context.dispatch = dispatch; + + const serviceZipCodeInfo = { + zipCode: "43212", + }; + + // Act + actions.saveServiceZipCodeInfo(context, serviceZipCodeInfo); + + // Assert + expect(dispatch).not.toHaveBeenCalledWith(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES); + expect(commit).not.toHaveBeenCalledWith(storeMutations.RESET_SERVICE_LOCATION_MOBILE_ADDRESS); + }); + it("saveServiceLocation, should call mutation and save service address to state", () => { // Arrange const context = state; @@ -962,6 +1040,242 @@ describe("Actions", () => { expect(state.order.serviceLocation.zipCodeCtu).toEqual("01820"); }); + it("saveServiceLocation, should reset if zipcode is different", () => { + // Arrange + const context = { + state: { + order: { + serviceLocation: { + address: "123 Test Lane", + city: "Columbus", + zipCode: "43212", + state: "OH", + zipCodeCtu: "01820", + appointmentType: "Mobile", + isVehicleProtected: true, + provider: { + providerNumber: "11111", + address: { + streetAddress: "123 Test Lane", + city: "Columbus", + state: "OH", + zip: "43212", + }, + }, + }, + }, + }, + }; + + const commit = jest.fn(); + const dispatch = jest.fn(); + + context.commit = commit; + context.dispatch = dispatch; + + const serviceLocation = { + address: "123 Test Lane", + city: "Columbus", + zipCode: "43202", + state: "OH", + zipCodeCtu: "01820", + appointmentType: "Mobile", + isVehicleProtected: true, + provider: { + providerNumber: "11111", + address: { + streetAddress: "123 Test Lane", + city: "Columbus", + state: "OH", + zip: "43212", + }, + }, + }; + + // Act + actions.saveServiceLocation(context, serviceLocation); + + // Assert + expect(commit).toHaveBeenCalledWith(storeMutations.RESET_SCHEDULE); + }); + + it("saveServiceLocation, should reset if provider is different", () => { + // Arrange + const context = { + state: { + order: { + serviceLocation: { + address: "123 Test Lane", + city: "Columbus", + zipCode: "43212", + state: "OH", + zipCodeCtu: "01820", + appointmentType: "Mobile", + isVehicleProtected: true, + provider: { + providerNumber: "11111", + address: { + streetAddress: "123 Test Lane", + city: "Columbus", + state: "OH", + zip: "43212", + }, + }, + }, + }, + }, + }; + + const commit = jest.fn(); + const dispatch = jest.fn(); + + context.commit = commit; + context.dispatch = dispatch; + + const serviceLocation = { + address: "123 Test Lane", + city: "Columbus", + zipCode: "43212", + state: "OH", + zipCodeCtu: "01820", + appointmentType: "Mobile", + isVehicleProtected: true, + provider: { + providerNumber: "22222", + address: { + streetAddress: "321 Test Lane", + city: "Columbus", + state: "OH", + zip: "43212", + }, + }, + }; + + // Act + actions.saveServiceLocation(context, serviceLocation); + + // Assert + expect(commit).toHaveBeenCalledWith(storeMutations.RESET_SCHEDULE); + }); + + it("saveServiceLocation, should reset if appointment type is different", () => { + // Arrange + const context = { + state: { + order: { + serviceLocation: { + address: "123 Test Lane", + city: "Columbus", + zipCode: "43212", + state: "OH", + zipCodeCtu: "01820", + appointmentType: "Mobile", + isVehicleProtected: true, + provider: { + providerNumber: "11111", + address: { + streetAddress: "123 Test Lane", + city: "Columbus", + state: "OH", + zip: "43212", + }, + }, + }, + }, + }, + }; + + const commit = jest.fn(); + const dispatch = jest.fn(); + + context.commit = commit; + context.dispatch = dispatch; + + const serviceLocation = { + address: "123 Test Lane", + city: "Columbus", + zipCode: "43212", + state: "OH", + zipCodeCtu: "01820", + appointmentType: "Inshop", + isVehicleProtected: true, + provider: { + providerNumber: "11111", + address: { + streetAddress: "123 Test Lane", + city: "Columbus", + state: "OH", + zip: "43212", + }, + }, + }; + + // Act + actions.saveServiceLocation(context, serviceLocation); + + // Assert + expect(commit).toHaveBeenCalledWith(storeMutations.RESET_SCHEDULE); + }); + + it("saveServiceLocation, should not reset if parameters are the same", () => { + // Arrange + const context = { + state: { + order: { + serviceLocation: { + address: "123 Test Lane", + city: "Columbus", + zipCode: "43212", + state: "OH", + zipCodeCtu: "01820", + appointmentType: "Mobile", + isVehicleProtected: true, + provider: { + providerNumber: "11111", + address: { + streetAddress: "123 Test Lane", + city: "Columbus", + state: "OH", + zip: "43212", + }, + }, + }, + }, + }, + }; + + const commit = jest.fn(); + const dispatch = jest.fn(); + + context.commit = commit; + context.dispatch = dispatch; + + const serviceLocation = { + address: "123 Test Lane", + city: "Columbus", + zipCode: "43212", + state: "OH", + zipCodeCtu: "01820", + appointmentType: "Mobile", + isVehicleProtected: true, + provider: { + providerNumber: "11111", + address: { + streetAddress: "123 Test Lane", + city: "Columbus", + state: "OH", + zip: "43212", + }, + }, + }; + + // Act + actions.saveServiceLocation(context, serviceLocation); + + // Assert + expect(commit).not.toHaveBeenCalledWith(storeMutations.RESET_SCHEDULE); + }); + it("saveGlassParts, should call mutation", () => { // Arrange const context = {