Skip to content

Commit

Permalink
Add unit test for client.js code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdkoh committed Nov 30, 2016
1 parent 2222ff9 commit 466b5b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = function (dependencies) {
}, notification.headers);

if (this.config.token) {
if (this.config.token.isExpired(this.config.token.current, "3300")) {
if (this.config.token.isExpired(this.config.token.current, 3300)) {
this.config.token.regenerate(this.config.token.generation);
}
headers.authorization = "bearer " + this.config.token.current;
Expand Down
19 changes: 19 additions & 0 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,25 @@ describe("Client", function () {

return expect(client.write(builtNotification(), "adfe5969")).to.eventually.have.property("status", "403");
});

it("regenerate token", function () {
fakes.stream = new FakeStream("abcd1234", "200");
fakes.endpointManager.getStream.onCall(0).returns(fakes.stream);

fakes.token.isExpired = function (current, validSeconds) {
return true;
}

let client = new Client({
address: "testapi",
token: fakes.token
});

return client.write(builtNotification(), "abcd1234")
.then(function () {
expect(fakes.token.generation).to.equal(1);
});
});
});
});
});
Expand Down

0 comments on commit 466b5b1

Please sign in to comment.