From aa992395d0289f4570c575a89026fe7edfd1399c Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Tue, 23 Apr 2024 05:58:55 -0400 Subject: [PATCH 1/5] bailout when getPartsOrQuestions errors --- src/constants/bailoutCode.js | 3 ++- src/constants/bailoutMessage.js | 4 ++++ src/layouts/vin-lookup/vin-lookup.vue | 22 ++++++++++++++-------- src/mixins/vehicle-questions-mixin.js | 3 ++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/constants/bailoutCode.js b/src/constants/bailoutCode.js index 8f8b0680..6e562261 100644 --- a/src/constants/bailoutCode.js +++ b/src/constants/bailoutCode.js @@ -8,7 +8,8 @@ const bailoutCode = Object.freeze({ PricingResponseError: 6, TPANotEnabled: 7, RequestCallback: 8, - HeavyTruckVehicle: 9 + HeavyTruckVehicle: 9, + NoPartsAvailable: 10 }); export default bailoutCode; diff --git a/src/constants/bailoutMessage.js b/src/constants/bailoutMessage.js index 8d046927..d18d4a3a 100644 --- a/src/constants/bailoutMessage.js +++ b/src/constants/bailoutMessage.js @@ -52,6 +52,10 @@ const bailoutMessage = Object.freeze({ HeavyTruckVehicle: (carId) => ({ code: bailoutCode.HeavyTruckVehicle, message: `User selected a heavy truck vehicle. Car ID: ${carId} ` + }), + NoPartsAvailable: (error) => ({ + code: bailoutCode.NoPartsAvailable, + message: `An error occurred in getPartsOrQuestions. Error: ${getItemData(error)}` }) }); diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 6984341d..78c594f8 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -274,21 +274,27 @@ export default { return null; } + let hasBailedOut = false; const partsOrQuestionsResponse = await this.getPartsOrQuestions(); if (partsOrQuestionsResponse.error) { - // To Do: Need requirement on what to do here + this.mainStore.setBailout( + bailoutMessage.NoPartsAvailable(partsOrQuestionsResponse.error.data)); window.console.error('Error on retrieving PartsOrQuestions'); this.$refs.siteFooter.removeLoader(); - return null; + hasBailedOut = true; + this.$router.navigate( + this.navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT, + this.$route + ); } // Comes from vehicleQuestionsMixin.navigateForward() - await this.navigateForward( - partsOrQuestionsResponse.data.partsOrQuestions, - this - ); - - return null; + if (!hasBailedOut) { + await this.navigateForward( + partsOrQuestionsResponse.data.partsOrQuestions, + this + ); + } }, async lookupVehicleByVin(vin) { try { diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index 4cad0395..88f6b2b6 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -347,7 +347,8 @@ export default { } catch (responseError) { return { error: { - status: responseError.status + status: responseError.status, + data: responseError.data } }; } From 647c47c86a03ebfa710944875098acf1b0ac227d Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Tue, 23 Apr 2024 09:43:46 -0400 Subject: [PATCH 2/5] unit test WIP --- src/layouts/vin-lookup/vin-lookup.spec.js | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/layouts/vin-lookup/vin-lookup.spec.js b/src/layouts/vin-lookup/vin-lookup.spec.js index 1d94f19e..cf76f334 100644 --- a/src/layouts/vin-lookup/vin-lookup.spec.js +++ b/src/layouts/vin-lookup/vin-lookup.spec.js @@ -121,6 +121,17 @@ const vehicleWithNoAdditionalPartsOrQuestionsMockResponse = { } }; +const partsOrQuestionsErrorMockResponse = { + data: { + partsOrQuestions: [ + { + parts: null + } + ], + partQuestions: null + } +}; + jest.mock('bootstrap', () => ({ getInstance: jest.fn(), getOrCreateInstance: jest.fn() @@ -517,6 +528,37 @@ describe('vin-lookup.vue', () => { ); }); }); + test( + 'Error in getPartsOrQuestions call => bailout true and navigate forward with CLICKED_FORWARD_WITH_BAILOUT scenario', + async () => { + const user = userEvent.setup(); + mountOptions.global.stubs.vinQuestion = false; + getPartsOrQuestions.mockResponse = partsOrQuestionsErrorMockResponse; + + jest.spyOn(VinLookupComponent.methods, lookupVehicleByVin.methodName) + .mockResolvedValue(lookupVehicleByVin.mockResponse); + jest.spyOn(vehicleQuestionsMixin.methods, getPartsOrQuestions.methodName) + .mockResolvedValue(getPartsOrQuestions.mockResponse); + + const { container } = render(VinLookupComponent, mountOptions); + + const vinInput = container.querySelector(vinInputSelector); + await user.type(vinInput, mockValidVin); + + const continueButton = container.querySelector(continueButtonQuerySelector); + await user.click(continueButton); + + await flushPromises(); + await waitFor(() => { + expect(mockRouter.navigate).toHaveBeenCalledTimes(1); + expect(mockRouter.navigate) + .toHaveBeenCalledWith( + navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT, + mockRoute + ); + }); + } + ); }); }); }); From ee08bed3eaac9d02b9969046af80783962a0d272 Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Tue, 23 Apr 2024 14:43:27 -0400 Subject: [PATCH 3/5] completed unit test --- src/layouts/vin-lookup/vin-lookup.spec.js | 17 +++++++++-------- src/layouts/vin-lookup/vin-lookup.vue | 11 ++++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/layouts/vin-lookup/vin-lookup.spec.js b/src/layouts/vin-lookup/vin-lookup.spec.js index cf76f334..cd8470be 100644 --- a/src/layouts/vin-lookup/vin-lookup.spec.js +++ b/src/layouts/vin-lookup/vin-lookup.spec.js @@ -122,14 +122,7 @@ const vehicleWithNoAdditionalPartsOrQuestionsMockResponse = { }; const partsOrQuestionsErrorMockResponse = { - data: { - partsOrQuestions: [ - { - parts: null - } - ], - partQuestions: null - } + error: 'Error getting parts' }; jest.mock('bootstrap', () => ({ @@ -533,6 +526,14 @@ describe('vin-lookup.vue', () => { async () => { const user = userEvent.setup(); mountOptions.global.stubs.vinQuestion = false; + + mountOptions.data = () => ({ + vinWithNonMatchingCarId: false, + isCarIdDifferentFromTheStore: false, + vin: mockValidVin, + hasBailedOut: true + }); + getPartsOrQuestions.mockResponse = partsOrQuestionsErrorMockResponse; jest.spyOn(VinLookupComponent.methods, lookupVehicleByVin.methodName) diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 78c594f8..9bbf2c59 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -151,6 +151,9 @@ export default { carIdIsValid() { return this.hasValidCarId(); }, + hasBailedOut() { + return false; + } }, watch: { vin() { @@ -274,14 +277,12 @@ export default { return null; } - let hasBailedOut = false; const partsOrQuestionsResponse = await this.getPartsOrQuestions(); if (partsOrQuestionsResponse.error) { - this.mainStore.setBailout( - bailoutMessage.NoPartsAvailable(partsOrQuestionsResponse.error.data)); + this.mainStore.setBailout(bailoutMessage.NoPartsAvailable(partsOrQuestionsResponse.error.data)); window.console.error('Error on retrieving PartsOrQuestions'); this.$refs.siteFooter.removeLoader(); - hasBailedOut = true; + this.hasBailedOut = true; this.$router.navigate( this.navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT, this.$route @@ -289,7 +290,7 @@ export default { } // Comes from vehicleQuestionsMixin.navigateForward() - if (!hasBailedOut) { + if (!this.hasBailedOut) { await this.navigateForward( partsOrQuestionsResponse.data.partsOrQuestions, this From acc72416583578521dd33c42955dc1e829b3ba00 Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Wed, 24 Apr 2024 09:02:49 -0400 Subject: [PATCH 4/5] add bailout to vehicle-damage + unit test --- .../vehicle-damage/vehicle-damage.spec.js | 37 +++++++++++++++++++ src/layouts/vehicle-damage/vehicle-damage.vue | 29 +++++++++------ src/layouts/vin-lookup/vin-lookup.vue | 1 - 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/layouts/vehicle-damage/vehicle-damage.spec.js b/src/layouts/vehicle-damage/vehicle-damage.spec.js index f2f911f7..8d772176 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.spec.js +++ b/src/layouts/vehicle-damage/vehicle-damage.spec.js @@ -6,6 +6,8 @@ import routerParams from '@/router/router-constants/router-params'; import { useMainStore } from '@/store'; import vehicleCategories from '@/constants/vehicle-categories'; import VehicleDamageComponent from '@/layouts/vehicle-damage/vehicle-damage.vue'; +import bailoutCode from '@/constants/bailoutCode'; +import issPageValues from '@/router/router-constants/issPage-values'; const mockRoute = { params: {} @@ -51,6 +53,7 @@ const mountOptions = { } } }; + beforeEach(() => { jest.clearAllMocks(); }); @@ -92,4 +95,38 @@ describe('vehicle-damage.vue', () => { expect(mockRouter.navigate) .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_REPAIR, mockRoute); }); + test('Error in getPartsOrQuestions call => bailout true and navigate forward with CLICKED_FORWARD_WITH_BAILOUT scenario', async () => { + mountOptions.global.plugins = [createTestingPinia({ + initialState: { + main: { + order: { + damage: { + isRepair: false + }, + vehicle: { + vin: 'MOCK VIN' + } + } + } + } + })]; + mountOptions.data = () => ({ + hasBailedOut: true + }); + + const wrapper = mount(VehicleDamageComponent, mountOptions); + const siteFooterWrapper = wrapper.getComponent({ ref: 'siteFooter' }); + const partsQuestionsErrorResponse = { + error: 'Error getting parts' + }; + useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => ( + partsQuestionsErrorResponse + )); + siteFooterWrapper.vm.$emit('forwardClicked'); + + await flushPromises(); + expect(mockRouter.navigate).toHaveBeenCalledTimes(1); + expect(mockRouter.navigate) + .toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT, mockRoute); + }); }); diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index e2e541ae..f42d4d76 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -121,6 +121,7 @@ import errorMessages from '@/constants/error-messages'; import damageLocationsCms from '@/constants/damage-locations-cms.js'; import damageLocationsSelected from '@/constants/damage-locations-selected.js'; import { useMainStore } from '@/store'; +import bailoutMessage from '@/constants/bailoutMessage'; // DEFINE VALIDATION RULES defineRule( @@ -295,6 +296,9 @@ export default { this.routerParams.DISPLAY_VEHICLE_CHANGE_ALERT ]; }, + hasBailedOut() { + return false; + } }, methods: { arePagePrerequisitesValid() { @@ -479,22 +483,25 @@ export default { } else if (this.mainStore.order.vehicle.vin) { // If vin already exists, navigate directly to vin-lookup - const partsOrQuestionsResponse = - await this.getPartsOrQuestions(); + const partsOrQuestionsResponse = await this.getPartsOrQuestions(); if (partsOrQuestionsResponse.error) { - // To Do: Need requirement on what to do here - window.console.error( - 'Error on retrieving PartsOrQuestions' - ); + this.mainStore.setBailout(bailoutMessage.NoPartsAvailable(partsOrQuestionsResponse.error.data)); + window.console.error('Error on retrieving PartsOrQuestions'); this.$refs.siteFooter.removeLoader(); - return null; + this.hasBailedOut = true; + this.$router.navigate( + this.navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT, + this.$route + ); } // Comes from vehicleQuestionsMixin.navigateForward() - await this.navigateForward( - partsOrQuestionsResponse.data.partsOrQuestions, - this - ); + if (!this.hasBailedOut) { + await this.navigateForward( + partsOrQuestionsResponse.data.partsOrQuestions, + this + ); + } } else { this.$router.navigate( this.navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN, diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 9bbf2c59..0b135e08 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -61,7 +61,6 @@ import vehicleBanner from '@/iss-components/vehicle-banner/vehicle-banner.vue'; import vinLocationInformation from '@/layouts/vin-lookup/vin-location-information/vin-location-information.vue'; import vinLookupAlerts from '@/layouts/vin-lookup/vin-lookup-alerts/vin-lookup-alerts.vue'; import vinQuestion from '@/layouts/vin-lookup/vin-question/vin-question.vue'; -import bailoutCode from '@/constants/bailoutCode'; import bailoutMessage from '@/constants/bailoutMessage'; export default { From 071bccb436f95ce03274a7004b320e356fbee765 Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Wed, 24 Apr 2024 11:37:29 -0400 Subject: [PATCH 5/5] refactoring WIP --- src/layouts/vehicle-damage/vehicle-damage.spec.js | 2 -- src/layouts/vehicle-damage/vehicle-damage.vue | 4 +--- src/layouts/vin-lookup/vin-lookup.vue | 4 +--- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/layouts/vehicle-damage/vehicle-damage.spec.js b/src/layouts/vehicle-damage/vehicle-damage.spec.js index 8d772176..2f964407 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.spec.js +++ b/src/layouts/vehicle-damage/vehicle-damage.spec.js @@ -6,8 +6,6 @@ import routerParams from '@/router/router-constants/router-params'; import { useMainStore } from '@/store'; import vehicleCategories from '@/constants/vehicle-categories'; import VehicleDamageComponent from '@/layouts/vehicle-damage/vehicle-damage.vue'; -import bailoutCode from '@/constants/bailoutCode'; -import issPageValues from '@/router/router-constants/issPage-values'; const mockRoute = { params: {} diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index f42d4d76..75094683 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -208,6 +208,7 @@ export default { }, selectedWindshieldOptions: this.getWindshieldOptionsFromStore(), selectedRearReplaceOptions: this.getRearReplaceOptionsFromStore(), + hasBailedOut: false }; }, computed: { @@ -295,9 +296,6 @@ export default { return this.$route.params[ this.routerParams.DISPLAY_VEHICLE_CHANGE_ALERT ]; - }, - hasBailedOut() { - return false; } }, methods: { diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 0b135e08..cfc74792 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -117,6 +117,7 @@ export default { vin, forwardButtonCarStyle: '', vinPopulatedOnPageLoad: vin?.length > 0 && this.hasValidCarId(), + hasBailedOut: false }; }, computed: { @@ -149,9 +150,6 @@ export default { }, carIdIsValid() { return this.hasValidCarId(); - }, - hasBailedOut() { - return false; } }, watch: {