diff --git a/src/helpers/service-location-helper.js b/src/helpers/service-location-helper.js index 1f4a12f51..41f4be147 100644 --- a/src/helpers/service-location-helper.js +++ b/src/helpers/service-location-helper.js @@ -1,20 +1,20 @@ import { storeActions } from "@/constants/store-actions"; import baseMixin from "@/mixins/base-mixin.js"; -export async function getMobileFee(serviceZipCode) { +export async function getPricedMobileFeePart(serviceZipCode) { if (!serviceZipCode) { - return 0; + return Promise.resolve(null); } const zipCodeData = await baseMixin.methods.getZipCodeData(serviceZipCode); - + // Get the Mobile Fee Part const mobileFeePart = await baseMixin.methods.dispatchStoreAction( storeActions.GET_MOBILE_FEE_PART, null, false ); - + // Get the Mobile Fee Part Price const pricingResults = await baseMixin.methods.dispatchStoreAction( storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA, @@ -26,5 +26,5 @@ export async function getMobileFee(serviceZipCode) { false ); - return Promise.resolve(baseMixin.methods.getTotalLineItemPrice(pricingResults[0])); + return Promise.resolve(pricingResults[0]); } diff --git a/src/helpers/service-location-helper.spec.js b/src/helpers/service-location-helper.spec.js index 66012402c..9b1920fba 100644 --- a/src/helpers/service-location-helper.spec.js +++ b/src/helpers/service-location-helper.spec.js @@ -1 +1,78 @@ -test.todo("some test to be written in the future"); \ No newline at end of file +import { getPricedMobileFeePart } from "./service-location-helper"; +import { storeActions } from "@/constants/store-actions"; + +const mockStoreActionGetMobileFeePart = storeActions.GET_MOBILE_FEE_PART; +const mockStoreActionPriceOrderItemsAndSaveServerData = storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA; + +jest.mock("@/mixins/base-mixin.js", () => ({ + methods: { + getZipCodeData: jest.fn().mockImplementation(() => { + return Promise.resolve({ + containsMilitaryBase: false, + isServiceable: true, + isValid: true, + state: "OH", + zipCodeCtu: "01820", + }); + }), + + dispatchStoreAction: jest.fn().mockImplementation((actionName) => { + 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, + }, + ]); + } + }), + + }, +})); + +describe("service-location-helper.js", () => { + it("Should return the null if no service zip code is passed in", async() => { + // Arrange / Act + const serviceZipCode = null; + const expected = null; + + const result = await getPricedMobileFeePart(serviceZipCode); + + // Assert + expect(result).toEqual(expected); + }); + + it("Should return the priced mobile fee part", async() => { + // Arrange / Act + const serviceZipCode = "43235"; + const expected = { + partNumber: "MOBILE FEE", + description: "MOBILE FEE", + partType: "FEE", + laborAmount: 49.99, + sellingPrice: 0, + kitPrice: 0, + } + + const result = await getPricedMobileFeePart(serviceZipCode); + + // Assert + expect(result).toEqual(expected); + }); +}) + +//test.todo("some test to be written in the future"); 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 a15709f67..ba7cc2fab 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 @@ -109,14 +109,21 @@ export default { }, mobileFeeText() { const cmsContentText = this.getCmsContent("MobileFeeDisclaimerWidget", "Text"); - if (this.modelValue.mobileFee === undefined) { - return cmsContentText.replaceAll("{custom:mobileFee}", 0); - } - return cmsContentText.replaceAll("{custom:mobileFee}", this.modelValue.mobileFee); + return cmsContentText.replaceAll("{custom:mobileFee}", this.mobileFee); }, modalFooterText() { return this.getCmsContent(this.modalWidgetName, "FooterText"); }, + mobileFee() { + if (!this.modelValue.mobileFeePart) { + return 0; + } + return ( + this.modelValue.mobileFeePart.laborAmount + + this.modelValue.mobileFeePart.sellingPrice + + this.modelValue.mobileFeePart.kitPrice + ); + }, addressModel: { get: function () { return this.modelValue.addressQuestions; diff --git a/src/layouts/service-location/service-location.vue b/src/layouts/service-location/service-location.vue index f2339b218..6c7849216 100644 --- a/src/layouts/service-location/service-location.vue +++ b/src/layouts/service-location/service-location.vue @@ -6,7 +6,7 @@ @@ -38,7 +38,7 @@ import { Form } from "vee-validate"; import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { settleAllPromises } from "@/helpers/layout-helper"; import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; -import { getMobileFee } from "@/helpers/service-location-helper"; +import { getPricedMobileFeePart } from "@/helpers/service-location-helper"; import store from "@/store"; export default { @@ -66,13 +66,13 @@ export default { }, }; }, - async beforeRouteEnter(to, from, next) { + async beforeRouteEnter(to, from, next) { // Call APIs const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); - const serviceZipCode = store.getters.order.serviceLocation.zipCode; - const mobileFeePromise = getMobileFee(serviceZipCode); - + const serviceZipCode = store.getters.order.serviceLocation.zipCode; + const mobileFeePartPromise = getPricedMobileFeePart(serviceZipCode); + // Settle promises and get results const promiseResultMap = [ { @@ -80,17 +80,19 @@ export default { promise: cmsContentPromise, }, { - resultKey: "mobileFee", - promise: mobileFeePromise, + resultKey: "mobileFeePart", + promise: mobileFeePartPromise, }, ]; const resultMap = await settleAllPromises(promiseResultMap); - + console.log(resultMap); + console.log(resultMap.cmsContent); + console.log(resultMap.mobileFeePart); // Call the "next" function to complete the transition to this page. next((vm) => { vm.setCmsContent(resultMap.cmsContent); - vm.setData(resultMap.mobileFee); + vm.setData(resultMap.mobileFeePart); }); }, methods: { @@ -102,9 +104,9 @@ export default { // store.getters.payment.isInsurance !== null // ); }, - setData(mobileFee) { - if (mobileFee) { - this.mobileLocationQuestions.mobileFee = mobileFee + setData(mobileFeePart) { + if (mobileFeePart) { + this.mobileLocationQuestions.mobileFeePart = mobileFeePart; } }, getRegistrationAddressFromStore() { @@ -128,9 +130,9 @@ export default { getIsServiceableFromStore() { return store.getters.order.serviceLocation.isServiceable; }, - recalculateMobileFee(serviceZipCode) { - getMobileFee(serviceZipCode).then((mobileFee) => { - this.mobileLocationQuestions.mobileFee = mobileFee; + resetMobileFeePart(serviceZipCode) { + getPricedMobileFeePart(serviceZipCode).then((pricedMobileFeePart) => { + this.mobileLocationQuestions.mobileFeePart = pricedMobileFeePart; }); }, resetMobileLocation(updatedServiceZipCode) { @@ -153,7 +155,7 @@ export default { this.serviceZipCodeQuestion.zipCode = newValue.zipCode; this.serviceZipCodeQuestion.isServiceable = newValue.isServiceable; - this.recalculateMobileFee(this.serviceZipCodeQuestion.zipCode); + this.resetMobileFeePart(this.serviceZipCodeQuestion.zipCode); }, backButtonAction() { this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route);