Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Handles requests for specific nested properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
onefrankguy committed May 20, 2016
1 parent 94ab804 commit d3a7c77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/control/v1/conqueso.js
Expand Up @@ -100,7 +100,7 @@ function makeConquesoProperties(properties) {
results = translateConquesoAddresses(results);
results = flatten(results);

return makeJavaProperties(results);
return results;
}

/**
Expand All @@ -113,12 +113,13 @@ function Conqueso(app, storage) {
// Conqueso compatible APIs are defined before the generic catch all route.
app.get('/v1/conqueso/api/roles/:role/properties/:property', (req, res) => {
const property = req.params.property;
const properties = makeConquesoProperties(storage.properties);

res.set('Content-Type', 'text/plain');
res.status(HTTP_OK);

if (property && (property in storage.properties)) {
res.end(String(storage.properties[property]));
if (property && (properties.hasOwnProperty(property))) {
res.end(String(properties[property]));
} else {
res.end();
}
Expand All @@ -137,7 +138,7 @@ function Conqueso(app, storage) {
route.get((req, res) => {
res.set('Content-Type', 'text/plain');
res.status(HTTP_OK);
res.end(makeConquesoProperties(storage.properties));
res.end(makeJavaProperties(makeConquesoProperties(storage.properties)));
});

// Express defaults to using the GET route for HEAD requests.
Expand Down
6 changes: 3 additions & 3 deletions test/conqueso-api-v1.js
Expand Up @@ -150,15 +150,15 @@ describe('Conqueso API v1', () => {

it('retrieves a specific property if it exists', (done) => {
request(server)
.get('/v1/conqueso/api/roles/global/properties/name')
.get('/v1/conqueso/api/roles/global/properties/food.name')
.set('Accept', 'text/plain')
.expect('Content-Type', 'text/plain; charset=utf-8')
.expect(HTTP_OK, 'hipster-mode-enabled', done);
.expect(HTTP_OK, 'tacos', done);
});

it('returns no data if a specific property does not exist', (done) => {
request(server)
.get('/v1/conqueso/api/roles/global/properties/bogus')
.get('/v1/conqueso/api/roles/global/properties/food.gluten')
.set('Accept', 'text/plain')
.expect('Content-Type', 'text/plain; charset=utf-8')
.expect(HTTP_OK, '', done);
Expand Down

0 comments on commit d3a7c77

Please sign in to comment.