Skip to content
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

Global params on POST request #228

Merged
merged 4 commits into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/registry-post-route.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ curl http://my-components-registry.mydomain.com/
}
}]
```

# Payload API

|Parameter|Type|Mandatory|Description|
|---------|----|---------|-----------|
|components|`array of objects`|`yes`|Components to retrieve|
|components[index].name|`string`|`yes`|Component name|
|components[index].version|`string`|`no`|Default latest, the component's version|
|components[index].parameters|`object`|`no`|Component's parameters|
|parameters|`object`|`no`|Global parameters for all components to retrieve. When component has its own parameters, globals will be overwritten|
2 changes: 1 addition & 1 deletion registry/routes/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function(conf, repository){
conf: res.conf,
headers: req.headers,
name: component.name,
parameters: component.parameters,
parameters: _.extend(_.clone(req.body.parameters) || {}, component.parameters || {}),
version: component.version
}, function(result){
callback(null, result);
Expand Down
96 changes: 95 additions & 1 deletion test/acceptance/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ describe('registry', function(){
expect(result.components).to.eql([
'http://localhost:3030/hello-world',
'http://localhost:3030/language',
'http://localhost:3030/no-containers',
'http://localhost:3030/no-containers',
'http://localhost:3030/welcome',
'http://localhost:3030/oc-client'
]);
});
Expand Down Expand Up @@ -304,6 +305,99 @@ describe('registry', function(){
expect(result[1].response.renderMode).to.equal('unrendered');
});
});

describe('when components require params', function(){
describe('when each component requires different params', function(){

before(function(done){
request({
url: 'http://localhost:3030/',
method: 'post',
json: true,
body: {
components: [
{name:'welcome', parameters: { firstName: 'Mickey', lastName: 'Mouse' }},
{name:'welcome', parameters: { firstName: 'Donald', lastName: 'Duck' }}
]
}
}, next(done));
});

it('should render components with expected parameters', function(){
expect(result[0].response.href).to.equal('http://localhost:3030/welcome?firstName=Mickey&lastName=Mouse');
expect(result[1].response.href).to.equal('http://localhost:3030/welcome?firstName=Donald&lastName=Duck');
});
});

describe('when components require same parameters', function(){

before(function(done){
request({
url: 'http://localhost:3030/',
method: 'post',
json: true,
body: {
parameters: { firstName: 'Donald', lastName: 'Duck' },
components: [
{name:'welcome'},
{name:'welcome'}
]
}
}, next(done));
});

it('should render components with expected parameters', function(){
expect(result[0].response.href).to.equal('http://localhost:3030/welcome?firstName=Donald&lastName=Duck');
expect(result[1].response.href).to.equal('http://localhost:3030/welcome?firstName=Donald&lastName=Duck');
});
});

describe('when components have some common parameters and some different', function(){

before(function(done){
request({
url: 'http://localhost:3030/',
method: 'post',
json: true,
body: {
parameters: { firstName: 'Donald' },
components: [
{name:'welcome', parameters: { lastName: 'Mouse' }},
{name:'welcome', parameters: { lastName: 'Duck' }}
]
}
}, next(done));
});

it('should render components with expected parameters', function(){
expect(result[0].response.href).to.equal('http://localhost:3030/welcome?firstName=Donald&lastName=Mouse');
expect(result[1].response.href).to.equal('http://localhost:3030/welcome?firstName=Donald&lastName=Duck');
});
});

describe('when components have global parameters with local overrides', function(){

before(function(done){
request({
url: 'http://localhost:3030/',
method: 'post',
json: true,
body: {
parameters: { firstName: 'Donald', lastName: 'Duck' },
components: [
{name:'welcome', parameters: { lastName: 'Mouse' }},
{name:'welcome'}
]
}
}, next(done));
});

it('should render components with expected parameters', function(){
expect(result[0].response.href).to.equal('http://localhost:3030/welcome?firstName=Donald&lastName=Mouse');
expect(result[1].response.href).to.equal('http://localhost:3030/welcome?firstName=Donald&lastName=Duck');
});
});
});
});
});
});
2 changes: 1 addition & 1 deletion test/fixtures/components/hello-world/_package/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"hello-world","description":"","version":"1.0.0","repository":"","oc":{"files":{"template":{"type":"handlebars","hashKey":"46ee85c314b371cac60471cef5b2e2e6c443dccf","src":"template.js"},"static":[]},"version":"0.26.0","packaged":true,"date":1455211863662}}
{"name":"hello-world","description":"","version":"1.0.0","repository":"","oc":{"files":{"template":{"type":"handlebars","hashKey":"46ee85c314b371cac60471cef5b2e2e6c443dccf","src":"template.js"},"static":[]},"version":"0.29.2","packaged":true,"date":1460061147109}}
2 changes: 1 addition & 1 deletion test/fixtures/components/language/_package/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"language","description":"A test component for testing accept-language interactions","version":"1.0.0","repository":"","oc":{"container":false,"renderInfo":false,"files":{"template":{"type":"jade","hashKey":"b6fd493b37ed12ab8b81c7147dc2feb0e04cb0cc","src":"template.js"},"dataProvider":{"type":"node.js","hashKey":"43c24bb8ea6abc4a311757591b95213679ed48d6","src":"server.js"},"static":[]},"version":"0.26.0","packaged":true,"date":1455211863688}}
{"name":"language","description":"A test component for testing accept-language interactions","version":"1.0.0","repository":"","oc":{"container":false,"renderInfo":false,"files":{"template":{"type":"jade","hashKey":"b6fd493b37ed12ab8b81c7147dc2feb0e04cb0cc","src":"template.js"},"dataProvider":{"type":"node.js","hashKey":"43c24bb8ea6abc4a311757591b95213679ed48d6","src":"server.js"},"static":[]},"version":"0.29.2","packaged":true,"date":1460061147191}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"no-containers","description":"","version":"1.0.0","repository":"","oc":{"container":false,"renderInfo":false,"files":{"template":{"type":"handlebars","hashKey":"46ee85c314b371cac60471cef5b2e2e6c443dccf","src":"template.js"},"static":[]},"version":"0.26.0","packaged":true,"date":1455211863693}}
{"name":"no-containers","description":"","version":"1.0.0","repository":"","oc":{"container":false,"renderInfo":false,"files":{"template":{"type":"handlebars","hashKey":"46ee85c314b371cac60471cef5b2e2e6c443dccf","src":"template.js"},"static":[]},"version":"0.29.2","packaged":true,"date":1460061147199}}
3 changes: 3 additions & 0 deletions test/fixtures/components/welcome/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_package
package.tar.gz
node_modules
1 change: 1 addition & 0 deletions test/fixtures/components/welcome/_package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"welcome","description":"","version":"1.0.0","repository":"","oc":{"files":{"template":{"type":"jade","hashKey":"28144f0dfecc345da2ee82c2614e61d1bd8543a9","src":"template.js"},"dataProvider":{"type":"node.js","hashKey":"b7cda8c12c2e0baf5183ad5fe82ffb34e946fdb5","src":"server.js"},"static":[]},"version":"0.29.2","packaged":true,"date":1460063591401}}
1 change: 1 addition & 0 deletions test/fixtures/components/welcome/_package/server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/components/welcome/_package/template.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/fixtures/components/welcome/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "welcome",
"description": "",
"version": "1.0.0",
"repository": "",
"oc": {
"files": {
"data": "server.js",
"template": {
"src": "template.jade",
"type": "jade"
}
}
}
}
8 changes: 8 additions & 0 deletions test/fixtures/components/welcome/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports.data = function(context, callback){
callback(null, {
firstName: context.params.firstName || 'John',
lastName: context.params.lastName || 'Doe'
});
};
1 change: 1 addition & 0 deletions test/fixtures/components/welcome/template.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
span hi #{firstName} #{lastName}
5 changes: 3 additions & 2 deletions test/unit/registry-domain-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('registry : domain : repository', function(){
'hello-world': ['1.0.0'],
'language': ['1.0.0'],
'no-containers': ['1.0.0'],
'welcome': ['1.0.0'],
'oc-client': ['1.0.0']
}
};
Expand All @@ -80,7 +81,7 @@ describe('registry : domain : repository', function(){
});

it('should list the components', function(){
expect(response.result).to.eql(['hello-world', 'language', 'no-containers', 'oc-client']);
expect(response.result).to.eql(['hello-world', 'language', 'no-containers', 'welcome', 'oc-client']);
});
});

Expand Down Expand Up @@ -251,7 +252,7 @@ describe('registry : domain : repository', function(){
});

it('should list the components', function(){
expect(response.result).to.eql(['hello-world', 'language', 'no-containers', 'oc-client']);
expect(response.result).to.eql(['hello-world', 'language', 'no-containers', 'welcome', 'oc-client']);
});
});

Expand Down