Skip to content

Commit

Permalink
fix(request): ensure falsy request parameters are passed through
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-request

ISSUES CLOSED: #142
  • Loading branch information
jgravois committed Mar 3, 2018
1 parent 4b1544f commit 3c69a10
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}
25 changes: 24 additions & 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
Expand Up @@ -68,7 +68,7 @@
},
"lint-staged": {
"*.ts": [
"prettier --write --parser typescript",
"prettier --write --parser typescript --tab-width 2 --use-tabs false",
"tslint",
"git add"
]
Expand Down
6 changes: 3 additions & 3 deletions packages/arcgis-rest-request/src/utils/process-params.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
* Apache-2.0 */

/**
* Checks parameters to see if we should use FormData to send the request
Expand Down Expand Up @@ -47,7 +47,7 @@ export function processParams(params: any): any {

Object.keys(params).forEach(key => {
const param = params[key];
if (!param) {
if (!param && param !== 0) {
return;
}
const type = param.constructor.name;
Expand Down Expand Up @@ -80,7 +80,7 @@ export function processParams(params: any): any {
value = param;
break;
}
if (value) {
if (value || value === 0) {
newParams[key] = value;
}
});
Expand Down
11 changes: 8 additions & 3 deletions packages/arcgis-rest-request/test/utils/process-params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,18 @@ describe("processParams", () => {
expect(processParams(params)).toEqual(expected);
});

it("should exclude null and undefined", () => {
it("should exclude null and undefined, but not a zero", () => {
const params: any = {
foo: null,
bar: undefined
bar: undefined,
baz: 0
};

expect(processParams(params)).toEqual({});
const expected = {
baz: 0
};

expect(processParams(params)).toEqual(expected);
});

it("should not require form data for simple requests", () => {
Expand Down

0 comments on commit 3c69a10

Please sign in to comment.