From 7789d19fbff3745952d8e06e682ade38ec097b55 Mon Sep 17 00:00:00 2001 From: Jason Wheeler Date: Thu, 10 Nov 2022 15:34:54 -0500 Subject: [PATCH 1/5] Created call to getVehicle, refactored setting vehicle properties, updated tests and removed store-actions (it wasn't being used) --- src/constants/endpoints.js | 4 ++ src/constants/store-actions.js | 9 --- src/helpers/unit-test-helper.js | 2 - src/layouts/vehicle-style/vehicle-style.vue | 12 ++-- src/mixins/base-mixin.js | 4 -- src/store/index.js | 38 +++++-------- src/store/store.spec.js | 63 ++++++++++++++++++--- 7 files changed, 81 insertions(+), 51 deletions(-) delete mode 100644 src/constants/store-actions.js 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 From b0d91b022466b5d77dfb567df8a83d6485772073 Mon Sep 17 00:00:00 2001 From: Jason Wheeler Date: Fri, 11 Nov 2022 11:53:08 -0500 Subject: [PATCH 2/5] updated to clear other areas of the vehicle when previous areas are changed --- src/layouts/vehicle-make/vehicle-make.vue | 5 ++++- src/layouts/vehicle-model/vehicle-model.vue | 5 ++++- src/layouts/vehicle-style/vehicle-style.vue | 8 ++++++-- src/layouts/vehicle-year/vehicle-year.vue | 6 +++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/layouts/vehicle-make/vehicle-make.vue b/src/layouts/vehicle-make/vehicle-make.vue index 84000425..9b92378f 100644 --- a/src/layouts/vehicle-make/vehicle-make.vue +++ b/src/layouts/vehicle-make/vehicle-make.vue @@ -90,7 +90,10 @@ }, watch: { selectedMake(make) { - this.mainStore.updateVehicleMake(make); + if(make != this.mainStore.order.vehicle.make) + { + this.mainStore.updateVehicle({make, model: null, style: null}); + } this.$router.navigate( this.navigationScenarios.SELECTED_MAKE, this.$route diff --git a/src/layouts/vehicle-model/vehicle-model.vue b/src/layouts/vehicle-model/vehicle-model.vue index 7cfcdb38..240656d9 100644 --- a/src/layouts/vehicle-model/vehicle-model.vue +++ b/src/layouts/vehicle-model/vehicle-model.vue @@ -83,7 +83,10 @@ watch: { selectedModel(model) { - this.mainStore.updateVehicleModel(model); + if(model != this.mainStore.order.vehicle.model) + { + this.mainStore.updateVehicle({model, style: null}); + } this.$router.navigate( this.navigationScenarios.SELECTED_MODEL, this.$route diff --git a/src/layouts/vehicle-style/vehicle-style.vue b/src/layouts/vehicle-style/vehicle-style.vue index 9d35ae65..8beac5cc 100644 --- a/src/layouts/vehicle-style/vehicle-style.vue +++ b/src/layouts/vehicle-style/vehicle-style.vue @@ -77,8 +77,12 @@ export default { watch: { selectedStyle(style) { - this.mainStore.updateVehicle({style}) - this.mainStore.setVehicle(style).then(() => { + if(style != this.mainStore.order.vehicle.style) + { + this.mainStore.updateVehicle({style}); + } + + this.mainStore.setVehicle().then(() => { this.$router.navigate( this.navigationScenarios.SELECTED_STYLE, this.$route diff --git a/src/layouts/vehicle-year/vehicle-year.vue b/src/layouts/vehicle-year/vehicle-year.vue index 96fa0804..bf302812 100644 --- a/src/layouts/vehicle-year/vehicle-year.vue +++ b/src/layouts/vehicle-year/vehicle-year.vue @@ -69,7 +69,11 @@ watch: { selectedYear(year) { const parsedYear = parseInt(year); - this.mainStore.updateVehicleYear(parsedYear); + if(parsedYear != this.mainStore.order.vehicle.year) + { + this.mainStore.updateVehicle({year: parsedYear, make: null, model: null, style: null}); + } + this.$router.navigate( this.navigationScenarios.SELECTED_YEAR, this.$route From 53160a51196515f70d5a25c0c659849681725b46 Mon Sep 17 00:00:00 2001 From: Jason Wheeler Date: Fri, 11 Nov 2022 12:51:43 -0500 Subject: [PATCH 3/5] updated to clear the entire vehicle object. Additional store items can be added to resetVehicle method as they are added to the store. --- src/layouts/vehicle-make/vehicle-make.vue | 3 +- src/layouts/vehicle-model/vehicle-model.vue | 3 +- src/layouts/vehicle-style/vehicle-style.vue | 11 +++++++- src/layouts/vehicle-year/vehicle-year.vue | 2 +- src/store/index.js | 31 ++++++++++++++++++++- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/layouts/vehicle-make/vehicle-make.vue b/src/layouts/vehicle-make/vehicle-make.vue index 9b92378f..3261ae92 100644 --- a/src/layouts/vehicle-make/vehicle-make.vue +++ b/src/layouts/vehicle-make/vehicle-make.vue @@ -92,7 +92,8 @@ selectedMake(make) { if(make != this.mainStore.order.vehicle.make) { - this.mainStore.updateVehicle({make, model: null, style: null}); + const vehicle = this.mainStore.order.vehicle; + this.mainStore.updateVehicle( { year: vehicle.year, make }, true ); } this.$router.navigate( this.navigationScenarios.SELECTED_MAKE, diff --git a/src/layouts/vehicle-model/vehicle-model.vue b/src/layouts/vehicle-model/vehicle-model.vue index 240656d9..443585ec 100644 --- a/src/layouts/vehicle-model/vehicle-model.vue +++ b/src/layouts/vehicle-model/vehicle-model.vue @@ -85,7 +85,8 @@ selectedModel(model) { if(model != this.mainStore.order.vehicle.model) { - this.mainStore.updateVehicle({model, style: null}); + const vehicle = this.mainStore.order.vehicle; + this.mainStore.updateVehicle( { year: vehicle.year, make: vehicle.make, model }, true ); } this.$router.navigate( this.navigationScenarios.SELECTED_MODEL, diff --git a/src/layouts/vehicle-style/vehicle-style.vue b/src/layouts/vehicle-style/vehicle-style.vue index 8beac5cc..225fae09 100644 --- a/src/layouts/vehicle-style/vehicle-style.vue +++ b/src/layouts/vehicle-style/vehicle-style.vue @@ -79,7 +79,16 @@ export default { selectedStyle(style) { if(style != this.mainStore.order.vehicle.style) { - this.mainStore.updateVehicle({style}); + const vehicle = this.mainStore.order.vehicle; + this.mainStore.updateVehicle( + { + year: vehicle.year, + make: vehicle.make, + model: vehicle.model, + style + }, + true + ); } this.mainStore.setVehicle().then(() => { diff --git a/src/layouts/vehicle-year/vehicle-year.vue b/src/layouts/vehicle-year/vehicle-year.vue index bf302812..1f0e7f5e 100644 --- a/src/layouts/vehicle-year/vehicle-year.vue +++ b/src/layouts/vehicle-year/vehicle-year.vue @@ -71,7 +71,7 @@ const parsedYear = parseInt(year); if(parsedYear != this.mainStore.order.vehicle.year) { - this.mainStore.updateVehicle({year: parsedYear, make: null, model: null, style: null}); + this.mainStore.updateVehicle( { year: parsedYear }, true ); } this.$router.navigate( diff --git a/src/store/index.js b/src/store/index.js index 2c733ed7..3fb78d66 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -131,10 +131,39 @@ export const useMainStore = defineStore({ }); }, - updateVehicle(vehicle) + updateVehicle(vehicle, reset = false) { + if(reset) + { + this.resetVehicle(); + } this.order.vehicle = { ...this.order.vehicle, ...vehicle }; }, + + resetVehicle() + { + this.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, + }, + } + }, addEventToBus (event) { this.applicationUser.eventBus.push(event); From 21ec33f8dcb4d286b21e380f5b2953313c960b9f Mon Sep 17 00:00:00 2001 From: Jason Wheeler Date: Fri, 11 Nov 2022 15:33:32 -0500 Subject: [PATCH 4/5] requested updates --- src/layouts/vehicle-make/vehicle-make.vue | 6 +- src/layouts/vehicle-model/vehicle-model.vue | 6 +- src/layouts/vehicle-style/vehicle-style.vue | 15 +--- src/layouts/vehicle-year/vehicle-year.vue | 5 +- src/store/index.js | 90 ++++++++++++++------- src/store/store.spec.js | 21 +++-- 6 files changed, 81 insertions(+), 62 deletions(-) diff --git a/src/layouts/vehicle-make/vehicle-make.vue b/src/layouts/vehicle-make/vehicle-make.vue index 3261ae92..3338132e 100644 --- a/src/layouts/vehicle-make/vehicle-make.vue +++ b/src/layouts/vehicle-make/vehicle-make.vue @@ -90,11 +90,7 @@ }, watch: { selectedMake(make) { - if(make != this.mainStore.order.vehicle.make) - { - const vehicle = this.mainStore.order.vehicle; - this.mainStore.updateVehicle( { year: vehicle.year, make }, true ); - } + this.mainStore.updateVehicleMake( make ); this.$router.navigate( this.navigationScenarios.SELECTED_MAKE, this.$route diff --git a/src/layouts/vehicle-model/vehicle-model.vue b/src/layouts/vehicle-model/vehicle-model.vue index 443585ec..986d4bed 100644 --- a/src/layouts/vehicle-model/vehicle-model.vue +++ b/src/layouts/vehicle-model/vehicle-model.vue @@ -83,11 +83,7 @@ watch: { selectedModel(model) { - if(model != this.mainStore.order.vehicle.model) - { - const vehicle = this.mainStore.order.vehicle; - this.mainStore.updateVehicle( { year: vehicle.year, make: vehicle.make, model }, true ); - } + this.mainStore.updateVehicleModel( model ); this.$router.navigate( this.navigationScenarios.SELECTED_MODEL, this.$route diff --git a/src/layouts/vehicle-style/vehicle-style.vue b/src/layouts/vehicle-style/vehicle-style.vue index 6ced6799..1ce939af 100644 --- a/src/layouts/vehicle-style/vehicle-style.vue +++ b/src/layouts/vehicle-style/vehicle-style.vue @@ -76,20 +76,7 @@ export default { watch: { selectedStyle(style) { - if(style != this.mainStore.order.vehicle.style) - { - const vehicle = this.mainStore.order.vehicle; - this.mainStore.updateVehicle( - { - year: vehicle.year, - make: vehicle.make, - model: vehicle.model, - style - }, - true - ); - } - + this.mainStore.updateVehicleStyle( style ); this.mainStore.setVehicle().then(() => { this.$router.navigate( this.navigationScenarios.SELECTED_STYLE, diff --git a/src/layouts/vehicle-year/vehicle-year.vue b/src/layouts/vehicle-year/vehicle-year.vue index 1f0e7f5e..876c619d 100644 --- a/src/layouts/vehicle-year/vehicle-year.vue +++ b/src/layouts/vehicle-year/vehicle-year.vue @@ -69,10 +69,7 @@ watch: { selectedYear(year) { const parsedYear = parseInt(year); - if(parsedYear != this.mainStore.order.vehicle.year) - { - this.mainStore.updateVehicle( { year: parsedYear }, true ); - } + this.mainStore.updateVehicleYear( parsedYear ); this.$router.navigate( this.navigationScenarios.SELECTED_YEAR, diff --git a/src/store/index.js b/src/store/index.js index 108f4074..8653686c 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -198,42 +198,76 @@ export const useMainStore = defineStore({ payload: {}, }) .then((response) => { - this.updateVehicle(response.data); + updateVehicle(response.vehicle); return response; }); }, - updateVehicle(vehicle, reset = false) - { - if(reset) - { - this.resetVehicle(); - } + updateVehicle(vehicle) { this.order.vehicle = { ...this.order.vehicle, ...vehicle }; }, - resetVehicle() + resetVehicleState() { - this.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, - }, + this.order.vehicle.year = null; + this.order.vehicle.make = null; + this.order.vehicle.model = null; + this.order.vehicle.style = null; + this.order.vehicle.carId = null; + this.order.vehicle.category = null; + this.order.vehicle.vin = null; + this.order.vehicle.imageUrl = null; + this.order.vehicle.imageVifNumber = null; + this.order.vehicle.imageColor = null; + }, + + updateVehicleYear(year) { + if(this.order.vehicle.year != year) + { + this.resetVehicleState(); + this.order.vehicle.year = year; + } + }, + + updateVehicleMake(make) { + if(this.order.vehicle.make != make) + { + const year = this.order.vehicle.year; + + this.resetVehicleState(); + + this.order.vehicle.year = year; + this.order.vehicle.make = make; + } + }, + + updateVehicleModel(model) { + if(this.order.vehicle.model != model) + { + const year = this.order.vehicle.year; + const make = this.order.vehicle.make; + + this.resetVehicleState(); + + this.order.vehicle.year = year; + this.order.vehicle.make = make; + this.order.vehicle.model = model; + } + }, + + updateVehicleStyle(style) { + if(this.order.vehicle.style != style) + { + const year = this.order.vehicle.year; + const make = this.order.vehicle.make; + const model = this.order.vehicle.model; + + this.resetVehicleState(); + + this.order.vehicle.year = year; + this.order.vehicle.make = make; + this.order.vehicle.model = model; + this.order.vehicle.style = style; } }, diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 4c1160b3..5136aab2 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -19,6 +19,13 @@ 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", @@ -90,7 +97,7 @@ describe("Store", () => { imageColor: null, }; - const response = { + const response = {data: { "carId": "CR00069299", "category": "CAR", "year": 2020, @@ -100,19 +107,20 @@ describe("Store", () => { "imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg", "imageVifNumber": "13996", "imageVifColor": "white" + } }; - store.updateVehicle(response); + store.updateVehicle(response.data); - expect(store.order.vehicle.imageUrl).toEqual(response.imageUrl); - expect(store.order.vehicle.imageVifNumber).toEqual(response.imageVifNumber); - expect(store.order.vehicle.imageVifColor).toEqual(response.imageVifColor); + expect(store.order.vehicle.imageUrl).toEqual(response.data.imageUrl); + expect(store.order.vehicle.imageVifNumber).toEqual(response.data.imageVifNumber); + expect(store.order.vehicle.imageVifColor).toEqual(response.data.imageVifColor); }); it("setVehicle should call globalMethods.callHttpClient", () => { store.order.vehicle = jest.fn(); - const response = { + const response = {data: { "carId": "CR00069299", "category": "CAR", "year": 2020, @@ -122,6 +130,7 @@ describe("Store", () => { "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)); From 8ad16eeb87100f6e82cbdd8dbb945d9f7b19ae34 Mon Sep 17 00:00:00 2001 From: Kulbhushan Kaushik Date: Mon, 14 Nov 2022 08:42:48 -0500 Subject: [PATCH 5/5] 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 5136aab2..daeb4efc 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -1,4 +1,4 @@ -import { useMainStore } from "./" +import { useMainStore } from "./@store"; import { createApp } from 'vue'; import { createPinia } from "pinia"; import globalMethods from "@/global-methods";