-
Couldn't load subscription status.
- Fork 22
Add ability to pass extra options on each request #12
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
Conversation
36be370 to
fe8ad94
Compare
| request(url, body, headers = {}, options = {}) { | ||
| const { method = 'get' } = options; | ||
| const requestOptions = { | ||
| ...options, |
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.
Are you destructuring the options object before the declaration of the other properties to prevent anyone from overriding those specific properties?
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.
Yes!
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.
Very well. 👍
| .then(() => { | ||
| expect(sdk.client.request).toBeCalledWith( | ||
| 'https://api.uphold.com/v0/foo', | ||
| 'get', |
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.
Why did we removed the get assert?
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.
The request method is not an argument anymore. It is now provided by the options object.
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.
So, we need to create new tests to cover this scenario.
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.
Added on a different file.
7375b76 to
a08e949
Compare
src/browser/services/fetch-client.js
Outdated
| export default class FetchClient extends Client { | ||
| request(url, method = 'get', body, headers = {}) { | ||
| const options = { | ||
| request(url, body, headers = {}, options = {}) { |
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.
Why did you removed the method and moved it to the options? Shouldn't the option only be an extra parameter to override all the other parameters?
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.
The method is passed to sdk as an option and then we chose to separate it into a different variable. This way and to avoid increase the argument size on this method, I opt to remove it and start using the one on the options object
c4f313d to
dc423ac
Compare
| fetchMock.mock('foo', {}); | ||
|
|
||
| return client.request('foo', 'post', 'bar', { 'Biz-Baz': 'buz' }) | ||
| return client.request('foo', 'get', 'bar', { 'Biz-Baz': 'buz' }) |
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.
Do we need this change?
| undefined, | ||
| { authorization: 'foo' } | ||
| { authorization: 'foo' }, | ||
| { headers: { authorization: 'foo' } } |
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.
According to the test name, this shouldn't be added, right?
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.
The test name was wrong and confusing. Updated.
dc423ac to
a8a2b8a
Compare
|
@SandroMachado updated |
a8a2b8a to
b04e9ea
Compare
b04e9ea to
6c08470
Compare
Description
This PR updates the request client making it to possible to pass additional options on each request
Related issues