From e4fee3c8abe880c2e81c95207215f5829f2fa9ef Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Tue, 11 Mar 2025 15:15:45 -0400 Subject: [PATCH] CASH-152: refactoring changes --- src/fmg-components/cart/cart.vue | 2 +- ...nd-payment-helper.js => pricing-helper.js} | 14 ++++++++-- ...-helper.spec.js => pricing-helper.spec.js} | 28 +++++++++---------- src/layouts/payment-method/payment-method.vue | 2 +- .../payment-pia-return/payment-pia-return.vue | 2 +- src/layouts/payment/payment.vue | 2 +- 6 files changed, 28 insertions(+), 22 deletions(-) rename src/helpers/{cart-and-payment-helper.js => pricing-helper.js} (85%) rename src/helpers/{cart-and-payment-helper.spec.js => pricing-helper.spec.js} (65%) diff --git a/src/fmg-components/cart/cart.vue b/src/fmg-components/cart/cart.vue index 7a6386eb5..b6525fa67 100644 --- a/src/fmg-components/cart/cart.vue +++ b/src/fmg-components/cart/cart.vue @@ -178,7 +178,7 @@ import { getAmountDue, getSubTotal, getSalesTax, -} from "@/helpers/cart-and-payment-helper.js"; +} from "@/helpers/pricing-helper.js"; // Constants import { partTypeStrings } from "@/constants/part-type-strings"; diff --git a/src/helpers/cart-and-payment-helper.js b/src/helpers/pricing-helper.js similarity index 85% rename from src/helpers/cart-and-payment-helper.js rename to src/helpers/pricing-helper.js index d419af8a2..a386ed231 100644 --- a/src/helpers/cart-and-payment-helper.js +++ b/src/helpers/pricing-helper.js @@ -26,17 +26,25 @@ export function getAmountDue(lineItems, includeTax = true) { ); } - const order = baseMixin?.methods?.hasSubmittedOrder() ? baseMixin?.methods?.getSubmittedOrder() : store.getters.order; + const order = baseMixin?.methods?.hasSubmittedOrder() + ? baseMixin?.methods?.getSubmittedOrder() + : store.getters.order; if (store.getters.coverageIsVerified && !order.policy.isNoComp && !order.policy.isItac) { amountDue = order.policy.currentDeductible; } if (lineItems?.vaps) { - amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts(lineItems.vaps, includeTax); + amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts( + lineItems.vaps, + includeTax + ); } if (lineItems?.promos) { - amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts(lineItems.promos, includeTax); + amountDue += baseMixin?.methods?.getTotalPriceOfAllLineItemsAndChildParts( + lineItems.promos, + includeTax + ); } return ((amountDue * 100) / 100).toFixed(2); diff --git a/src/helpers/cart-and-payment-helper.spec.js b/src/helpers/pricing-helper.spec.js similarity index 65% rename from src/helpers/cart-and-payment-helper.spec.js rename to src/helpers/pricing-helper.spec.js index aeebe0431..6076343f5 100644 --- a/src/helpers/cart-and-payment-helper.spec.js +++ b/src/helpers/pricing-helper.spec.js @@ -33,34 +33,32 @@ const lineItems = { promos: [], }; -describe('cart-and-payment-helper', () => { - - describe('getDisplayAmountDue', () => { - it('should return the correct display amount due', () => { +describe("cart-and-payment-helper", () => { + describe("getDisplayAmountDue", () => { + it("should return the correct display amount due", () => { const result = getDisplayAmountDue(lineItems); - expect(result).toBe('53.00'); + expect(result).toBe("53.00"); }); }); - describe('getAmountDue', () => { - it('should return the correct amount due', () => { + describe("getAmountDue", () => { + it("should return the correct amount due", () => { const result = getAmountDue(lineItems, true); - expect(result).toBe('53.00'); + expect(result).toBe("53.00"); }); }); - describe('getSubTotal', () => { - it('should return the correct subtotal', () => { + describe("getSubTotal", () => { + it("should return the correct subtotal", () => { const result = getSubTotal(lineItems); - expect(result).toBe('50.00'); + expect(result).toBe("50.00"); }); }); - describe('getSalesTax', () => { - it('should return the correct sales tax', () => { + describe("getSalesTax", () => { + it("should return the correct sales tax", () => { const result = getSalesTax(lineItems); - expect(result).toBe('3.00'); + expect(result).toBe("3.00"); }); }); }); - diff --git a/src/layouts/payment-method/payment-method.vue b/src/layouts/payment-method/payment-method.vue index 1d1e34b27..33e070a93 100644 --- a/src/layouts/payment-method/payment-method.vue +++ b/src/layouts/payment-method/payment-method.vue @@ -163,7 +163,7 @@ import { getAmountDue, getSubTotal, getSalesTax, -} from "@/helpers/cart-and-payment-helper.js"; +} from "@/helpers/pricing-helper.js"; defineRule("payment-method-required", required(errorMessages.OPTION_REQUIRED)); defineRule("recal-ack-required", required(errorMessages.RECAL_ACK_REQUIRED)); diff --git a/src/layouts/payment-pia-return/payment-pia-return.vue b/src/layouts/payment-pia-return/payment-pia-return.vue index cd68ada0f..b9f19f64a 100644 --- a/src/layouts/payment-pia-return/payment-pia-return.vue +++ b/src/layouts/payment-pia-return/payment-pia-return.vue @@ -20,7 +20,7 @@ import { getAmountDue, getSubTotal, getSalesTax, -} from "@/helpers/cart-and-payment-helper.js"; +} from "@/helpers/pricing-helper.js"; // iframeResizer IS loaded into the page and necessary for the package to // to auto scale the iFrame this page is loaded in // Do not remove despite showing as "unused" CASH-309 diff --git a/src/layouts/payment/payment.vue b/src/layouts/payment/payment.vue index c11c9033b..abf06927b 100644 --- a/src/layouts/payment/payment.vue +++ b/src/layouts/payment/payment.vue @@ -239,7 +239,7 @@ import { getAmountDue, getSubTotal, getSalesTax, -} from "@/helpers/cart-and-payment-helper.js"; +} from "@/helpers/pricing-helper.js"; export default { name: "payment",