Skip to content

Commit

Permalink
fix: product attributes not nullable (#1197, #1248)
Browse files Browse the repository at this point in the history
* product.attributes will always return at least an empty Array
  • Loading branch information
DiverDori authored Aug 15, 2022
1 parent e77ee0e commit 90c384c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/app/core/models/product/product.mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ describe('Product Mapper', () => {
expect(p2.attributes).toEqual([{ name: 'Grafikkarte', type: 'String', value: 'NVIDIA Quadro K2200' }]);
});

it('should return an empty array if no attributes available', () => {
const product: Product = productMapper.fromData({
sku: '1',
attributes: undefined,
} as ProductData);
expect(product).toBeTruthy();
expect(product.attributes).toBeEmpty();
});

describe('available', () => {
it.each([
[undefined, undefined, false],
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/models/product/product.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class ProductMapper {
stepOrderQuantity: data.stepOrderQuantity,
packingUnit: data.packingUnit,
availableStock: data.availableStock,
attributes: data.attributeGroups?.PRODUCT_DETAIL_ATTRIBUTES?.attributes || data.attributes,
attributes: data.attributeGroups?.PRODUCT_DETAIL_ATTRIBUTES?.attributes || data.attributes || [],
attributeGroups: data.attributeGroups,
attachments: this.attachmentMapper.fromAttachments(data.attachments),
images: this.imageMapper.fromImages(data.images),
Expand Down

0 comments on commit 90c384c

Please sign in to comment.