Skip to content

Commit

Permalink
feat: don't remove empty string and null of query string value
Browse files Browse the repository at this point in the history
  • Loading branch information
kelp404 committed Jun 16, 2022
1 parent 051dbe5 commit 7f43345
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/route.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Route {
}
`;

exports[`Generate the URI of the route with params 1`] = `"/users/AWgrmJp1SjjuUM2bzZXM/projects?index=0&sort=asc"`;
exports[`Generate the URI of the route with params 1`] = `"/users/AWgrmJp1SjjuUM2bzZXM/projects?array=a&array=b&empty=&index=0&nullValue&sort=asc"`;

exports[`Initial Route with a parent. 1`] = `
Route {
Expand Down
6 changes: 5 additions & 1 deletion __tests__/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test('Get an error on generating a route with a resolve key called "params".', (
test('Generate the URI of the route with params', () => {
const fakeRoute = new Route({
name: 'web',
uri: '/users/{userId:[\\w-]{20}}/projects?index?sort',
uri: '/users/{userId:[\\w-]{20}}/projects?index?sort?nullValue?empty?array?undefinedValue',
resolve: {
user: ({userId}) => Promise.resolve({id: userId, name: 'User'}),
projects: () => Promise.resolve([{id: 'AWgrmJp1SjjuUM2bzZXM', title: 'Project'}]),
Expand All @@ -79,6 +79,10 @@ test('Generate the URI of the route with params', () => {
userId: 'AWgrmJp1SjjuUM2bzZXM',
index: 0,
sort: 'asc',
nullValue: null,
empty: '',
undefinedValue: undefined,
array: ['a', 'b'],
});
expect(uri).toMatchSnapshot();
});
2 changes: 1 addition & 1 deletion lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = class Route {
const value = params[key];
if (uri.indexOf(`{${key}}`) >= 0) {
uri = uri.replace(`{${key}}`, value);
} else if (this.uriParamKeys.indexOf(`?${key}`) >= 0 && (value || value === 0)) {
} else if (this.uriParamKeys.indexOf(`?${key}`) >= 0) {
query[key] = value;
}
});
Expand Down

0 comments on commit 7f43345

Please sign in to comment.