Skip to content

Commit

Permalink
Merge pull request #39 from zebbra/nested-params
Browse files Browse the repository at this point in the history
Support nested objects in query params
  • Loading branch information
icebob committed Apr 24, 2018
2 parents 10bdec9 + 98fdf5d commit 3299c4c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
11 changes: 9 additions & 2 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"lodash": "4.17.5",
"nanomatch": "1.2.9",
"path-to-regexp": "1.7.0",
"qs": "6.5.1",
"serve-static": "1.13.2"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const http = require("http");
const https = require("https");
const queryString = require("querystring");
const queryString = require("qs");
const deprecate = require("depd")("moleculer-web");

const _ = require("lodash");
Expand Down
26 changes: 26 additions & 0 deletions test/integration/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,32 @@ describe("Test aliases", () => {
});
});

it("GET opt-test with array params", () => {
return request(server)
.get("/api/opt-test")
.query("a=1&a=2")
.expect(200)
.expect("Content-Type", "application/json; charset=utf-8")
.then(res => {
expect(res.body.params).toEqual({
a: ["1", "2"],
});
});
});

it("GET opt-test with nested params", () => {
return request(server)
.get("/api/opt-test")
.query("foo[bar]=a&foo[bar]=b&foo[baz]=c")
.expect(200)
.expect("Content-Type", "application/json; charset=utf-8")
.then(res => {
expect(res.body.params).toEqual({
foo: { bar: ["a", "b"], baz: "c" }
});
});
});

it("GET opt-test/:name? without name", () => {
return request(server)
.get("/api/opt-test")
Expand Down

0 comments on commit 3299c4c

Please sign in to comment.