From 4fbca5ccd8fd7250129b9781a3697150616a125e Mon Sep 17 00:00:00 2001 From: Alex Humphries Date: Mon, 4 May 2026 15:08:52 -0400 Subject: [PATCH 1/3] INSR-9513: Add all recal parts to glass part child parts array --- src/store/index.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index e93e62b7..ca323c1c 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1120,7 +1120,7 @@ export const useMainStore = defineStore({ .then((response) => { const recalResponse = response.data; if (recalResponse && recalResponse.recalibrationParts && recalResponse.recalibrationParts.length > 0) { - this.addGlassPartRecalibrationInfo(partNumberChecked, recalResponse.recalibrationParts[0]); + this.addGlassPartRecalibrationInfo(partNumberChecked, recalResponse.recalibrationParts); } })); } @@ -1128,15 +1128,18 @@ export const useMainStore = defineStore({ await Promise.allSettled(recalPromises); } }, - addGlassPartRecalibrationInfo(partNumber, recalPartInformation) { + addGlassPartRecalibrationInfo(partNumber, recalPartArray) { const glassPart = this.lineItems.glassParts.find((gp) => gp.partNumber === partNumber); if (glassPart) { - const recalChildPart = glassPart.childParts?.find((cp) => cp.partNumber === recalPartInformation.partNumber); - if (!recalChildPart) { - if (!Array.isArray(glassPart.childParts) || !glassPart.childParts.length) { - glassPart.childParts = []; + for (const recalPartInformation of recalPartArray) { + const recalChildPart = glassPart.childParts?.find((cp) => cp.partNumber === recalPartInformation.partNumber); + console.log('Existing recalibration child part found', recalChildPart); + if (!recalChildPart) { + if (!Array.isArray(glassPart.childParts) || !glassPart.childParts.length) { + glassPart.childParts = []; + } + glassPart.childParts.push(recalPartInformation); } - glassPart.childParts.push(recalPartInformation); } } }, From 2be1a91e16244fc94e12ea35b7637368c369331a Mon Sep 17 00:00:00 2001 From: Alex Humphries Date: Mon, 4 May 2026 15:39:34 -0400 Subject: [PATCH 2/3] INSR-9513: Remove console.log, handle multiple recal parts in price calc --- src/helpers/cart-helper.js | 5 +++-- src/store/index.js | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/cart-helper.js b/src/helpers/cart-helper.js index 1920df3c..22b0dcdb 100644 --- a/src/helpers/cart-helper.js +++ b/src/helpers/cart-helper.js @@ -165,8 +165,9 @@ export function getCartTotal(order) { export function getRecalibrationTotal(order) { const itemsWithRecalibration = getServiceLineItems(order) .filter((item) => item.requiresRecalibration); - const recalibrationLineItems = itemsWithRecalibration.map((item) => { - return item.childParts?.find((child) => child.partType === partTypeStrings.RECALIBRATION || child.partType === partTypeStrings.ADAS_RECALIBRATION) ?? {}; + + const recalibrationLineItems = itemsWithRecalibration.flatMap((item) => { + return item.childParts?.filter((child) => child.partType === partTypeStrings.RECALIBRATION || child.partType === partTypeStrings.ADAS_RECALIBRATION) ?? []; }); return getPriceOfLineItems(recalibrationLineItems); diff --git a/src/store/index.js b/src/store/index.js index ca323c1c..955c7283 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1133,7 +1133,6 @@ export const useMainStore = defineStore({ if (glassPart) { for (const recalPartInformation of recalPartArray) { const recalChildPart = glassPart.childParts?.find((cp) => cp.partNumber === recalPartInformation.partNumber); - console.log('Existing recalibration child part found', recalChildPart); if (!recalChildPart) { if (!Array.isArray(glassPart.childParts) || !glassPart.childParts.length) { glassPart.childParts = []; From 5e5d31d97971c82c7715fc36dfe5eb9c12b776fe Mon Sep 17 00:00:00 2001 From: Alex Humphries Date: Tue, 5 May 2026 08:41:37 -0400 Subject: [PATCH 3/3] INSR-9513: Add getRecalibrationTotal tests --- src/helpers/cart-helper.spec.js | 102 +++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 3 deletions(-) diff --git a/src/helpers/cart-helper.spec.js b/src/helpers/cart-helper.spec.js index 5a70feab..c57eaa86 100644 --- a/src/helpers/cart-helper.spec.js +++ b/src/helpers/cart-helper.spec.js @@ -4,6 +4,7 @@ import { getDeductible, getLineItems, getMobileFeeLineItem, getNonServiceLineItems, + getRecalibrationTotal, getRecycleFeeLineItem, getSalesTax, getServiceLineItems, getSubtotal, isOrderITAC, isOrderNoComp, isOrderUnverified @@ -25,7 +26,7 @@ describe('cart-helper', () => { }; } - function createDummyFeeItem(partNumber, partType, price, salesTax) { + function createDummyItemWithPartType(partNumber, partType, price, salesTax) { return { partNumber, partType, @@ -56,8 +57,8 @@ describe('cart-helper', () => { const glassLineItem = createDummyItem('glass', 40, 2); const otherLineItem = createDummyItem('other', 50, 3); const vapsLineItem = createDummyItem('vaps', 60, 4); - const mobileFeeLineItem = createDummyFeeItem(null, partTypeStrings.MOBILE_FEE, 70, 5); - const recycleFeeLineItem = createDummyFeeItem(partNumberStrings.RECYCLE_FEE, null, 80, 6); + const mobileFeeLineItem = createDummyItemWithPartType(null, partTypeStrings.MOBILE_FEE, 70, 5); + const recycleFeeLineItem = createDummyItemWithPartType(partNumberStrings.RECYCLE_FEE, null, 80, 6); const defaultLineItems = { supportingItems: [supportingLineItem], @@ -592,4 +593,99 @@ describe('cart-helper', () => { }); }); }); + + describe('getRecalibrationTotal', () => { + test('Returns total price of recalibration items when there is only 1', () => { + // Arrange + const recalibrationItem = createDummyItemWithPartType('recal', partTypeStrings.RECALIBRATION, 25, 2); + const lineItemWithRecal = { + ...glassLineItem, + requiresRecalibration: true, + childParts: [recalibrationItem] + }; + const order = { + lineItems: { + ...defaultLineItems, + glassParts: [lineItemWithRecal] + } + }; + + // Act + const result = getRecalibrationTotal(order); + + // Assert + expect(result).toBe(25); + }); + test('Returns total price of recalibration items when there are multiple', () => { + // Arrange + const recalibrationItem = createDummyItemWithPartType('recal', partTypeStrings.RECALIBRATION, 25, 2); + const thirdRecalibrationItem = createDummyItemWithPartType('third-recal', partTypeStrings.ADAS_RECALIBRATION, 35, 3); + const lineItemWithRecal = { + ...glassLineItem, + requiresRecalibration: true, + childParts: [recalibrationItem, thirdRecalibrationItem] + }; + const order = { + lineItems: { + ...defaultLineItems, + glassParts: [lineItemWithRecal] + } + }; + + // Act + const result = getRecalibrationTotal(order); + + // Assert + expect(result).toBe(60); + }); + + test('Returns 0 when no items require recalibration', () => { + // Arrange + const order = { + lineItems: defaultLineItems + }; + + // Act + const result = getRecalibrationTotal(order); + + // Assert + expect(result).toBe(0); + }); + + test('Returns 0 when line items are null', () => { + // Arrange + const order = { + lineItems: nullLineItems + }; + + // Act + const result = getRecalibrationTotal(order); + + // Assert + expect(result).toBe(0); + }); + + test('Filters out non-recalibration child parts', () => { + // Arrange + const recalibrationItem = createDummyItemWithPartType('recal', partTypeStrings.RECALIBRATION, 25, 2); + const otherChildItem = createDummyItem('other-child', 15, 1); + const lineItemWithRecal = { + ...glassLineItem, + requiresRecalibration: true, + childParts: [recalibrationItem, otherChildItem] + }; + const order = { + lineItems: { + ...defaultLineItems, + glassParts: [lineItemWithRecal] + } + }; + + // Act + const result = getRecalibrationTotal(order); + + // Assert + expect(result).toBe(25); + }); + }); });