Skip to content

Conversation

@pgom
Copy link
Contributor

@pgom pgom commented Mar 19, 2018

Description

This PR updates the request client making it to possible to pass additional options on each request

Related issues

@pgom pgom force-pushed the enhancement/request-options branch from 36be370 to fe8ad94 Compare March 19, 2018 16:09
request(url, body, headers = {}, options = {}) {
const { method = 'get' } = options;
const requestOptions = {
...options,
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

Copy link
Contributor

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',
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@pgom pgom requested a review from d-moreira March 22, 2018 18:06
@pgom pgom force-pushed the enhancement/request-options branch 2 times, most recently from 7375b76 to a08e949 Compare March 23, 2018 16:44
export default class FetchClient extends Client {
request(url, method = 'get', body, headers = {}) {
const options = {
request(url, body, headers = {}, options = {}) {
Copy link
Contributor

@SandroMachado SandroMachado Apr 5, 2018

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?

Copy link
Contributor Author

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

@pgom pgom force-pushed the enhancement/request-options branch 4 times, most recently from c4f313d to dc423ac Compare April 6, 2018 13:28
fetchMock.mock('foo', {});

return client.request('foo', 'post', 'bar', { 'Biz-Baz': 'buz' })
return client.request('foo', 'get', 'bar', { 'Biz-Baz': 'buz' })
Copy link
Contributor

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' } }
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@pgom pgom force-pushed the enhancement/request-options branch from dc423ac to a8a2b8a Compare April 6, 2018 14:30
@pgom
Copy link
Contributor Author

pgom commented Apr 9, 2018

@SandroMachado updated

@pgom pgom force-pushed the enhancement/request-options branch from a8a2b8a to b04e9ea Compare April 10, 2018 11:17
@pgom pgom force-pushed the enhancement/request-options branch from b04e9ea to 6c08470 Compare April 13, 2018 17:44
@SandroMachado SandroMachado merged commit c1f3623 into master Apr 13, 2018
@SandroMachado SandroMachado deleted the enhancement/request-options branch April 13, 2018 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants