Skip to content

Commit

Permalink
New test case: sets default value at object attr with undefined value
Browse files Browse the repository at this point in the history
  • Loading branch information
edudavid committed Dec 20, 2018
1 parent f8ff071 commit 21aaa6e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/jsonMapTransform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ test('executes transformation callback for a single object', () => {
expect(convertedJson.categoryCode).toBe(101);
});

test('sets default value at object attrubute', () => {
test('sets default value at object attrubute on unexisting path', () => {
const templateWithDefaultValue = Object.assign({}, template, {
title: {
path: 'unexisting.path',
Expand All @@ -91,6 +91,22 @@ test('sets default value at object attrubute', () => {
expect(convertedJson.title).toBe('This is a default path');
});

test('sets default value at object attrubute with undefined value', () => {
const templateWithDefaultValue = Object.assign({}, template, {
title: {
path: 'name',
default: 'This is a default path'
}
});

const productWIthUndefinedName = Object.assign({}, product1, {
name: undefined
});

const convertedJson = transform(productWIthUndefinedName, templateWithDefaultValue);
expect(convertedJson.title).toBe('This is a default path');
});

test('converts json object based on template with nested path', () => {
const convertedJson = transform(product1, template);

Expand Down

0 comments on commit 21aaa6e

Please sign in to comment.