Skip to content

Commit

Permalink
transfer methods added
Browse files Browse the repository at this point in the history
  • Loading branch information
mgovindhasamy committed Nov 2, 2020
1 parent 37dec47 commit 5e68e6d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Hyperwallet.js
Expand Up @@ -1980,4 +1980,19 @@ export default class Hyperwallet {
}
this.client.doPutMultipart(`users/${encodeURIComponent(userToken)}/business-stakeholders/${encodeURIComponent(stakeholderToken)}`, data, callback);
}

/**
* List of Transfer Methods
*
* @param {string} userToken - The user 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 is not provided
*/
listTransferMethods(userToken, options, callback) {
if (!userToken) {
throw new Error("userToken is required");
}
this.client.doGet(`users/${encodeURIComponent(userToken)}/transfer-methods`, options, Hyperwallet.handle204Response(callback));
}
}
63 changes: 63 additions & 0 deletions test/Hyperwallet.spec.js
Expand Up @@ -4753,4 +4753,67 @@ describe("Hyperwallet", () => {
apiClientSpy.should.have.been.calledOnce();
});
});

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

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

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

/** @test {Hyperwallet#listTransferMethods} */
it("should do get call with options", () => {
const callback = () => null;
client.listTransferMethods("test-user-token", { test: "value" }, callback);

apiClientSpy.should.have.been.calledOnce();
apiClientSpy.should.have.been.calledWith("users/test-user-token/transfer-methods", { test: "value" });
});

/** @test {Hyperwallet#listTransferMethods} */
it("should do get call without options", () => {
const callback = () => null;
client.listTransferMethods("test-user-token", {}, callback);

apiClientSpy.should.have.been.calledOnce();
apiClientSpy.should.have.been.calledWith("users/test-user-token/transfer-methods", {});
});

/** @test {Hyperwallet#listTransferMethods} */
it("should handle 204 return", (cb) => {
const callback = (err, data) => {
data.should.be.deep.equal({
hasNextPage: false,
hasPreviousPage: false,
limit: 0,
data: [],
});

cb();
};
client.listTransferMethods("test-user-token", {}, callback);

apiClientSpy.should.have.been.calledOnce();
apiClientSpy.should.have.been.calledWith("users/test-user-token/transfer-methods", {});

apiClientSpy.getCall(0).args[2](undefined, {}, {
status: 204,
});
});
});
});

0 comments on commit 5e68e6d

Please sign in to comment.