Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
confusion around seconds and minutes expiry solved and tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
auberryberry committed Jan 26, 2018
1 parent ad67ab2 commit 521ed91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions __test__/lib/Teams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ describe('authentication', () => {
return {
getToken: jest.fn((cb) => {
configuration.token = 'token';
configuration.token_expires_in = '20';
configuration.token_expires_in = '1200';
cb(null);
})
};
}));
let bot = require('../../lib/Teams')(config);
expect(bot.config.token_expires_in).toBe('20');
expect(bot.config.token_expires_in).toBe('1200');
expect(bot.api.getToken).toHaveBeenCalledTimes(1);
jest.runTimersToTime(1000 * 60 * 11);
jest.runTimersToTime(1000 * 60 * 9);
expect(bot.api.getToken).toHaveBeenCalledTimes(1);
jest.runTimersToTime(1000 * 60 * 1.1);
expect(bot.api.getToken).toHaveBeenCalledTimes(2);
});
});
2 changes: 1 addition & 1 deletion lib/Teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function TeamsBot(configuration) {
throw new Error(err);
}
//use the expires_in value, convert to ms and remove 10 mins in ms
let tokenExpiresIn = 1000 * 60 * (configuration.token_expires_in || 60);
let tokenExpiresIn = (configuration.token_expires_in || 3600) * 1000;
let expiryCheckDelta = 1000 * 60 * 10;
setTimeout(controller.api.getToken, (tokenExpiresIn - expiryCheckDelta), tokenHandler);
};
Expand Down

0 comments on commit 521ed91

Please sign in to comment.