diff --git a/src/layouts/vin-lookup/vin-lookup.spec.js b/src/layouts/vin-lookup/vin-lookup.spec.js index cd8470be..2ac22591 100644 --- a/src/layouts/vin-lookup/vin-lookup.spec.js +++ b/src/layouts/vin-lookup/vin-lookup.spec.js @@ -24,7 +24,17 @@ const lookupVehicleByVin = { methodName: 'lookupVehicleByVin', mockResponse: { data: { - carId: mockCarId + carId: mockCarId, + canSafeliteService: true + } + } +}; +const lookupVehicleByVinCannotService = { + methodName: 'lookupVehicleByVin', + mockResponse: { + data: { + carId: mockCarId, + canSafeliteService: false } } }; @@ -484,6 +494,41 @@ describe('vin-lookup.vue', () => { ); }); }); + test('Bailout if entered vin cannot be serviced', async () => { + const user = userEvent.setup(); + mountOptions.global.stubs.vinQuestion = false; + + mountOptions.data = () => ({ + vinWithNonMatchingCarId: false, + isCarIdDifferentFromTheStore: false, + vin: mockValidVin + }); + + getPartsOrQuestions.mockResponse = vehicleWithNoAdditionalPartsOrQuestionsMockResponse; + + jest.spyOn(VinLookupComponent.methods, lookupVehicleByVin.methodName) + .mockResolvedValue(lookupVehicleByVinCannotService.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 + ); + }); + }); // eslint-disable-next-line max-len test('Policy Vehicle with invalid vin corrected. Click "Continue", execute navigate with navigationScenario.CORRECTED_VIN_FROM_POLICY_VEHICLE', async () => { diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index cf6a7558..f469953d 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -185,8 +185,7 @@ export default { const vehicleLookupResponse = await this.lookupVehicleByVin(this.vin); if (vehicleLookupResponse.error) { - this.activeVehicleLookupAlertType = - vehicleLookupAlertTypes.NOT_FOUND; + this.activeVehicleLookupAlertType = vehicleLookupAlertTypes.NOT_FOUND; this.mainStore.setBailout(bailoutMessage.vehicleNotFound(this.vin)); this.resetVehicleFromLookup(); this.$refs.siteFooter.removeLoader(); @@ -197,6 +196,12 @@ export default { return; } + if (!vehicleLookupResponse.data.canSafeliteService) { + this.mainStore.setBailout(bailoutMessage.HeavyTruckVehicle(vehicleLookupResponse.data.carId)); + this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT, this.$route); + return; + } + this.mainStore.resetBailout(); // Add vin bcs the response from the service doesn't contain vin