Skip to content

Commit

Permalink
Merge 8d85cc7 into a63faa1
Browse files Browse the repository at this point in the history
  • Loading branch information
aseveryn-hw committed Nov 13, 2019
2 parents a63faa1 + 8d85cc7 commit cbd7a81
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Hyperwallet.js
Expand Up @@ -861,6 +861,26 @@ export default class Hyperwallet {
this.client.doGet(`users/${encodeURIComponent(userToken)}/paypal-accounts`, options, Hyperwallet.handle204Response(callback));
}

/**
* Create PayPal account status transition
*
* @param {string} userToken - The user token
* @param {string} payPalAccountToken - PayPal account token
* @param {Object} data - PayPal account status transition data
* @param {api-callback} callback - The callback for this call
* @throws Will throw an error if userToken or payPalAccountToken is not provided
*/
createPayPalAccountStatusTransition(userToken, payPalAccountToken, data, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
if (!payPalAccountToken) {
throw new Error("payPalAccountToken is required");
}

this.client.doPost(`users/${encodeURIComponent(userToken)}/paypal-accounts/${encodeURIComponent(payPalAccountToken)}/status-transitions`, data, {}, callback);
}

//--------------------------------------
// Bank Accounts
//--------------------------------------
Expand Down
40 changes: 40 additions & 0 deletions test/Hyperwallet.spec.js
Expand Up @@ -1525,6 +1525,46 @@ describe("Hyperwallet", () => {
});
});

/** @test {Hyperwallet#createPayPalAccountStatusTransition} */
describe("createPayPalAccountStatusTransition()", () => {
let client;
let apiClientSpy;

beforeEach(() => {
apiClientSpy = sinon.spy();
client = new Hyperwallet({
username: "test-username",
password: "test-password",
});
client.client = {
doPost: apiClientSpy,
};
});

/** @test {Hyperwallet#createPayPalAccountStatusTransition} */
it("should throw error if userToken is missing", () => {
const callback = () => null;
expect(() => client.createPayPalAccountStatusTransition(undefined, undefined, { test: "value" }, callback)).to.throw("userToken is required");
});

/** @test {Hyperwallet#createPayPalAccountStatusTransition} */
it("should throw error if payPalAccountToken is missing", () => {
const callback = () => null;
expect(() => client.createPayPalAccountStatusTransition("test-user-token", undefined, { test: "value" }, callback)).to.throw("payPalAccountToken is required");
});

/** @test {Hyperwallet#createPayPalAccountStatusTransition} */
it("should send post call to paypal account status transition endpoint", () => {
const callback = () => null;
client.createPayPalAccountStatusTransition("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",
}, {}, callback);
});
});

//--------------------------------------
// Prepaid Cards
//--------------------------------------
Expand Down

0 comments on commit cbd7a81

Please sign in to comment.