Merge pull request #1209 from Safelite/feature/humphries/ISR-9513

INSR-9513: Add all recal parts to glass part child parts array
This commit is contained in:
AHumphriesSL 2026-05-05 09:45:02 -04:00 committed by GitHub
commit 943e23f4de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 111 additions and 12 deletions

View file

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

View file

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

View file

@ -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,17 @@ 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);
if (!recalChildPart) {
if (!Array.isArray(glassPart.childParts) || !glassPart.childParts.length) {
glassPart.childParts = [];
}
glassPart.childParts.push(recalPartInformation);
}
glassPart.childParts.push(recalPartInformation);
}
}
},