From d7908620a766f1b61dbf71f4443c56a8e761c8a3 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 5 Apr 2022 14:08:21 -0400 Subject: [PATCH] updates for unit tests and code coverage --- jest.config.js | 3 ++- src/constants/endpoints.js | 2 +- src/store/index.js | 44 ++++++++++++++++++----------------- src/store/store.spec.js | 47 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 23 deletions(-) diff --git a/jest.config.js b/jest.config.js index c108399b7..c1edf3074 100644 --- a/jest.config.js +++ b/jest.config.js @@ -34,7 +34,8 @@ module.exports = { testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"], coverageThreshold: { global: { - statements: 89, + statements: 87, + // Got the go ahead from Mark to temporarily lower this. Taking out initialize component made the year,make,model and style coverage drop a bit. Once unit tests for license plate lookup, vin lookup and address lookup are in the coverage should go back up to 90 }, }, }; diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 236197cc2..2aa1fe226 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -58,7 +58,7 @@ const endpoints = { LoadOrder: { url: "/order/api/v1/order/load", method: "POST", - } + }, ValidateZip: { url: "/location/api/v1/location/zip", method: "GET", diff --git a/src/store/index.js b/src/store/index.js index 099e8dbcf..b1a8f4da1 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -6,27 +6,29 @@ import createPersistedState from "vuex-persistedstate"; import globalMethods from "@/global-methods"; // Export State -export const state = { - order: { - vehicle: { - year: null, - make: null, - model: null, - style: null, - carId: null, - category: null, - imageUrl: null, - imageVifNumber: null, - imageColor: null, - vin: null, - registration: { - licensePlate: null, - address: null, - city: null, - state: null, - zipCode: null, - firstName: null, - lastName: null, +const getDefaultState = () => { + return { + order: { + vehicle: { + year: null, + make: null, + model: null, + style: null, + carId: null, + category: null, + vin: null, + imageUrl: null, + imageVifNumber: null, + imageColor: null, + registration: { + licensePlate: null, + address: null, + city: null, + state: null, + zipCode: null, + firstName: null, + lastName: null, + }, }, serviceLocation: { zip: null, diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 5c7e0c881..dc743d1ae 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -283,6 +283,22 @@ describe("Actions", () => { expect(response.data).toEqual({ carId: "C00000001" }); }); + it("lookupVinByPlate action, should return car data", async () => { + + // Arrange + const context = state; + + // Act + globalMethods.callHttpClient.mockImplementation(() => { + return Promise.resolve({ data: { carId: "C00000001" } }); + }); + + // Assert + const response = await actions.lookupVinByPlate(context, "12345678901234567") + + expect(response.data).toEqual({ carId: "C00000001" }); + }); + it("getVehicleMakes action, should return makes list", async () => { // Arrange @@ -368,6 +384,22 @@ describe("Actions", () => { expect(response.data).toEqual(["Windshield", "DriversFrontDoor"]); }); + it("validateZip action", async () => { + + // Arrange + const context = state; + + // Act + globalMethods.callHttpClient.mockImplementation(() => { + return Promise.resolve({ data: "43201" }); + }); + + const response = await actions.validateZip(context, "C00000000") + + // Assert + expect(response.data).toEqual("43201"); + }); + it("resetVehicleAndDependencies action", async () => { // Arrange @@ -432,6 +464,21 @@ describe("Actions", () => { }); + it("resetState action", async () => { + + // Arrange + const context = state; + const commit = jest.fn(); + + context.commit = commit; + + // Act + await actions.resetState(context) + + expect(commit).toBeCalledWith(storeMutations.RESET_STATE); + + }); + it("getRouteInfo action, returns route info", async () => { // Arrange