diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index c4c5d876..02de2756 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -26,6 +26,10 @@ const endpoints = { GetVehicleStyles: { url: "/vehicle/api/v1/vehicle/styles", method: "GET", + }, + GetVehicle: { + url: "/vehicle/api/v1/vehicle/lookup", + method: "GET", } }; diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js deleted file mode 100644 index ff3d60fb..00000000 --- a/src/constants/store-actions.js +++ /dev/null @@ -1,9 +0,0 @@ -const storeActions = { - // Content Actions - GET_ROUTE_INFO_ACTION: "getRouteInfo", - GET_HOMEPAGE_NAME: "getHomepageName", - GET_PAGE_DATA: "getPageData", - }; - - export { storeActions }; - \ No newline at end of file diff --git a/src/helpers/unit-test-helper.js b/src/helpers/unit-test-helper.js index c52adf5d..a71d616f 100644 --- a/src/helpers/unit-test-helper.js +++ b/src/helpers/unit-test-helper.js @@ -1,4 +1,3 @@ -import { storeActions } from "@/constants/store-actions"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios.js"; import { vehicleCategories } from "@/constants/vehicle-categories.js"; import { issPageValues } from "@/router/router-constants/issPage-values"; @@ -28,7 +27,6 @@ export function getMountOptions(mockData) { // Mock const files - mocks.storeActions = storeActions; mocks.navigationScenarios = navigationScenarios; mocks.vehicleCategories = vehicleCategories; mocks.issPageValues = issPageValues; diff --git a/src/layouts/vehicle-style/vehicle-style.vue b/src/layouts/vehicle-style/vehicle-style.vue index 531c6693..9d35ae65 100644 --- a/src/layouts/vehicle-style/vehicle-style.vue +++ b/src/layouts/vehicle-style/vehicle-style.vue @@ -77,11 +77,13 @@ export default { watch: { selectedStyle(style) { - this.mainStore.updateVehicleStyle(style); - this.$router.navigate( - this.navigationScenarios.SELECTED_STYLE, - this.$route - ); + this.mainStore.updateVehicle({style}) + this.mainStore.setVehicle(style).then(() => { + this.$router.navigate( + this.navigationScenarios.SELECTED_STYLE, + this.$route + ); + }); }, }, diff --git a/src/mixins/base-mixin.js b/src/mixins/base-mixin.js index 61a358be..a3c4c41e 100644 --- a/src/mixins/base-mixin.js +++ b/src/mixins/base-mixin.js @@ -1,4 +1,3 @@ -import { storeActions } from "@/constants/store-actions.js"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import { vehicleCategories } from "@/constants/vehicle-categories.js"; import { queryStrings } from "@/constants/query-strings"; @@ -27,9 +26,6 @@ export default { computed: { // store will be accessible globally as its id + 'Store' ...mapStores(useMainStore), - storeActions() { - return storeActions; - }, navigationScenarios() { return navigationScenarios; }, diff --git a/src/store/index.js b/src/store/index.js index 80f9b966..2c733ed7 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -118,34 +118,24 @@ export const useMainStore = defineStore({ }); }, - // Vehicle API Actions - updateVehicleYear(year) - { - if (this.order.vehicle.year !== year) { - this.order.vehicle.year = year; - } + setVehicle() { + return globalMethods + .callHttpClient({ + methods: endpoints.GetVehicle.method, + endpoint: `${endpoints.GetVehicle.url}/${this.order.vehicle.year}/${this.order.vehicle.make}/${this.order.vehicle.model}/${this.order.vehicle.style}`, + payload: {}, + }) + .then((response) => { + this.updateVehicle(response.data); + return response; + }); }, - updateVehicleMake(make) + updateVehicle(vehicle) { - if (this.order.vehicle.make !== make) { - this.order.vehicle.make = make; - } - }, - - updateVehicleModel(model) - { - if (this.order.vehicle.model !== model) { - this.order.vehicle.model = model; - } - }, - - updateVehicleStyle(style) - { - if (this.order.vehicle.style !== style) { - this.order.vehicle.style = style; - } + this.order.vehicle = { ...this.order.vehicle, ...vehicle }; }, + addEventToBus (event) { this.applicationUser.eventBus.push(event); }, diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 9f5db937..4c1160b3 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -1,6 +1,7 @@ import { useMainStore } from "./" import { createApp } from 'vue'; import { createPinia } from "pinia"; +import globalMethods from "@/global-methods"; import App from '@/App.vue'; @@ -18,13 +19,6 @@ describe("Store", () => { jest.resetAllMocks(); }) - - it("Should Store Vehicle Year", () => { - let testYear = "2001"; - store.updateVehicleYear(testYear); - expect(store.order.vehicle.year).toEqual(testYear); - }); - it("Should add events to the bus", () => { let event = { category: "TestCategory", @@ -82,4 +76,59 @@ describe("Store", () => { expect(actual).toEqual(event.eventValue); }); + it("UpdateVehicle should merge vehicle with response object", () => { + store.order.vehicle = { + year: 2020, + make: "Honda", + model: "Civic", + style: "4 door sedan", + carId: null, + category: null, + vin: null, + imageUrl: null, + imageVifNumber: null, + imageColor: null, + }; + + const response = { + "carId": "CR00069299", + "category": "CAR", + "year": 2020, + "make": "Honda", + "model": "Civic", + "style": "4 door sedan", + "imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg", + "imageVifNumber": "13996", + "imageVifColor": "white" + }; + + store.updateVehicle(response); + + expect(store.order.vehicle.imageUrl).toEqual(response.imageUrl); + expect(store.order.vehicle.imageVifNumber).toEqual(response.imageVifNumber); + expect(store.order.vehicle.imageVifColor).toEqual(response.imageVifColor); + }); + + it("setVehicle should call globalMethods.callHttpClient", () => { + store.order.vehicle = jest.fn(); + + const response = { + "carId": "CR00069299", + "category": "CAR", + "year": 2020, + "make": "Honda", + "model": "Civic", + "style": "4 door sedan", + "imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg", + "imageVifNumber": "13996", + "imageVifColor": "white" + }; + + globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); + + store.setVehicle(); + + expect(globalMethods.callHttpClient).toHaveBeenCalled(); + }); + }); \ No newline at end of file