Skip to content

Commit

Permalink
Updated hypermedia() to apply the same logic to Entity reps, update…
Browse files Browse the repository at this point in the history
…d tests
  • Loading branch information
avoidwork committed Aug 21, 2014
1 parent 088eb57 commit 64fdf66
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 0.5.2
- Updated `hypermedia()` to apply the same logic to Entity reps, updated tests

## 0.5.1
- Changed `data.result` to `null` if all content is lifted into `data.link`, updated tests

Expand Down
2 changes: 1 addition & 1 deletion doc/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ <h5>Returns:</h5>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on 2014-08-21T08:58:16-04:00 using the <a
on 2014-08-21T18:11:24-04:00 using the <a
href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ <h2>License</h2>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on 2014-08-21T08:58:16-04:00 using the <a
on 2014-08-21T18:11:24-04:00 using the <a
href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
Expand Down
4 changes: 2 additions & 2 deletions doc/module-tenso.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h2>
<dt class="tag-version">Version:</dt>
<dd class="tag-version">
<ul class="dummy">
<li>0.5.0</li>
<li>0.5.2</li>
</ul>
</dd>

Expand Down Expand Up @@ -218,7 +218,7 @@ <h2>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on 2014-08-21T08:58:16-04:00 using the <a
on 2014-08-21T18:11:24-04:00 using the <a
href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion doc/modules.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ <h2>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on 2014-08-21T08:58:16-04:00 using the <a
on 2014-08-21T18:11:24-04:00 using the <a
href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
Expand Down
10 changes: 7 additions & 3 deletions lib/tenso.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* @license BSD-3 <https://raw.github.com/avoidwork/tenso/master/LICENSE>
* @link http://avoidwork.github.io/tenso
* @module tenso
* @version 0.5.1
* @version 0.5.2
*/
( function () {
"use strict";

var turtleio = require( "turtle.io" ),
SERVER = "tenso/0.5.1",
SERVER = "tenso/0.5.2",
CONFIG = require( __dirname + "/../config.json" ),
keigai = require( "keigai" ),
util = keigai.util,
Expand Down Expand Up @@ -52,7 +52,7 @@ function Tenso () {
this.rates = {};
this.server = turtleio();
this.server.tenso = this;
this.version = "0.5.1";
this.version = "0.5.2";
}

/**
Expand Down Expand Up @@ -719,6 +719,10 @@ function hypermedia ( server, req, rep, headers ) {
}
}
} );

if ( array.keys( rep.data.result ).length === 0 ) {
rep.data.result = null;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tenso",
"description": "Tensō is a REST API facade for node.js, designed to simplify the implementation of APIs.",
"version": "0.5.1",
"version": "0.5.2",
"homepage": "http://avoidwork.github.io/tenso",
"author": {
"name": "Jason Mulligan",
Expand Down
4 changes: 4 additions & 0 deletions src/hypermedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ function hypermedia ( server, req, rep, headers ) {
}
}
} );

if ( array.keys( rep.data.result ).length === 0 ) {
rep.data.result = null;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports.get = {
"/uuid": function (req, res) {
this.respond( req, res, uuid() );
},
"/somethings/abc": {"something_id": "abc", "user_id": 123, "title": "This is a title", "body": "Where is my body?", "source_url": "http://source.tld"}
"/somethings/abc": {"something_id": "abc", "user_id": 123, "title": "This is a title", "body": "Where is my body?", "source_url": "http://source.tld"},
"/somethings/def": {"user_id": 123, "source_url": "http://source.tld"}
}

module.exports.post = {
Expand Down
18 changes: 17 additions & 1 deletion test/tenso_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ describe("Hypermedia", function () {
tenso( {port: port, routes: routes, logs: {level: "error"}} );

describe("GET /somethings/abc", function () {
it("returns an entity that has hypermedia properties", function (done) {
it("returns an entity that has hypermedia properties, and data", function (done) {
api( port )
.get("/somethings/abc")
.expectStatus(200)
Expand All @@ -235,6 +235,22 @@ describe("Hypermedia", function () {
});
});
});

describe("GET /somethings/def", function () {
it("returns an entity that has hypermedia properties, and no data", function (done) {
api( port )
.get("/somethings/def")
.expectStatus(200)
.expectValue("data.link", [{ uri: "http://localhost:" + port + "/somethings", rel: "collection" }, { uri: "http://localhost:" + port + "/users/123", rel: "related" }, { uri: "http://source.tld", rel: "related" }])
.expectValue("data.result", null)
.expectValue("error", null)
.expectValue("status", 200)
.end(function(err) {
if (err) throw err;
done();
});
});
});
});

describe("Basic Auth", function () {
Expand Down

0 comments on commit 64fdf66

Please sign in to comment.