-
Notifications
You must be signed in to change notification settings - Fork 29
Fix: parameters in requests #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7d466dd
refactor: change parameter to camelcase
jepser 233286b
fix: camelcased parameter
jepser ab78174
feat: add parameters as part of the url for fetch
jepser 09181cb
fix: send filter parameters to responses
jepser 665ad34
fix: send parameters to forms request
jepser 2c979f0
chore: move method outside the test condition
jepser e12fe9c
test: add coverage to parameters
jepser 03be8e7
docs: update parameters
jepser 69f2832
chore: typos in reference
jepser eded16c
chore: support 0 as value and remove null from values
jepser daf4b3a
refactor: simplify query params
jepser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { buildUrlWithParams } from '../../src/utils' | ||
|
|
||
| test('the url reminds the same if no parameter passed', () => { | ||
| const url = 'http://typeform.com' | ||
| expect(buildUrlWithParams(url)).toBe(url) | ||
| }) | ||
|
|
||
| test('the url has a query string if parameters are passed', () => { | ||
| const url = 'http://typeform.com' | ||
| const params = { | ||
| a: '1', | ||
| b: '2' | ||
| } | ||
| expect(buildUrlWithParams(url, params)).toBe('http://typeform.com?a=1&b=2') | ||
| }) | ||
|
|
||
| test('parameters should be enconded', () => { | ||
| const url = 'http://typeform.com' | ||
| const params = { | ||
| a: '@1', | ||
| b: '#2' | ||
| } | ||
| expect(buildUrlWithParams(url, params)).toBe('http://typeform.com?a=%401&b=%232') | ||
| }) | ||
|
|
||
| test('undefined values for parameter will be skipped', () => { | ||
| const url = 'http://typeform.com' | ||
| const params = { | ||
| a: '@1', | ||
| b: undefined | ||
| } | ||
| expect(buildUrlWithParams(url, params)).toBe('http://typeform.com?a=%401') | ||
| }) | ||
|
|
||
| test('falsy values should be passed', () => { | ||
| const url = 'http://typeform.com' | ||
| const params = { | ||
| a: '0', | ||
| b: 0, | ||
| c: null | ||
| } | ||
| expect(buildUrlWithParams(url, params)).toBe('http://typeform.com?a=0&b=0') | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another approach could be to filter out the falsy values first:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because
filterandmapwill iterate over the values twice, andreducewill do it only once, said that your solution looks more readable and since the parameters won't be more than 10 elements, I will implement your suggestion, thanks :)