Merge pull request #637 from Safelite/feature/SSR-683

SSR-683 - solution for inventory shortages
This commit is contained in:
michaela-brydon-safelite 2024-04-24 14:54:06 -04:00 committed by GitHub
commit d1d341d0cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 117 additions and 24 deletions

View file

@ -8,7 +8,8 @@ const bailoutCode = Object.freeze({
PricingResponseError: 6, PricingResponseError: 6,
TPANotEnabled: 7, TPANotEnabled: 7,
RequestCallback: 8, RequestCallback: 8,
HeavyTruckVehicle: 9 HeavyTruckVehicle: 9,
NoPartsAvailable: 10
}); });
export default bailoutCode; export default bailoutCode;

View file

@ -52,6 +52,10 @@ const bailoutMessage = Object.freeze({
HeavyTruckVehicle: (carId) => ({ HeavyTruckVehicle: (carId) => ({
code: bailoutCode.HeavyTruckVehicle, code: bailoutCode.HeavyTruckVehicle,
message: `User selected a heavy truck vehicle. Car ID: ${carId} ` message: `User selected a heavy truck vehicle. Car ID: ${carId} `
}),
NoPartsAvailable: (error) => ({
code: bailoutCode.NoPartsAvailable,
message: `An error occurred in getPartsOrQuestions. Error: ${getItemData(error)}`
}) })
}); });

View file

@ -51,6 +51,7 @@ const mountOptions = {
} }
} }
}; };
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks(); jest.clearAllMocks();
}); });
@ -92,4 +93,38 @@ describe('vehicle-damage.vue', () => {
expect(mockRouter.navigate) expect(mockRouter.navigate)
.toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_REPAIR, mockRoute); .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);
});
}); });

View file

@ -121,6 +121,7 @@ import errorMessages from '@/constants/error-messages';
import damageLocationsCms from '@/constants/damage-locations-cms.js'; import damageLocationsCms from '@/constants/damage-locations-cms.js';
import damageLocationsSelected from '@/constants/damage-locations-selected.js'; import damageLocationsSelected from '@/constants/damage-locations-selected.js';
import { useMainStore } from '@/store'; import { useMainStore } from '@/store';
import bailoutMessage from '@/constants/bailoutMessage';
// DEFINE VALIDATION RULES // DEFINE VALIDATION RULES
defineRule( defineRule(
@ -207,6 +208,7 @@ export default {
}, },
selectedWindshieldOptions: this.getWindshieldOptionsFromStore(), selectedWindshieldOptions: this.getWindshieldOptionsFromStore(),
selectedRearReplaceOptions: this.getRearReplaceOptionsFromStore(), selectedRearReplaceOptions: this.getRearReplaceOptionsFromStore(),
hasBailedOut: false
}; };
}, },
computed: { computed: {
@ -294,7 +296,7 @@ export default {
return this.$route.params[ return this.$route.params[
this.routerParams.DISPLAY_VEHICLE_CHANGE_ALERT this.routerParams.DISPLAY_VEHICLE_CHANGE_ALERT
]; ];
}, }
}, },
methods: { methods: {
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
@ -479,22 +481,25 @@ export default {
} else if (this.mainStore.order.vehicle.vin) { } else if (this.mainStore.order.vehicle.vin) {
// If vin already exists, navigate directly to vin-lookup // If vin already exists, navigate directly to vin-lookup
const partsOrQuestionsResponse = const partsOrQuestionsResponse = await this.getPartsOrQuestions();
await this.getPartsOrQuestions();
if (partsOrQuestionsResponse.error) { if (partsOrQuestionsResponse.error) {
// To Do: Need requirement on what to do here this.mainStore.setBailout(bailoutMessage.NoPartsAvailable(partsOrQuestionsResponse.error.data));
window.console.error( window.console.error('Error on retrieving PartsOrQuestions');
'Error on retrieving PartsOrQuestions'
);
this.$refs.siteFooter.removeLoader(); this.$refs.siteFooter.removeLoader();
return null; this.hasBailedOut = true;
this.$router.navigate(
this.navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT,
this.$route
);
} }
// Comes from vehicleQuestionsMixin.navigateForward() // Comes from vehicleQuestionsMixin.navigateForward()
await this.navigateForward( if (!this.hasBailedOut) {
partsOrQuestionsResponse.data.partsOrQuestions, await this.navigateForward(
this partsOrQuestionsResponse.data.partsOrQuestions,
); this
);
}
} else { } else {
this.$router.navigate( this.$router.navigate(
this.navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN, this.navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN,

View file

@ -121,6 +121,10 @@ const vehicleWithNoAdditionalPartsOrQuestionsMockResponse = {
} }
}; };
const partsOrQuestionsErrorMockResponse = {
error: 'Error getting parts'
};
jest.mock('bootstrap', () => ({ jest.mock('bootstrap', () => ({
getInstance: jest.fn(), getInstance: jest.fn(),
getOrCreateInstance: 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
);
});
}
);
}); });
}); });
}); });

View file

@ -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 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 vinLookupAlerts from '@/layouts/vin-lookup/vin-lookup-alerts/vin-lookup-alerts.vue';
import vinQuestion from '@/layouts/vin-lookup/vin-question/vin-question.vue'; import vinQuestion from '@/layouts/vin-lookup/vin-question/vin-question.vue';
import bailoutCode from '@/constants/bailoutCode';
import bailoutMessage from '@/constants/bailoutMessage'; import bailoutMessage from '@/constants/bailoutMessage';
export default { export default {
@ -118,6 +117,7 @@ export default {
vin, vin,
forwardButtonCarStyle: '', forwardButtonCarStyle: '',
vinPopulatedOnPageLoad: vin?.length > 0 && this.hasValidCarId(), vinPopulatedOnPageLoad: vin?.length > 0 && this.hasValidCarId(),
hasBailedOut: false
}; };
}, },
computed: { computed: {
@ -150,7 +150,7 @@ export default {
}, },
carIdIsValid() { carIdIsValid() {
return this.hasValidCarId(); return this.hasValidCarId();
}, }
}, },
watch: { watch: {
vin() { vin() {
@ -276,19 +276,23 @@ export default {
const partsOrQuestionsResponse = await this.getPartsOrQuestions(); const partsOrQuestionsResponse = await this.getPartsOrQuestions();
if (partsOrQuestionsResponse.error) { 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'); window.console.error('Error on retrieving PartsOrQuestions');
this.$refs.siteFooter.removeLoader(); this.$refs.siteFooter.removeLoader();
return null; this.hasBailedOut = true;
this.$router.navigate(
this.navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT,
this.$route
);
} }
// Comes from vehicleQuestionsMixin.navigateForward() // Comes from vehicleQuestionsMixin.navigateForward()
await this.navigateForward( if (!this.hasBailedOut) {
partsOrQuestionsResponse.data.partsOrQuestions, await this.navigateForward(
this partsOrQuestionsResponse.data.partsOrQuestions,
); this
);
return null; }
}, },
async lookupVehicleByVin(vin) { async lookupVehicleByVin(vin) {
try { try {

View file

@ -347,7 +347,8 @@ export default {
} catch (responseError) { } catch (responseError) {
return { return {
error: { error: {
status: responseError.status status: responseError.status,
data: responseError.data
} }
}; };
} }