Skip to content

Commit

Permalink
fix: merge product information for lower product completeness levels (#…
Browse files Browse the repository at this point in the history
…1279)

* update product information, add attributes even if the completeness level of the incoming product is lower than the existing one
  • Loading branch information
SGrueber authored Sep 23, 2022
1 parent 856b3f7 commit eec9cda
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/app/core/models/product/product.helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ describe('Product Helper', () => {
} as Product;
stubProduct = {
sku: '110',
longDescription: 'additional info',
completenessLevel: 0,
name: 'Stub Product',
available: false,
Expand Down Expand Up @@ -366,6 +367,7 @@ describe('Product Helper', () => {
Object {
"available": false,
"completenessLevel": 0,
"longDescription": "additional info",
"name": "Stub Product",
"sku": "110",
}
Expand Down Expand Up @@ -402,6 +404,7 @@ describe('Product Helper', () => {
"available": false,
"availableStock": undefined,
"completenessLevel": 3,
"longDescription": "additional info",
"manufacturer": "Detail Manufacturer",
"name": "Detail Product",
"shortDescription": "The best product",
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/models/product/product.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ export class ProductHelper {
if (!product.completenessLevel || newProduct.completenessLevel >= product.completenessLevel) {
return newProduct as AllProductTypes;
}
// if the newProduct information has a lower completeness level merge attributes and
// always update dynamic product information with the new product information (e.g. availability)
product = {
...newProduct,
...product,
// list of product properties that should be updated
available: newProduct.available ?? product.available,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Products Selectors', () => {
store$.dispatch(loadProductSuccess({ product: newProd }));

expect(getProductEntities(store$.state)).toEqual({
[prod.sku]: { ...prod, available: false, availableStock: undefined },
[prod.sku]: { ...prod, available: false, manufacturer: 'Microsoft', availableStock: undefined },
});
});
});
Expand Down

0 comments on commit eec9cda

Please sign in to comment.