-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prepare-server-get-component-parameters #432
Changes from 9 commits
200e65b
3d5df1b
6b244e1
d45c760
e3aefc1
c6f48be
7ea328c
a36f255
13b91a8
db3cb1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,5 +59,27 @@ describe('client : href-builder :', () => { | |
.to.equal('http://localhost:3030/hello-world/1.0.0/?p1=v1&p2=v%202'); | ||
}); | ||
}); | ||
|
||
describe('when there are parameters in both "options" and "component"', () => { | ||
it('it should return a valid request for the component with the parameters set as URL query params', () => { | ||
let options = { parameters: { p1: 'v1', p2: 'v 2' } }; | ||
let component = { name: 'hello-world', version: '1.0.0', parameters: { message: 'hello' } }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we include a common parameter to ensure our merge goes in the right way, such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is covered at the |
||
let hrefBuilder = new hrefBuilderPrototype({}); | ||
|
||
expect(hrefBuilder.prepareServerGet('http://localhost:3030', component, options)) | ||
.to.equal('http://localhost:3030/hello-world/1.0.0/?message=hello&p1=v1&p2=v%202'); | ||
}); | ||
}); | ||
|
||
describe('when there are common parameters in both "options" and "component"', () => { | ||
it('it should return a valid request for the component with the parameters set as URL query params', () => { | ||
let options = { parameters: { p1: 'v1', p2: 'v 2' } }; | ||
let component = { name: 'hello-world', version: '1.0.0', parameters: { message: 'hello', p1: 'v3' } }; | ||
let hrefBuilder = new hrefBuilderPrototype({}); | ||
|
||
expect(hrefBuilder.prepareServerGet('http://localhost:3030', component, options)) | ||
.to.equal('http://localhost:3030/hello-world/1.0.0/?message=hello&p1=v3&p2=v%202'); | ||
}); | ||
}); | ||
}); | ||
}); |
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/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); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about using _.extend instead of mergeObjects. We use it a lot everywhere so it would be more consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about that but looking at the package.json I couldn't see
lodash
as a dependency (https://github.com/opentable/oc/blob/master/client/package.json#L17-L21) also in ES6 this will be part of the language so I preferred not to add a dependency and go "vanilla". plus the component is a standalone one (and fully tested) so we can always swap its internal implementation.