fixed issues with check to see if prices were all there

This commit is contained in:
Jason Wheeler 2023-05-23 13:49:01 -04:00
parent 9e5845014c
commit 39fe1337c3
4 changed files with 66 additions and 34 deletions

View file

@ -0,0 +1,41 @@
export const allGlassPartsAndItemsHavePrices = (lineItems) => {
if (lineItems.glassParts && Array.isArray(lineItems.glassParts)) {
if(!processLineItems(lineItems.glassParts))
{
return false;
}
};
if (lineItems.supportingItems && Array.isArray(lineItems.supportingItems)) {
if(!processLineItems(lineItems.supportingItems))
{
return false;
}
};
if (lineItems.vaps && Array.isArray(lineItems.vaps)) {
if(!processLineItems(lineItems.vaps))
{
return false;
}
};
return true;
};
const processLineItems = (lineItems) => {
let returnVal = true;
lineItems.forEach( lineItem => {
if (!hasPrice(lineItem)) {
returnVal = false;
};
});
return returnVal;
}
const hasPrice = (lineItem) => {
const value = (!!lineItem?.kitPrice && lineItem.kitPrice != 0) ||
(!!lineItem?.laborAmount && lineItem.laborAmount != 0) ||
(!!lineItem?.sellingPrice && lineItem.sellingPrice != 0);
return value;
};

View file

@ -0,0 +1,19 @@
import { allGlassPartsAndItemsHavePrices } from './service-package-helper';
it("service package helper should return false when line item has missing price", () => {
// Arrange
const mockData = { glassParts: [{partNumber: 'DW01571GBNNOEE', sellingPrice: 25}], supportingItems: [{ laborAmount: 0 }] }
// Act
const actual = allGlassPartsAndItemsHavePrices(mockData);
// Assert
expect(actual).toEqual(false);
});
it("service package helper should return true when line item has all prices", () => {
// Arrange
const mockData = { glassParts: [{partNumber: 'DW01571GBNNOEE', sellingPrice: 25}], laborAmount: [{ sellingPrice: 10 }] }
// Act
const actual = allGlassPartsAndItemsHavePrices(mockData);
// Assert
expect(actual).toBeTruthy();
});

View file

@ -13,9 +13,10 @@
import buttonQuestion from '@/digital-components/button-question/button-question';
import { processIfStatements } from '@/helpers/cms-content-helper';
import { damageLocationsSelected as glassLocations } from '@/constants/damage-locations-selected';
import servicePackageRadio from './service-package-radio/service-package-radio';
import servicePackageRadio from '@/layouts/service-packages/service-package-question/service-package-radio/service-package-radio';
import { partTypeStrings } from '@/constants/part-type-strings';
import { useMainStore } from '@/store';
import { allGlassPartsAndItemsHavePrices } from '@/layouts/service-packages/service-package-helper/service-package-helper'
const packageNames = {
TIER_ONE: 'TierOne',
@ -43,7 +44,7 @@
},
watch: {
availableLineItems() {
if (this.allGlassPartsAndItemsHavePrices(store.order.lineItems)) {
if (allGlassPartsAndItemsHavePrices(store.order.lineItems)) {
this.selectDefaultPackage();
}
},
@ -312,37 +313,6 @@
return null;
}
},
allGlassPartsAndItemsHavePrices() {
if (this.pricedGlassParts) {
for (let i = 0; i < this.pricedGlassParts.length; i++) {
if (this.priceIsNullOrZero(this.pricedGlassParts[i])) {
return false;
}
}
}
if (this.supportingItems) {
for (let i = 0; i < this.supportingItems.length; i++) {
if (this.priceIsNullOrZero(this.supportingItems[i])) {
return false;
}
}
}
if (this.selectedVaps) {
for (let i = 0; i < this.selectedVaps.length; i++) {
if (this.priceIsNullOrZero(this.selectedVaps[i])) {
return false;
}
}
}
return true;
},
priceIsNullOrZero(lineItem) {
return (
(lineItem.kitPrice == null || lineItem.kitPrice == 0) &&
(lineItem.laborAmount == null || lineItem.laborAmount == 0) &&
(lineItem.sellingPrice == null || lineItem.sellingPrice == 0)
);
},
getLineItemsContainingPartType(partType) {
const partTypeMatches = this.nullSafeAvailableLineItems.filter(
(lineItem) => lineItem.partType.toUpperCase() === partType

View file

@ -54,6 +54,7 @@
import { required } from '@/helpers/validation-rules';
import { errorMessages } from '@/constants/error-messages';
import { Form, defineRule } from 'vee-validate';
import { allGlassPartsAndItemsHavePrices } from '@/layouts/service-packages/service-package-helper/service-package-helper'
defineRule('option-required', required(errorMessages.OPTION_REQUIRED));
@ -143,7 +144,8 @@
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
},
forwardButtonAction() {
if (!this.$ref.servicePackage.allGlassPartsAndItemsHavePrices()) {
const parts = { glassParts: this.pricedGlassParts, supportingItems: this.supportingItems, vaps: this.selectedVaps };
if (!allGlassPartsAndItemsHavePrices(parts)) {
console.error('One or more items have no price assigned!');
}
if (this.pricedGlassParts.length > 0) {