From 3c8f90cc2ff282af1be7ccbc21c8cc31e3409a24 Mon Sep 17 00:00:00 2001 From: aseveryn-epam Date: Tue, 4 Dec 2018 14:44:32 +0200 Subject: [PATCH] Add Get Client Token endpoint --- CHANGELOG.md | 1 + src/Hyperwallet.js | 19 +++++++++++++++++++ test/Hyperwallet.spec.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aab03e..2bcec46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog 0.2.0 (in progress) ------------------- +- Added client token endpoint - Added payment status transition endpoint - Added paper check endpoint - Added bank card endpoint diff --git a/src/Hyperwallet.js b/src/Hyperwallet.js index 0f3a8ca..7fe81f0 100644 --- a/src/Hyperwallet.js +++ b/src/Hyperwallet.js @@ -557,6 +557,25 @@ export default class Hyperwallet { this.client.doGet(`users/${encodeURIComponent(userToken)}/bank-cards/${encodeURIComponent(bankCardToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); } + //-------------------------------------- + // Client Token + //-------------------------------------- + + /** + * Get client token + * + * @param {string} userToken - The user token + * @param {api-callback} callback - The callback for this call + * + * @throws Will throw an error if userToken is not provided + */ + getClientToken(userToken, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + this.client.doPost(`users/${encodeURIComponent(userToken)}/client-token`, {}, {}, callback); + } + //-------------------------------------- // Paper Checks //-------------------------------------- diff --git a/test/Hyperwallet.spec.js b/test/Hyperwallet.spec.js index d9913ad..247ff9e 100644 --- a/test/Hyperwallet.spec.js +++ b/test/Hyperwallet.spec.js @@ -761,6 +761,42 @@ describe("Hyperwallet", () => { }); }); + //-------------------------------------- + // Client Token + //-------------------------------------- + + /** @test {Hyperwallet#getClientToken} */ + describe("getClientToken()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doPost: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#getClientToken} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.getClientToken(undefined, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#getClientToken} */ + it("should do post call to client token endpoint", () => { + const callback = () => null; + client.getClientToken("test-user-token", callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/client-token", {}, {}, callback); + }); + }); + //-------------------------------------- // Paper Checks //--------------------------------------