Merge pull request #1487 from Safelite/feature/CSR-1382-loose-ends

Front end changes for recent backend changed related to repair chips
This commit is contained in:
Leah Schumann 2023-11-02 15:08:30 -04:00 committed by GitHub
commit b2b5e4ff6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 6 deletions

View file

@ -452,7 +452,7 @@ describe("shop-question.vue", () => {
// Assert
expect(wrapper.vm.answers.length).toBe(6);
console.log(wrapper.vm.answers);
expect(wrapper.vm.answers).toEqual([
{
buttonBodyCopy: "4403 Executive Pkwy, Westerville, OH 43081",

View file

@ -2605,12 +2605,69 @@ export function mapTaxedAvailableLineItemsToStoreFormat(availableLineItems, stor
for (let [category, lineItemsInCategory] of Object.entries(lineItems)) {
lineItemsInCategory = lineItemsInCategory ?? [];
for (let lineItemIndex = 0; lineItemIndex < lineItemsInCategory.length; lineItemIndex++) {
const availableLineItem = availableLineItems.find(
(ali) => ali.partNumber == lineItemsInCategory[lineItemIndex].partNumber
if (category == "supportingItems") {
// if the category is supporting items we need to filter out the items that aren't repair chips
const nonRepairChipSupportItemsLineItems = lineItemsInCategory.filter(
(lineItem) => lineItem.partNumber != "WSREPAIR"
);
if (availableLineItem) {
lineItemsInCategory[lineItemIndex].salesTax = availableLineItem.salesTax;
/*
Because repair chips all have the same part number but different prices based on the quantity,
we have to sort the store line items and available line items by descending labor amount in order to
map the tax correctly to each repair chip
*/
// get the supporting items that ARE repair chips and sort them by descending labor amount
let repairChipLineItems = lineItemsInCategory.filter(
(lineItem) => lineItem.partNumber == "WSREPAIR"
);
repairChipLineItems = repairChipLineItems.sort(
(a, b) => parseFloat(b.laborAmount) - parseFloat(a.laborAmount)
);
// get the supporting items from the available line items (taxed) that ARE repair chips and sort them by descending labor amount
let availableRepairChipLineItems = availableLineItems.filter(
(lineItem) => lineItem.partNumber == "WSREPAIR"
);
availableRepairChipLineItems = availableRepairChipLineItems.sort(
(a, b) => parseFloat(b.laborAmount) - parseFloat(a.laborAmount)
);
// go through each one of those mapping the taxes to the correct chip
for (let i = 0; i < availableRepairChipLineItems.length; i++) {
repairChipLineItems[i].salesTax = availableRepairChipLineItems[i].salesTax;
}
// then we map the non-repair chip items based on part number
for (
let lineItemIndex = 0;
lineItemIndex < nonRepairChipSupportItemsLineItems.length;
lineItemIndex++
) {
const availableLineItem = availableLineItems.find(
(ali) =>
ali.partNumber ==
nonRepairChipSupportItemsLineItems[lineItemIndex].partNumber
);
if (availableLineItem) {
nonRepairChipSupportItemsLineItems[lineItemIndex].salesTax =
availableLineItem.salesTax;
}
}
// finally we splice the two arrays back into one
lineItemsInCategory = nonRepairChipSupportItemsLineItems.concat(repairChipLineItems);
} else {
for (
let lineItemIndex = 0;
lineItemIndex < lineItemsInCategory.length;
lineItemIndex++
) {
const availableLineItem = availableLineItems.find(
(ali) => ali.partNumber == lineItemsInCategory[lineItemIndex].partNumber
);
if (availableLineItem) {
lineItemsInCategory[lineItemIndex].salesTax = availableLineItem.salesTax;
}
}
}
}