Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gh 12987 handle new cart entry api format #13066

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
f7b8191
GH-12987 handle new cart entry API format
AlexanderKuschner Jul 7, 2021
36d5298
Merge remote-tracking branch 'origin/develop' into feature/GH-12987_H…
AlexanderKuschner Jul 7, 2021
a8b3de9
GH-12987 adjust line item access logic
AlexanderKuschner Jul 7, 2021
5280d91
GH-12987 add aditional unittests for enhanced API format
Stofftiger Jul 9, 2021
ff6675a
Merge remote-tracking branch 'origin/develop' into feature/GH-12987_H…
AlexanderKuschner Jul 12, 2021
c629640
Update feature-libs/product-configurator/common/components/configurat…
AlexanderKuschner Jul 12, 2021
921324d
Update feature-libs/product-configurator/common/components/configurat…
AlexanderKuschner Jul 12, 2021
6f96c31
Update feature-libs/product-configurator/common/components/configurat…
AlexanderKuschner Jul 12, 2021
05ffa0b
Update feature-libs/product-configurator/common/core/model/common-con…
AlexanderKuschner Jul 12, 2021
eef8fd4
Update feature-libs/product-configurator/common/core/model/common-con…
AlexanderKuschner Jul 12, 2021
cd9662c
GH-12987 adjust configuration info format
AlexanderKuschner Jul 12, 2021
211b5a7
Merge remote-tracking branch 'origin/develop' into feature/GH-12987_H…
AlexanderKuschner Jul 13, 2021
9fa1b5c
Merge remote-tracking branch 'origin/develop' into feature/GH-12987_H…
AlexanderKuschner Jul 14, 2021
71bc503
Merge branch 'develop' into feature/GH-12987_Handle_new_cart_entry_AP…
ChristophHi Jul 14, 2021
e1ce51c
Merge remote-tracking branch 'origin/develop' into feature/GH-12987_H…
AlexanderKuschner Jul 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,115 @@ const orderEntry: OrderEntry = {
],
};

const productName0 = 'PRODUCT_NAME_0';
const productQty0 = '1';
const productFormattedPrice0 = '$100.00';
const productKey0 = 'PRODUCT_KEY_0';
const productPriceValue0 = '100.00';
const productName1 = 'PRODUCT_NAME_1';
const productQty1 = '1';
const productFormattedPrice1 = '$100.00';
const productKey1 = 'PRODUCT_KEY_1';
const productPriceValue1 = '100.00';
const v2_confInfo_version: ConfigurationInfo = {
configurationLabel: 'CI#@#VERSION',
configurationValue: '2',
};

const v2_confInfo0_name_novalue: ConfigurationInfo = {
configurationLabel: 'LI#0#NAME',
configurationValue: '',
};

const v2_confInfo0_unexpected: ConfigurationInfo = {
configurationLabel: 'UNEXPECTED#0#NAME',
configurationValue: 'VALUE',
};

const v2_confInfo0_name: ConfigurationInfo = {
configurationLabel: 'LI#0#NAME',
configurationValue: productName0,
};

const v2_confInfo0_qty: ConfigurationInfo = {
configurationLabel: 'LI#0#QTY',
configurationValue: productQty0,
};

const v2_confInfo0_formattedprice: ConfigurationInfo = {
configurationLabel: 'LI#0#FORMATTED_PRICE',
configurationValue: productFormattedPrice0,
};

const v2_confInfo0_key: ConfigurationInfo = {
configurationLabel: 'LI#0#KEY',
configurationValue: productKey0,
};

const v2_confInfo0_pricevalue: ConfigurationInfo = {
configurationLabel: 'LI#0#PRICE_VALUE',
configurationValue: productPriceValue0,
};

const v2_confInfo1_name: ConfigurationInfo = {
configurationLabel: 'LI#1#NAME',
configurationValue: productName1,
};

const v2_confInfo1_qty: ConfigurationInfo = {
configurationLabel: 'LI#1#QTY',
configurationValue: productQty1,
};

const v2_confInfo1_formattedprice: ConfigurationInfo = {
configurationLabel: 'LI#1#FORMATTED_PRICE',
configurationValue: productFormattedPrice1,
};

const v2_confInfo1_key: ConfigurationInfo = {
configurationLabel: 'LI#1#KEY',
configurationValue: productKey1,
};

const v2_confInfo1_pricevalue: ConfigurationInfo = {
configurationLabel: 'LI#1#PRICE_VALUE',
configurationValue: productPriceValue1,
};

const v2_expectedLineItem0: LineItem = {
name: productName0,
formattedQuantity: productQty0,
formattedPrice: productFormattedPrice0,
};

const v2_expectedLineItem1: LineItem = {
name: productName1,
formattedQuantity: productQty1,
formattedPrice: productFormattedPrice1,
};

const v2_initializedLineItem: LineItem = {
name: '',
formattedQuantity: '',
formattedPrice: '',
};

const v2_orderEntry: OrderEntry = {
configurationInfos: [
v2_confInfo_version,
v2_confInfo0_key,
v2_confInfo0_name,
v2_confInfo0_qty,
v2_confInfo0_formattedprice,
v2_confInfo0_pricevalue,
v2_confInfo1_key,
v2_confInfo1_name,
v2_confInfo1_qty,
v2_confInfo1_formattedprice,
v2_confInfo1_pricevalue,
],
};

describe('ConfiguratorCartEntryBundleInfoService', () => {
let configuratorCartEntryBundleInfoService: ConfiguratorCartEntryBundleInfoService;

Expand Down Expand Up @@ -124,4 +233,239 @@ describe('ConfiguratorCartEntryBundleInfoService', () => {
expect(lineItems[2]).toEqual(expectedLineItem3);
expect(lineItems[3]).toEqual(expectedLineItem4);
});

describe('for enhanced OCC API format: ', () => {
it('should retrieve an existing line item for requested line item number from line item map', () => {
const lineItemMap: Map<number, LineItem> = new Map();
const lineItemNumber = 123;
lineItemMap.set(lineItemNumber, v2_expectedLineItem0);
const lineItem: LineItem = configuratorCartEntryBundleInfoService[
'getOrCreateLineItem'
](lineItemMap, lineItemNumber);
expect(lineItem).toEqual(v2_expectedLineItem0);
expect(lineItemMap.size).toBe(1);
expect(lineItemMap.get(lineItemNumber)).toEqual(v2_expectedLineItem0);
});

it('should retrieve a new line item for requested line item number if it doesnt exist in line item map yet', () => {
const lineItemMap: Map<number, LineItem> = new Map();
const lineItemNumber = 123;
const lineItem: LineItem = configuratorCartEntryBundleInfoService[
'getOrCreateLineItem'
](lineItemMap, lineItemNumber);
expect(lineItem).toEqual(v2_initializedLineItem);
expect(lineItemMap.size).toBe(1);
expect(lineItemMap.get(lineItemNumber)).toEqual(v2_initializedLineItem);
});

it('should add line item data for expected fields(NAME, QTY, FORMATTED_PRICE): ', () => {
const lineItemMap: Map<number, LineItem> = new Map();
const lineItemNumber = 123;
const lineItemNumberAsString = '123';
const configurationInfosSplitName = [
'LINEITEM',
lineItemNumberAsString,
'NAME',
];
const configurationInfosSplitQty = [
'LINEITEM',
lineItemNumberAsString,
'QTY',
];
const configurationInfosSplitFormattedPrice = [
'LINEITEM',
lineItemNumberAsString,
'FORMATTED_PRICE',
];

const configurationInfoValueName = 'Name';
const configurationInfoValueQty = 'QtY';
const configurationInfoValueFormattedPrice = 'FormattedPrice';

configuratorCartEntryBundleInfoService['addLineItemData'](
lineItemMap,
configurationInfosSplitName,
configurationInfoValueName
);
configuratorCartEntryBundleInfoService['addLineItemData'](
lineItemMap,
configurationInfosSplitQty,
configurationInfoValueQty
);
configuratorCartEntryBundleInfoService['addLineItemData'](
lineItemMap,
configurationInfosSplitFormattedPrice,
configurationInfoValueFormattedPrice
);

expect(lineItemMap.size).toBe(1);
expect(lineItemMap.get(lineItemNumber)?.name).toBe(
configurationInfoValueName
);
expect(lineItemMap.get(lineItemNumber)?.formattedQuantity).toBe(
configurationInfoValueQty
);
expect(lineItemMap.get(lineItemNumber)?.formattedPrice).toBe(
configurationInfoValueFormattedPrice
);
});

it('should not add line item data for unexpected fields ', () => {
const lineItemMap: Map<number, LineItem> = new Map();
const lineItemNumberAsString = '123';
const configurationInfosSplitUnexpectedFieldName = [
'LINEITEM',
lineItemNumberAsString,
'UNEXPECTED_FIELD_NAME',
];

const configurationInfosSplitKey = [
'LINEITEM',
lineItemNumberAsString,
'KEY',
];

const configurationInfosSplitPriceValue = [
'LINEITEM',
lineItemNumberAsString,
'PRICE_VALUE',
];

const configurationInfoValueUnexpectedField = 'ValueOfUnexpectedField';
configuratorCartEntryBundleInfoService['addLineItemData'](
lineItemMap,
configurationInfosSplitUnexpectedFieldName,
configurationInfoValueUnexpectedField
);

configuratorCartEntryBundleInfoService['addLineItemData'](
lineItemMap,
configurationInfosSplitKey,
configurationInfoValueUnexpectedField
);

configuratorCartEntryBundleInfoService['addLineItemData'](
lineItemMap,
configurationInfosSplitPriceValue,
configurationInfoValueUnexpectedField
);

expect(lineItemMap.size).toBe(0);
});

it('should not add line item data for unexpected format ', () => {
const lineItemMap: Map<number, LineItem> = new Map();
const configurationInfosSplitUnexpectedFormat = [
'LINEITEM',
'0',
'NAME',
'unexpectedField',
];
const configurationInfoValue = 'Value of unexpected Field';
configuratorCartEntryBundleInfoService['addLineItemData'](
lineItemMap,
configurationInfosSplitUnexpectedFormat,
configurationInfoValue
);
expect(lineItemMap.size).toBe(0);
});

it('should add line item data if configurationSplit[0] is "LI" ', () => {
const lineItemMap: Map<number, LineItem> = new Map();
configuratorCartEntryBundleInfoService['processConfigurationInfoEntry'](
lineItemMap,
v2_confInfo0_name
);
expect(lineItemMap.size).toBe(1);
expect(lineItemMap.get(0)?.name).toBe(productName0);
});

it('should not add line item data if configurationSplit[0] is not "LI" ', () => {
const lineItemMap: Map<number, LineItem> = new Map();
configuratorCartEntryBundleInfoService['processConfigurationInfoEntry'](
lineItemMap,
v2_confInfo0_unexpected
);
expect(lineItemMap.size).toBe(0);
});

it('should not add line item data to the map if configuration label is empty or undefined', () => {
const lineItemMap: Map<number, LineItem> = new Map();
configuratorCartEntryBundleInfoService['processConfigurationInfoEntry'](
lineItemMap,
{
configurationLabel: '',
configurationValue: 'VALUE',
}
);
configuratorCartEntryBundleInfoService['processConfigurationInfoEntry'](
lineItemMap,
{
configurationLabel: undefined,
configurationValue: 'VALUE',
}
);
expect(lineItemMap.size).toBe(0);
});

it('should set configuration value to empty string if configuration info has no configuration value set', () => {
const lineItemMap: Map<number, LineItem> = new Map();
configuratorCartEntryBundleInfoService['processConfigurationInfoEntry'](
lineItemMap,
v2_confInfo0_name_novalue
);
expect(lineItemMap.get(0)?.name).toEqual('');
});

it('should deliver a correctly sorted line item array when a sorted configuration info array is given', () => {
const configurationInfoArraySorted: ConfigurationInfo[] = [
v2_confInfo0_key,
v2_confInfo0_name,
v2_confInfo0_qty,
v2_confInfo0_formattedprice,
v2_confInfo0_pricevalue,
v2_confInfo1_key,
v2_confInfo1_name,
v2_confInfo1_qty,
v2_confInfo1_formattedprice,
v2_confInfo1_pricevalue,
];
const lineItemArray: LineItem[] = configuratorCartEntryBundleInfoService[
'processConfigurationInfos'
](configurationInfoArraySorted);
expect(lineItemArray.length).toBe(2);
expect(lineItemArray[0]).toEqual(v2_expectedLineItem0);
expect(lineItemArray[1]).toEqual(v2_expectedLineItem1);
});

it('should deliver a correctly sorted line item array when an unsorted configuration info array is given', () => {
const configurationInfoArrayUnSorted: ConfigurationInfo[] = [
v2_confInfo1_key,
v2_confInfo0_key,
v2_confInfo0_qty,
v2_confInfo1_name,
v2_confInfo1_qty,
v2_confInfo0_name,
v2_confInfo0_formattedprice,
v2_confInfo0_pricevalue,
v2_confInfo1_formattedprice,
v2_confInfo1_pricevalue,
];
const lineItemArray: LineItem[] = configuratorCartEntryBundleInfoService[
'processConfigurationInfos'
](configurationInfoArrayUnSorted);
expect(lineItemArray.length).toBe(2);
expect(lineItemArray[0]).toEqual(v2_expectedLineItem0);
expect(lineItemArray[1]).toEqual(v2_expectedLineItem1);
});

it('should retrieve line items', () => {
const lineItems: LineItem[] = configuratorCartEntryBundleInfoService.retrieveLineItems(
v2_orderEntry
);
expect(lineItems.length).toBe(2);
expect(lineItems[0]).toEqual(v2_expectedLineItem0);
expect(lineItems[1]).toEqual(v2_expectedLineItem1);
});
});
});
Loading