From 4605fa624e87c67f4bf800063fa150c62c590d25 Mon Sep 17 00:00:00 2001 From: saraswati Date: Tue, 3 Nov 2020 13:10:06 +0530 Subject: [PATCH] Added get and list methods for PayPal Account Status Transition --- src/Hyperwallet.js | 45 +++++++++++++++- test/Hyperwallet.spec.js | 112 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+), 1 deletion(-) diff --git a/src/Hyperwallet.js b/src/Hyperwallet.js index 0cc82d3..7010d73 100644 --- a/src/Hyperwallet.js +++ b/src/Hyperwallet.js @@ -1042,7 +1042,7 @@ export default class Hyperwallet { * @param {Object} data - The PayPal account data to update * @param {api-callback} callback - The callback for this call * - * @throws Will throw an error if userToken or bankAccountToken is not provided + * @throws Will throw an error if userToken or payPalAccountToken is not provided */ updatePayPalAccount(userToken, payPalAccountToken, data, callback) { if (!userToken) { @@ -1074,6 +1074,49 @@ export default class Hyperwallet { this.client.doPost(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions`, data, {}, callback); } + /** + * Get PayPal account status transition + * + * @param {string} userToken - The user token + * @param {string} payPalAccountToken - PayPal account token + * @param {string} statusTransitionToken - The PayPal account status transition token + * @param {api-callback} callback - The callback for this call + * @throws Will throw an error if userToken or payPalAccountToken or statusTransitionToken is not provided + */ + getPayPalAccountStatusTransition(userToken, payPalAccountToken, statusTransitionToken, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!payPalAccountToken) { + throw new Error("payPalAccountToken is required"); + } + if (!statusTransitionToken) { + throw new Error("statusTransitionToken is required"); + } + this.client.doGet(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions/${encodeURIComponent(statusTransitionToken)}`, + {}, + callback); + } + + /** + * List PayPal account status transition + * + * @param {string} userToken - The user token + * @param {string} payPalAccountToken - PayPal account token + * @param {Object} options - The query parameters to send + * @param {api-callback} callback - The callback for this call + * @throws Will throw an error if userToken or payPalAccountToken is not provided + */ + listPayPalAccountStatusTransitions(userToken, payPalAccountToken, options, callback) { + if (!userToken) { + throw new Error("userToken is required"); + } + if (!payPalAccountToken) { + throw new Error("payPalAccountToken is required"); + } + this.client.doGet(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions`, options, Hyperwallet.handle204Response(callback)); + } + //-------------------------------------- // Bank Accounts //-------------------------------------- diff --git a/test/Hyperwallet.spec.js b/test/Hyperwallet.spec.js index a07d6aa..e0cc403 100644 --- a/test/Hyperwallet.spec.js +++ b/test/Hyperwallet.spec.js @@ -2041,6 +2041,118 @@ describe("Hyperwallet", () => { }); }); + /** @test {Hyperwallet#getPayPalAccountStatusTransition} */ + describe("getPayPalAccountStatusTransition()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doGet: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#getPayPalAccountStatusTransition} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.getPayPalAccountStatusTransition(undefined, undefined, undefined, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#getPayPalAccountStatusTransition} */ + it("should throw error if payPalAccountToken is missing", () => { + const callback = () => null; + expect(() => client.getPayPalAccountStatusTransition("test-user-token", undefined, undefined, callback)).to.throw("payPalAccountToken is required"); + }); + + /** @test {Hyperwallet#getPayPalAccountStatusTransition} */ + it("should throw error if statusTransitionToken is missing", () => { + const callback = () => null; + expect(() => client.getPayPalAccountStatusTransition("test-user-token", "test-paypal-account-token", undefined, callback)).to.throw("statusTransitionToken is required"); + }); + + /** @test {Hyperwallet#getPayPalAccountStatusTransition} */ + it("should do get call if userToken, payPalAccountToken and statusTransitionToken is provided", () => { + const callback = () => null; + client.getPayPalAccountStatusTransition("test-user-token", "test-paypal-account-token", "status-transition-token", callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions/status-transition-token", {}, callback); + }); + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + describe("listPayPalAccountStatusTransitions()", () => { + let client; + let apiClientSpy; + + beforeEach(() => { + apiClientSpy = sinon.spy(); + client = new Hyperwallet({ + username: "test-username", + password: "test-password", + }); + client.client = { + doGet: apiClientSpy, + }; + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + it("should throw error if userToken is missing", () => { + const callback = () => null; + expect(() => client.listPayPalAccountStatusTransitions(undefined, undefined, {}, callback)).to.throw("userToken is required"); + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + it("should throw error if payPalAccountToken is missing", () => { + const callback = () => null; + expect(() => client.listPayPalAccountStatusTransitions("test-user-token", undefined, {}, callback)).to.throw("payPalAccountToken is required"); + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + it("should do get call with options", () => { + const callback = () => null; + client.listPayPalAccountStatusTransitions("test-user-token", "test-paypal-account-token", { test: "value" }, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", { test: "value" }); + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + it("should do get call without options", () => { + const callback = () => null; + client.listPayPalAccountStatusTransitions("test-user-token", "test-paypal-account-token", {}, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", {}); + }); + + /** @test {Hyperwallet#listPayPalAccountStatusTransitions} */ + it("should handle 204 return", (cb) => { + const callback = (err, data) => { + data.should.be.deep.equal({ + hasNextPage: false, + hasPreviousPage: false, + limit: 0, + data: [], + }); + cb(); + }; + client.listPayPalAccountStatusTransitions("test-user-token", "test-paypal-account-token", {}, callback); + + apiClientSpy.should.have.been.calledOnce(); + apiClientSpy.should.have.been.calledWith("users/test-user-token/paypal-accounts/test-paypal-account-token/status-transitions", {}); + + apiClientSpy.getCall(0).args[2](undefined, {}, { + status: 204, + }); + }); + }); + //-------------------------------------- // Prepaid Cards //--------------------------------------