-
-
Notifications
You must be signed in to change notification settings - Fork 68
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 #89 from MatteoMolinari93/feature/accept_objects_a…
…nd_paths_to_files Feature/accept objects and paths to files
- Loading branch information
Showing
4 changed files
with
82 additions
and
26 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const gmail = require('../gmail'); | ||
const tokenStore = require('../token-store'); | ||
|
||
const { google } = require('googleapis'); | ||
|
||
const fs = require('fs'); | ||
|
||
describe('Gmail', () => { | ||
|
||
it('authorize works with file paths', () => { | ||
const cred_file = '{"installed":{"client_secret":"client_secret","client_id":"client_id","redirect_uris":["redirect_uris"]}}'; | ||
spyOn(fs, 'readFileSync').and.returnValue(Buffer.alloc(cred_file.length, cred_file)); | ||
spyOn(tokenStore, 'get').and.returnValue('tokenfile'); | ||
|
||
const oAuth2Spy = jasmine.createSpyObj('oAuth2', ['setCredentials']) | ||
spyOn(google.auth, 'OAuth2').and.returnValue(oAuth2Spy); | ||
|
||
const result = gmail.authorize('cred_path', 'token_path'); | ||
|
||
expect(fs.readFileSync).toHaveBeenCalledOnceWith('cred_path'); | ||
expect(tokenStore.get).toHaveBeenCalledOnceWith('token_path'); | ||
expect(result).not.toBeNull(); | ||
expect(oAuth2Spy.setCredentials).toHaveBeenCalledOnceWith('tokenfile'); | ||
}); | ||
|
||
it('authorize works with json objects', () => { | ||
const cred_obj = {"installed":{"client_secret":"client_secret","client_id":"client_id","redirect_uris":["redirect_uris"]}}; | ||
spyOn(fs, 'readFileSync'); | ||
spyOn(tokenStore, 'get'); | ||
|
||
const oAuth2Spy = jasmine.createSpyObj('oAuth2', ['setCredentials']) | ||
spyOn(google.auth, 'OAuth2').and.returnValue(oAuth2Spy); | ||
|
||
const result = gmail.authorize(cred_obj, {myObj: true}); | ||
|
||
expect(fs.readFileSync).not.toHaveBeenCalled(); | ||
expect(tokenStore.get).not.toHaveBeenCalled(); | ||
expect(result).not.toBeNull(); | ||
expect(oAuth2Spy.setCredentials).toHaveBeenCalledOnceWith({myObj: true}); | ||
}); | ||
|
||
}); |