Skip to content

Commit

Permalink
Merge pull request #165 from opentable/post-api-change
Browse files Browse the repository at this point in the history
Making the POST response API return status and response for each comp…
  • Loading branch information
jankowiakmaria committed Jan 14, 2016
2 parents 75e6310 + ce5c199 commit f19dcfa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
34 changes: 20 additions & 14 deletions docs/registry-post-route.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ curl http://my-components-registry.mydomain.com/
-d '{components:[{"name": hello-world", "version": "1.X.X"}, {"name": "my-component", "parameters": { "something": 2345 }}]}'

[{
"href": "https://my-components-registry.mydomain.com/hello-world/1.X.X",
"name": "hello-world",
"version": "1.0.0",
"requestVersion": "1.X.X",
"html": "Hello John doe!",
"type": "oc-component",
"renderMode": "rendered"
"status": 200,
"response": {
"href": "https://my-components-registry.mydomain.com/hello-world/1.X.X",
"name": "hello-world",
"version": "1.0.0",
"requestVersion": "1.X.X",
"html": "Hello John doe!",
"type": "oc-component",
"renderMode": "rendered"
}
},{
"href": "https://my-components-registry.mydomain.com/my-component/?something=2345",
"name": "my-component",
"version": "1.0.0",
"requestVersion": "",
"html": "Bla bla",
"type": "oc-component",
"renderMode": "rendered"
"status": 200,
"response": {
"href": "https://my-components-registry.mydomain.com/my-component/?something=2345",
"name": "my-component",
"version": "1.0.0",
"requestVersion": "",
"html": "Bla bla",
"type": "oc-component",
"renderMode": "rendered"
}
}]
```
2 changes: 1 addition & 1 deletion registry/routes/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = function(conf, repository){
parameters: component.parameters,
version: component.version
}, function(result){
callback(null, result.response);
callback(null, result);
});
}, function(err, results){
return res.json(200, results);
Expand Down
21 changes: 13 additions & 8 deletions test/acceptance/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,16 @@ describe('registry', function(){
});
});

it('should respond with two 200 status codes', function(){
expect(result[0].status).to.equal(200);
expect(result[1].status).to.equal(200);
});

it('should respond with two rendered components', function() {
expect(result[0].html).to.match(/<oc-component (.*?)>Hello world!<script>(.*?)<\/script><\/oc-component>/g);
expect(result[0].renderMode).to.equal('rendered');
expect(result[1].html).to.equal('Hello world!');
expect(result[1].renderMode).to.equal('rendered');
expect(result[0].response.html).to.match(/<oc-component (.*?)>Hello world!<script>(.*?)<\/script><\/oc-component>/g);
expect(result[0].response.renderMode).to.equal('rendered');
expect(result[1].response.html).to.equal('Hello world!');
expect(result[1].response.renderMode).to.equal('rendered');
});
});

Expand Down Expand Up @@ -250,10 +255,10 @@ describe('registry', function(){
});

it('should respond with two unrendered components', function() {
expect(result[0].template).to.exist;
expect(result[0].renderMode).to.equal('unrendered');
expect(result[1].template).to.exist;
expect(result[1].renderMode).to.equal('unrendered');
expect(result[0].response.template).to.exist;
expect(result[0].response.renderMode).to.equal('unrendered');
expect(result[1].response.template).to.exist;
expect(result[1].response.renderMode).to.equal('unrendered');
});
});
});
Expand Down
18 changes: 13 additions & 5 deletions test/unit/registry-routes-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,25 @@ describe('registry : routes : components', function(){
});

it('should return a response containing components in the correct order', function(){
expect(response[0].href).to.be.undefined;
expect(response[1].href).to.be.equal('http://components.com/async-error2-component/1.0.0');
expect(response[0].response.href).to.be.undefined;
expect(response[1].response.href).to.be.equal('http://components.com/async-error2-component/1.0.0');
});

it('should return a response with error code and description for first component', function(){
expect(response[0].code).to.be.equal('GENERIC_ERROR');
expect(response[0].error).to.be.equal('Component execution error: thisDoesnotExist is not defined');
expect(response[0].response.code).to.be.equal('GENERIC_ERROR');
expect(response[0].response.error).to.be.equal('Component execution error: thisDoesnotExist is not defined');
});

it('should return a response with rendered html for second component', function(){
expect(response[1].html).to.be.equal('<div>hello</div>');
expect(response[1].response.html).to.be.equal('<div>hello</div>');
});

it('should include 500 status code for first component', function(){
expect(response[0].status).to.equal(500);
});

it('should include 200 status code for second component', function(){
expect(response[1].status).to.equal(200);
});
});

Expand Down

0 comments on commit f19dcfa

Please sign in to comment.