Skip to content

Commit

Permalink
Fixing a regression in hypermedia() regarding pagination - returnin…
Browse files Browse the repository at this point in the history
…g original `or` for `NaN` outputs of `Number()`
  • Loading branch information
avoidwork committed Sep 19, 2019
1 parent 8bab09c commit bb2d327
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ function hypermedia (server, req, rep, headers) {
}

query = req.parsed.searchParams;
page = Number(query.get("page"));
page_size = Number(query.get("page_size"));
page = Number(query.get("page")) || 1;
page_size = Number(query.get("page_size")) || server.config.pageSize || 5;

if (page < 1) {
page = 1;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

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 an HTTP/HTTP2 REST API framework",
"version": "12.0.7",
"version": "12.0.8",
"homepage": "http://avoidwork.github.io/tenso",
"author": "Jason Mulligan <[email protected]>",
"repository": {
Expand Down
13 changes: 13 additions & 0 deletions test/behavior_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ describe("Pagination", function () {
.end();
});

it("GET /items?page=a&page_size=b - returns page 1/3 of an array of numbers", function () {
return tinyhttptest({url: "http://localhost:" + port + "/items?page=a&page_size=b"})
.expectStatus(200)
.expectValue("links", [{"uri": "/", "rel": "collection"}, {
"uri": "/items?page=3&page_size=5",
"rel": "last"
}, {"uri": "/items?page=2&page_size=5", "rel": "next"}])
.expectValue("data", [1, 2, 3, 4, 5])
.expectValue("error", null)
.expectValue("status", 200)
.end();
});

it("GET /items?page=0&page_size=5 - returns page 1/3 of an array of numbers", function () {
return tinyhttptest({url: "http://localhost:" + port + "/items?page=0&page_size=5"})
.expectStatus(200)
Expand Down
13 changes: 13 additions & 0 deletions test/behavior_test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ describe("Pagination (HTTP2)", function () {
.end();
});

it("GET /items?page=a&page_size=b - returns page 1/3 of an array of numbers", function () {
return tinyhttptest({http2: true, url: `https://localhost:${port}/items?page=a&page_size=b`})
.expectStatus(200)
.expectValue("links", [{"uri": "/", "rel": "collection"}, {
"uri": "/items?page=3&page_size=5",
"rel": "last"
}, {"uri": "/items?page=2&page_size=5", "rel": "next"}])
.expectValue("data", [1, 2, 3, 4, 5])
.expectValue("error", null)
.expectValue("status", 200)
.end();
});

it("GET /items?page=0&page_size=5 - returns page 1/3 of an array of numbers", function () {
return tinyhttptest({http2: true, url: `https://localhost:${port}/items?page=0&page_size=5`})
.expectStatus(200)
Expand Down

0 comments on commit bb2d327

Please sign in to comment.