This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1235 from howdyai/069
0.6.9
- Loading branch information
Showing
9 changed files
with
474 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
let teamsBot; | ||
let teamsApi; | ||
let config = { | ||
clientId: 'client', | ||
clientSecret: 'secret', | ||
debug: false | ||
}; | ||
|
||
describe('authentication', () => { | ||
beforeEach(() => { | ||
jest.doMock('../../lib/TeamsAPI', () => { | ||
return jest.fn((configuration) => { | ||
return { | ||
getToken: jest.fn((cb) => { | ||
configuration.token = 'token'; | ||
configuration.token_expires_in = '3600'; | ||
cb(null); | ||
}) | ||
}; | ||
}); | ||
}); | ||
|
||
jest.useFakeTimers(); | ||
teamsApi = require('../../lib/TeamsAPI'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetModules(); | ||
jest.clearAllTimers(); | ||
}); | ||
|
||
test('get token', () => { | ||
let bot = require('../../lib/Teams')(config); | ||
expect(bot.api.getToken).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('refresh token before expiry', () => { | ||
let bot = require('../../lib/Teams')(config); | ||
expect(bot.api.getToken).toHaveBeenCalledTimes(1); | ||
jest.runOnlyPendingTimers(); | ||
expect(bot.api.getToken).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
test('token valid for 20 mins should refresh after 10 mins', () => { | ||
teamsApi.mockImplementation(jest.fn((configuration) => { | ||
return { | ||
getToken: jest.fn((cb) => { | ||
configuration.token = 'token'; | ||
configuration.token_expires_in = '1200'; | ||
cb(null); | ||
}) | ||
}; | ||
})); | ||
let bot = require('../../lib/Teams')(config); | ||
expect(bot.config.token_expires_in).toBe('1200'); | ||
expect(bot.api.getToken).toHaveBeenCalledTimes(1); | ||
jest.runTimersToTime(1000 * 60 * 9); | ||
expect(bot.api.getToken).toHaveBeenCalledTimes(1); | ||
jest.runTimersToTime(1000 * 60 * 1.1); | ||
expect(bot.api.getToken).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.