Skip to content

Commit

Permalink
HW-67902-added createUserStatusTransition
Browse files Browse the repository at this point in the history
  • Loading branch information
jkurra-hw committed Oct 6, 2020
1 parent 55086a5 commit 5f39f9b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Hyperwallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ export default class Hyperwallet {
this.client.doGet("users", options, Hyperwallet.handle204Response(callback));
}

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

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

/**
* Get user status transition
*
Expand Down
34 changes: 34 additions & 0 deletions test/Hyperwallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,40 @@ describe("Hyperwallet", () => {
});
});

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

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

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

/** @test {Hyperwallet#createUserStatusTransition} */
it("should send post call to user status transition endpoint", () => {
const callback = () => null;
client.createUserStatusTransition("test-user-token", { test: "value" }, callback);

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

/** @test {Hyperwallet#getUserStatusTransition} */
describe("getUserStatusTransition()", () => {
let client;
Expand Down

0 comments on commit 5f39f9b

Please sign in to comment.