-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #432 from opentable/prepare-server-get-component-p…
…arameters prepare-server-get-component-parameters
- Loading branch information
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
function addProperties(source, destination) { | ||
for (var key in source) { | ||
if (source.hasOwnProperty(key) && !destination[key]) { | ||
destination[key] = source[key]; | ||
} | ||
} | ||
} | ||
|
||
// info: use Object.assign() w/ ES6 | ||
module.exports = function (obj1, obj2) { | ||
var obj3 = {}; | ||
addProperties(obj1, obj3); | ||
addProperties(obj2, obj3); | ||
return obj3; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const mergeObjects = require('../../client/src/utils/merge-objects'); | ||
|
||
describe('client : merge-objects :', () => { | ||
const scenarios = [ | ||
{ describe: 'obj1 is empty and obj2 is empty', obj1: {}, obj2: {}, obj3: {} }, | ||
{ describe: 'obj1 is not empty and obj2 is empty', obj1: { p1: 'aaa' }, obj2: {}, obj3: { p1: 'aaa' } }, | ||
{ describe: 'obj1 is empty and obj2 is not empty', obj1: {}, obj2: { p2: 'bbb' }, obj3: { p2: 'bbb' } }, | ||
{ describe: 'obj1 is not empty and obj2 is not empty', obj1: { p1: 'aaa' }, obj2: { p2: 'bbb' }, obj3: { p1: 'aaa', p2: 'bbb' } }, | ||
{ describe: 'obj1 is undefined and obj2 is undefined', obj1: undefined, obj2: undefined, obj3: {} }, | ||
{ describe: 'obj1 is null and obj2 is null', obj1: null, obj2: null, obj3: {} }, | ||
{ describe: 'obj1 and obj2 have a property in common', obj1: { a: 1, b: 2 }, obj2: { b: 3, c: 4 }, obj3: { a: 1, b: 2, c: 4 } } | ||
]; | ||
|
||
scenarios.forEach((scenario) => { | ||
describe(`when ${scenario.describe}`, () => { | ||
it(`then obj3 is equal to ${JSON.stringify(scenario.obj3)}`, () => { | ||
expect(mergeObjects(scenario.obj1, scenario.obj2)).to.deep.equal(scenario.obj3); | ||
}); | ||
}); | ||
}); | ||
}); |