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/vehicle-damage/vehicle-damage.spec.js b/src/layouts/vehicle-damage/vehicle-damage.spec.js index f2f911f7..2f964407 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.spec.js +++ b/src/layouts/vehicle-damage/vehicle-damage.spec.js @@ -51,6 +51,7 @@ const mountOptions = { } } }; + beforeEach(() => { jest.clearAllMocks(); }); @@ -92,4 +93,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..75094683 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( @@ -207,6 +208,7 @@ export default { }, selectedWindshieldOptions: this.getWindshieldOptionsFromStore(), selectedRearReplaceOptions: this.getRearReplaceOptionsFromStore(), + hasBailedOut: false }; }, computed: { @@ -294,7 +296,7 @@ export default { return this.$route.params[ this.routerParams.DISPLAY_VEHICLE_CHANGE_ALERT ]; - }, + } }, methods: { arePagePrerequisitesValid() { @@ -479,22 +481,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.spec.js b/src/layouts/vin-lookup/vin-lookup.spec.js index 1d94f19e..cd8470be 100644 --- a/src/layouts/vin-lookup/vin-lookup.spec.js +++ b/src/layouts/vin-lookup/vin-lookup.spec.js @@ -121,6 +121,10 @@ const vehicleWithNoAdditionalPartsOrQuestionsMockResponse = { } }; +const partsOrQuestionsErrorMockResponse = { + error: 'Error getting parts' +}; + jest.mock('bootstrap', () => ({ getInstance: jest.fn(), getOrCreateInstance: jest.fn() @@ -517,6 +521,45 @@ 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; + + mountOptions.data = () => ({ + vinWithNonMatchingCarId: false, + isCarIdDifferentFromTheStore: false, + vin: mockValidVin, + hasBailedOut: true + }); + + 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 + ); + }); + } + ); }); }); }); diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 6984341d..cfc74792 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 { @@ -118,6 +117,7 @@ export default { vin, forwardButtonCarStyle: '', vinPopulatedOnPageLoad: vin?.length > 0 && this.hasValidCarId(), + hasBailedOut: false }; }, computed: { @@ -150,7 +150,7 @@ export default { }, carIdIsValid() { return this.hasValidCarId(); - }, + } }, watch: { vin() { @@ -276,19 +276,23 @@ export default { 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; + 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 - ); - - return null; + if (!this.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 } }; }