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

Omit href #227

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
1 change: 1 addition & 0 deletions docs/registry-post-route.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ curl http://my-components-registry.mydomain.com/
|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|
|omitHref|`boolean`|`no`|Default false, when `true` omits the href value in the response of each component|
|parameters|`object`|`no`|Global parameters for all components to retrieve. When component has its own parameters, globals will be overwritten|
9 changes: 4 additions & 5 deletions registry/routes/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ module.exports = function(conf, repository){
}

async.map(components, function(component, callback){
getComponent({
getComponent(_.extend(component, {
conf: res.conf,
headers: req.headers,
name: component.name,
parameters: _.extend(_.clone(req.body.parameters) || {}, component.parameters || {}),
version: component.version
}, function(result){
omitHref: !!req.body.omitHref,
parameters: _.extend(_.clone(req.body.parameters) || {}, component.parameters || {})
}), function(result){
callback(null, result);
});
}, function(err, results){
Expand Down
5 changes: 4 additions & 1 deletion registry/routes/helpers/get-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,17 @@ module.exports = function(conf, repository){
renderMode = isUnrendered ? 'unrendered' : 'rendered';

var response = {
href: componentHref,
type: conf.local ? 'oc-component-local' : 'oc-component',
version: component.version,
requestVersion: requestedComponent.version,
name: requestedComponent.name,
renderMode: renderMode
};

if(!options.omitHref){
response.href = componentHref;
}

retrievingInfo.extend({
href: componentHref,
version: component.version,
Expand Down
51 changes: 50 additions & 1 deletion test/acceptance/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe('registry', function(){
});
});

describe('when body contains two components', function(){
describe('when body contains multiple components', function(){

describe('when Accept header not specified', function(){

Expand Down Expand Up @@ -281,6 +281,55 @@ describe('registry', function(){
});
});

describe('when omitHref=true', function(){
describe('when getting rendered components', function(){

before(function(done){
request({
url: 'http://localhost:3030/',
method: 'post',
json: true,
body: {
omitHref: true,
components: [
{name:'hello-world'},
{name:'no-containers'}
]
}
}, next(done));
});

it('should respond without href parameter', function(){
expect(result[0].response.href).not.to.exist;
expect(result[1].response.href).not.to.exist;
});
});

describe('when getting unrendered components', function(){

before(function(done){
request({
url: 'http://localhost:3030/',
method: 'post',
headers: {'Accept': 'application/vnd.oc.unrendered+json'},
json: true,
body: {
omitHref: true,
components: [
{name:'hello-world'},
{name:'no-containers'}
]
}
}, next(done));
});

it('should respond without href parameter', function(){
expect(result[0].response.href).not.to.exist;
expect(result[1].response.href).not.to.exist;
});
});
});

describe('when Accept header set to application/vnd.oc.unrendered+json', function(){

before(function(done){
Expand Down