Skip to content

Commit

Permalink
handle missing asset type
Browse files Browse the repository at this point in the history
  • Loading branch information
Fried Hoeben authored and fhoeben committed Jan 15, 2024
1 parent 1bd2ea3 commit c47e5a6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lansweeper/aws/integration-lambda/lansweeper_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class LansweeperHelper {

getProductCategory(asset) {
return this.getByReferenceOrAdd(this.categories,
asset.assetBasicInfo.type,
asset.assetBasicInfo.type || 'Unknown',
(reference, assetType) => {
return {
name: assetType,
Expand Down
37 changes: 37 additions & 0 deletions lansweeper/aws/integration-lambda/tests/lansweeper_helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,44 @@ describe('toReference', () => {
});
});

describe('getProductCategory', () => {
it('handles undefined type', () => {
const asset = {
assetCustom: {},
assetBasicInfo: {name: 'Smart TV'},
};
const productCategory = helper.getProductCategory(asset);

expect(productCategory.reference).toEqual('unknown');
expect(productCategory.name).toEqual('Unknown');
});

it('handles type', () => {
const asset = {
assetCustom: {},
assetBasicInfo: {name: 'Smart TV', type: 'Tv'},
};
const productCategory = helper.getProductCategory(asset);

expect(productCategory.reference).toEqual('tv');
expect(productCategory.name).toEqual('Tv');
});
});


describe('getProduct', () => {
it('handles undefined type', () => {
const asset = {
assetCustom: {},
assetBasicInfo: {name: 'Smart TV'},
};
const product = helper.getProduct(asset);

expect(product.reference).toEqual('unknown_unknown_unknown');
expect(product.model).toEqual('Unknown');
expect(product.brand).toEqual('Unknown');
});

it('handles undefined model and brand', () => {
const asset = {
assetCustom: {},
Expand Down

0 comments on commit c47e5a6

Please sign in to comment.