From 964b06744f9b60d2ea77d3c1ca9eb00e9ae31ab3 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Thu, 21 Sep 2023 14:08:32 -0400 Subject: [PATCH] Service Location --- .../service-location-helper.js | 18 ++++---- .../service-location-helper.spec.js | 41 +++++++++++++++++++ .../mobile-location-modal-questions.vue | 14 +++++-- .../service-location/service-location.vue | 10 +++-- .../service-zip-modal-question.vue | 16 ++++++-- .../shop-question/shop-question.vue | 10 +++-- src/mixins/base-mixin.js | 7 +++- src/store/index.js | 19 +++++++-- 8 files changed, 110 insertions(+), 25 deletions(-) diff --git a/src/layouts/service-location/helpers/service-location-helper/service-location-helper.js b/src/layouts/service-location/helpers/service-location-helper/service-location-helper.js index 19758bd07..2298aa386 100644 --- a/src/layouts/service-location/helpers/service-location-helper/service-location-helper.js +++ b/src/layouts/service-location/helpers/service-location-helper/service-location-helper.js @@ -2,42 +2,45 @@ import { storeActions } from "@/constants/store-actions"; import store from "@/store"; import baseMixin from "@/mixins/base-mixin.js"; -export async function getPricedMobileFeePart(serviceZipCode) { +export async function getPricedMobileFeePart(serviceZipCode, pageNameToLog) { if (!serviceZipCode) { return Promise.resolve(null); } - const zipCodeData = await baseMixin.methods.getZipCodeData(serviceZipCode); + const zipCodeData = await baseMixin.methods.getZipCodeData(serviceZipCode, pageNameToLog); // Get the Mobile Fee Part - const mobileFeePart = await baseMixin.methods.dispatchStoreAction( + const mobileFeePart = await baseMixin.methods.dispatchStoreActionWithLogging( storeActions.GET_MOBILE_FEE_PART, null, + pageNameToLog, false ); // Get the Mobile Fee Part Price - const pricingResults = await baseMixin.methods.dispatchStoreAction( + const pricingResults = await baseMixin.methods.dispatchStoreActionWithLogging( storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA, { availableLineItems: [mobileFeePart.data], serviceZipCode: serviceZipCode, serviceZipCodeCtu: zipCodeData.zipCodeCtu, }, + pageNameToLog, false ); return Promise.resolve(pricingResults[0]); } -export async function getServiceabilityDetails(serviceZipCode, lineItems) { +export async function getServiceabilityDetails(serviceZipCode, lineItems, pageNameToLog) { // Get the Mobile Fee Part - const serviceabilityDetails = await baseMixin.methods.dispatchStoreAction( + const serviceabilityDetails = await baseMixin.methods.dispatchStoreActionWithLogging( storeActions.GET_SERVICEABILITY_DETAILS, { serviceZipCode: serviceZipCode, lineItems: lineItems, }, + pageNameToLog, false ); @@ -51,7 +54,7 @@ export async function getAvailabilityRating( providerNumber ) { // For a given shop provider number and date range, get the appointment time slots available - const shopTimeSlots = await baseMixin.methods.dispatchStoreAction( + const shopTimeSlots = await baseMixin.methods.dispatchStoreActionWithLogging( storeActions.GET_SHOP_TIME_SLOTS, { providerNumber: providerNumber, @@ -59,6 +62,7 @@ export async function getAvailabilityRating( endDate: endDate, shopAppointmentType: shopAppointmentType, }, + "service-location", false ); diff --git a/src/layouts/service-location/helpers/service-location-helper/service-location-helper.spec.js b/src/layouts/service-location/helpers/service-location-helper/service-location-helper.spec.js index 6b530fddb..5bb41c657 100644 --- a/src/layouts/service-location/helpers/service-location-helper/service-location-helper.spec.js +++ b/src/layouts/service-location/helpers/service-location-helper/service-location-helper.spec.js @@ -188,6 +188,47 @@ jest.mock("@/mixins/base-mixin.js", () => ({ }); } + if (actionName === mockStoreActionGetShopTimeSlots) { + if (request.providerNumber == "0000001") { + return Promise.resolve(mockGetShopTimeSlotsGoodAvailability); + } + + return Promise.resolve(mockGetShopTimeSlotsLowAvailability); + } + }), + dispatchStoreActionWithLogging: jest.fn().mockImplementation((actionName, request) => { + if (actionName === mockStoreActionGetMobileFeePart) { + return Promise.resolve({ + data: { + partNumber: "MOBILE FEE", + description: "MOBILE FEE", + partType: "FEE", + }, + }); + } + + if (actionName === mockStoreActionPriceOrderItemsAndSaveServerData) { + return Promise.resolve([ + { + partNumber: "MOBILE FEE", + description: "MOBILE FEE", + partType: "FEE", + laborAmount: 49.99, + sellingPrice: 0, + kitPrice: 0, + }, + ]); + } + + if (actionName === mockStoreActionGetServiceabilityDetails) { + return Promise.resolve({ + isGlassServiceableInshop: true, + isRecalibrationServiceableInshop: true, + isGlassServiceableMobile: true, + isRecalibrationServiceableMobile: true, + }); + } + if (actionName === mockStoreActionGetShopTimeSlots) { if (request.providerNumber == "0000001") { return Promise.resolve(mockGetShopTimeSlotsGoodAvailability); diff --git a/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.vue b/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.vue index 0fef11cb1..2c63bdf43 100644 --- a/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.vue +++ b/src/layouts/service-location/mobile-location-modal-questions/mobile-location-modal-questions.vue @@ -229,7 +229,8 @@ export default { ) { // Validate the Zip Code const zipCodeData = await this.getZipCodeData( - this.internalModel.addressQuestions.zipCode + this.internalModel.addressQuestions.zipCode, + "service-location" ); if (!zipCodeData.isValid) { @@ -238,10 +239,17 @@ export default { } else { // retrieve mobile fee part const serviceZipCode = this.internalModel.addressQuestions.zipCode; - const mobileFeePart = await getPricedMobileFeePart(serviceZipCode); + const mobileFeePart = await getPricedMobileFeePart( + serviceZipCode, + "service-location" + ); // retrieve serviceability details - const serviceabilityDetails = await getServiceabilityDetails(serviceZipCode); + const serviceabilityDetails = await getServiceabilityDetails( + serviceZipCode, + null, + "service-location" + ); // update content related to service zip code this.$emit("updated-mobile-fee-part", mobileFeePart); diff --git a/src/layouts/service-location/service-location.vue b/src/layouts/service-location/service-location.vue index f93a1d5c8..ea81491ab 100644 --- a/src/layouts/service-location/service-location.vue +++ b/src/layouts/service-location/service-location.vue @@ -177,11 +177,15 @@ export default { const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); const serviceZipCode = store.getters.order.serviceLocation.zipCode; - const getZipCodeData = baseMixin.methods.getZipCodeData(serviceZipCode); + const getZipCodeData = baseMixin.methods.getZipCodeData(serviceZipCode, "service-location"); - const serviceabilityDetailsPromise = getServiceabilityDetails(serviceZipCode); + const serviceabilityDetailsPromise = getServiceabilityDetails( + serviceZipCode, + null, + "service-location" + ); - const mobileFeePartPromise = getPricedMobileFeePart(serviceZipCode); + const mobileFeePartPromise = getPricedMobileFeePart(serviceZipCode, "service-location"); const shopQuestionInitialDataPromise = shopQuestion.methods.loadInitialData(serviceZipCode); diff --git a/src/layouts/service-location/service-zip-modal-question/service-zip-modal-question.vue b/src/layouts/service-location/service-zip-modal-question/service-zip-modal-question.vue index d24bb618a..34a3d23c1 100644 --- a/src/layouts/service-location/service-zip-modal-question/service-zip-modal-question.vue +++ b/src/layouts/service-location/service-zip-modal-question/service-zip-modal-question.vue @@ -133,7 +133,10 @@ export default { if (this.internalModel.zipCode !== this.modelValue.zipCode) { this.resetAlerts(); - const zipCodeData = await this.getZipCodeData(this.internalModel.zipCode); + const zipCodeData = await this.getZipCodeData( + this.internalModel.zipCode, + "service-location" + ); if (!zipCodeData.isValid) { this.displayInvalidZipAlert = true; @@ -144,10 +147,17 @@ export default { // retrieve mobile fee part const serviceZipCode = this.internalModel.zipCode; - const mobileFeePart = await getPricedMobileFeePart(serviceZipCode); + const mobileFeePart = await getPricedMobileFeePart( + serviceZipCode, + "service-location" + ); // retrieve serviceability details - const serviceabilityDetails = await getServiceabilityDetails(serviceZipCode); + const serviceabilityDetails = await getServiceabilityDetails( + serviceZipCode, + null, + "service-location" + ); // update content related to service zip code this.$emit("updated-mobile-fee-part", mobileFeePart); diff --git a/src/layouts/service-location/shop-question/shop-question.vue b/src/layouts/service-location/shop-question/shop-question.vue index f588f6422..17153f9c9 100644 --- a/src/layouts/service-location/shop-question/shop-question.vue +++ b/src/layouts/service-location/shop-question/shop-question.vue @@ -126,9 +126,13 @@ export default { return this.loadData(serviceZipCode); }, loadData(serviceZipCode) { - return baseMixin.methods.dispatchStoreAction(storeActions.GET_PROVIDERS, { - serviceZipCode: serviceZipCode, - }); + return baseMixin.methods.dispatchStoreActionWithLogging( + storeActions.GET_PROVIDERS, + { + serviceZipCode: serviceZipCode, + }, + "service-location" + ); }, initializeComponent(shopQuestionInitialData) { this.shopProviders = shopQuestionInitialData.shopProviders; diff --git a/src/mixins/base-mixin.js b/src/mixins/base-mixin.js index 2632b42fb..4c7c07de1 100644 --- a/src/mixins/base-mixin.js +++ b/src/mixins/base-mixin.js @@ -63,8 +63,11 @@ export default { const footerInfoBox = document.querySelector(".footer#infoBox"); return footerInfoBox ? footerInfoBox.offsetHeight : 0; }, - async getZipCodeData(zipCode) { - const pageName = this.$options?.name; + async getZipCodeData(zipCode, pageNameToLog = null) { + const pageName = pageNameToLog ?? this.$options?.name; + if (pageName == null) { + console.log("Missed a spot."); + } const serviceZipValidationResponse = await this.dispatchStoreActionWithLogging( storeActions.VALIDATE_ZIP, diff --git a/src/store/index.js b/src/store/index.js index e468fc224..acdbea86d 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1235,7 +1235,7 @@ export const actions = { }); }, - getMobileFeePart(context) { + getMobileFeePart(context, { pageNameToLog }) { const damageType = context.getters.damage.isRepair ? "Repair" : "Replace"; const parentAccountNumber = context.getters.payment.parentAccountNumber; const billToAccountNumber = 87291; // TODO: MAKE THIS REAL @@ -1243,10 +1243,12 @@ export const actions = { return globalMethods.callHttpClient({ method: endpoints.GetMobileFeePart.method, endpoint: `${endpoints.GetMobileFeePart.url}/${damageType}/${parentAccountNumber}/${billToAccountNumber}`, + logApiCall: true, + pageNameToLog: pageNameToLog, }); }, - getServiceabilityDetails(context, { serviceZipCode }) { + getServiceabilityDetails(context, { payload: { serviceZipCode }, pageNameToLog }) { const lineItemsWithOnlyPartNumbers = context.getters.order.lineItems.supportingItems.map( (lineItem) => ({ partNumber: lineItem.partNumber, @@ -1270,16 +1272,20 @@ export const actions = { return globalMethods.callHttpClient({ method: endpoints.GetServiceabilityDetails.method, endpoint: `${endpoints.GetServiceabilityDetails.url}?zip=${serviceZipCode}&carId=${carId}&${lineItems}&${glassPieces}`, + logApiCall: true, + pageNameToLog: pageNameToLog, }); }, - getProviders(context, { serviceZipCode }) { + getProviders(context, { payload: { serviceZipCode }, pageNameToLog }) { const damageType = context.getters.damage.isRepair ? "Repair" : "Replace"; const shopRadiusInMiles = 100; return globalMethods.callHttpClient({ method: endpoints.GetProviders.method, endpoint: `${endpoints.GetProviders.url}/${serviceZipCode}/${damageType}/${shopRadiusInMiles}`, + logApiCall: true, + pageNameToLog: pageNameToLog, }); }, @@ -1336,7 +1342,10 @@ export const actions = { }); }, - getShopTimeSlots(context, { startDate, endDate, shopAppointmentType, providerNumber }) { + getShopTimeSlots( + context, + { payload: { startDate, endDate, shopAppointmentType, providerNumber }, pageNameToLog } + ) { const order = context.state.order; const vehicle = context.state.order.vehicle; @@ -1391,6 +1400,8 @@ export const actions = { method: endpoints.GetShopTimeSlots.method, endpoint: endpoints.GetShopTimeSlots.url, payload: payload, + logApiCall: true, + pageNameToLog: pageNameToLog, additionalSuccessEventDataHandler: (response) => getTimeSlotsAdditionalEventData( response.data.provisionalTriggers,