From 7f3ec203ffe6ee48e43e86528731def99585cbbe Mon Sep 17 00:00:00 2001 From: Ricardo Gama Date: Wed, 24 May 2017 16:19:53 +0100 Subject: [PATCH] Add otp argument to updateMe --- docs/actions/user/update-me.md | 3 +++ src/core/actions/user.js | 15 ++++++++++++--- test/core/actions/user.spec.js | 25 ++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/docs/actions/user/update-me.md b/docs/actions/user/update-me.md index 9413535..57eeae7 100644 --- a/docs/actions/user/update-me.md +++ b/docs/actions/user/update-me.md @@ -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: diff --git a/src/core/actions/user.js b/src/core/actions/user.js index 44b37bd..26e146a 100644 --- a/src/core/actions/user.js +++ b/src/core/actions/user.js @@ -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, @@ -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); } diff --git a/test/core/actions/user.spec.js b/test/core/actions/user.spec.js index 89b85b3..a7e39b4 100644 --- a/test/core/actions/user.spec.js +++ b/test/core/actions/user.spec.js @@ -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', { @@ -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' + }); + }); + }); }); });