Skip to content

Commit 5bd5854

Browse files
authored
Merge pull request #4 from uphold/feature/update-me-with-otp
Add otp argument to .updateMe()
2 parents 04d0e11 + 7f3ec20 commit 5bd5854

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

docs/actions/user/update-me.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
Updates the authenticated user's details.
44

5+
The `otp` argument will add the `OTP-TOKEN` header to the request.
6+
57
| Argument | Type | Required | Description |
68
|:----------|:-------|:---------|:---------------------------------------------------------|
79
| `body` | Object | Yes | Request body |
10+
| `otp` | String | No | OTP token |
811
| `options` | Object | No | Any options you may want to pass to [`.api()`](/sdk#api) |
912

1013
The `body` argument accepts the following keys:

src/core/actions/user.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export function getMe(options) {
44
return this.api('/me', options);
55
}
66

7-
export function updateMe({ address, birthdate, country, firstName, identity, lastName, settings, state, username }, options) {
8-
return this.api('/me', merge({
7+
export function updateMe({ address, birthdate, country, firstName, identity, lastName, settings, state, username }, otp, options) {
8+
options = merge({
99
body: {
1010
address,
1111
birthdate,
@@ -18,5 +18,14 @@ export function updateMe({ address, birthdate, country, firstName, identity, las
1818
username
1919
},
2020
method: 'patch'
21-
}, options));
21+
}, options);
22+
23+
if (otp) {
24+
options.headers = {
25+
'otp-token': otp,
26+
...options.headers
27+
};
28+
}
29+
30+
return this.api('/me', options);
2231
}

test/core/actions/user.spec.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('UserActions', () => {
2929
settings: 'qex',
3030
state: 'qix',
3131
username: 'qox'
32-
}, { fiz: 'faz' })
32+
}, false, { fiz: 'faz' })
3333
.then(result => {
3434
expect(result).toBe('foo');
3535
expect(sdk.api).toBeCalledWith('/me', {
@@ -49,5 +49,28 @@ describe('UserActions', () => {
4949
});
5050
});
5151
});
52+
53+
it('should make a request to `PATCH /me` with otp', () => {
54+
return sdk.updateMe({
55+
address: 'bar'
56+
}, 'biz', {
57+
headers: {
58+
baz: 'buz'
59+
}
60+
})
61+
.then(result => {
62+
expect(result).toBe('foo');
63+
expect(sdk.api).toBeCalledWith('/me', {
64+
body: {
65+
address: 'bar'
66+
},
67+
headers: {
68+
baz: 'buz',
69+
'otp-token': 'biz'
70+
},
71+
method: 'patch'
72+
});
73+
});
74+
});
5275
});
5376
});

0 commit comments

Comments
 (0)