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,
TPANotEnabled: 7,
RequestCallback: 8,
HeavyTruckVehicle: 9
HeavyTruckVehicle: 9,
NoPartsAvailable: 10
});
export default bailoutCode;

View file

@ -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)}`
})
});

View file

@ -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);
});
});

View file

@ -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,

View file

@ -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
);
});
}
);
});
});
});

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 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 {

View file

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