Skip to content

Commit

Permalink
Merge pull request #4 from uphold/feature/update-me-with-otp
Browse files Browse the repository at this point in the history
Add otp argument to .updateMe()
  • Loading branch information
ruipenso authored May 24, 2017
2 parents 04d0e11 + 7f3ec20 commit 5bd5854
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/actions/user/update-me.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

Updates the authenticated user's details.

The `otp` argument will add the `OTP-TOKEN` header to the request.

| Argument | Type | Required | Description |
|:----------|:-------|:---------|:---------------------------------------------------------|
| `body` | Object | Yes | Request body |
| `otp` | String | No | OTP token |
| `options` | Object | No | Any options you may want to pass to [`.api()`](/sdk#api) |

The `body` argument accepts the following keys:
Expand Down
15 changes: 12 additions & 3 deletions src/core/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export function getMe(options) {
return this.api('/me', options);
}

export function updateMe({ address, birthdate, country, firstName, identity, lastName, settings, state, username }, options) {
return this.api('/me', merge({
export function updateMe({ address, birthdate, country, firstName, identity, lastName, settings, state, username }, otp, options) {
options = merge({
body: {
address,
birthdate,
Expand All @@ -18,5 +18,14 @@ export function updateMe({ address, birthdate, country, firstName, identity, las
username
},
method: 'patch'
}, options));
}, options);

if (otp) {
options.headers = {
'otp-token': otp,
...options.headers
};
}

return this.api('/me', options);
}
25 changes: 24 additions & 1 deletion test/core/actions/user.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('UserActions', () => {
settings: 'qex',
state: 'qix',
username: 'qox'
}, { fiz: 'faz' })
}, false, { fiz: 'faz' })
.then(result => {
expect(result).toBe('foo');
expect(sdk.api).toBeCalledWith('/me', {
Expand All @@ -49,5 +49,28 @@ describe('UserActions', () => {
});
});
});

it('should make a request to `PATCH /me` with otp', () => {
return sdk.updateMe({
address: 'bar'
}, 'biz', {
headers: {
baz: 'buz'
}
})
.then(result => {
expect(result).toBe('foo');
expect(sdk.api).toBeCalledWith('/me', {
body: {
address: 'bar'
},
headers: {
baz: 'buz',
'otp-token': 'biz'
},
method: 'patch'
});
});
});
});
});

0 comments on commit 5bd5854

Please sign in to comment.