INSR-9513: Add getRecalibrationTotal tests
This commit is contained in:
parent
2be1a91e16
commit
5e5d31d979
1 changed files with 99 additions and 3 deletions
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue