-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(socialLogin google):socialLogin using google
setup social Login using passport google [Delivers #167574995]
- Loading branch information
Adekoreday
committed
Aug 7, 2019
1 parent
9401e35
commit 0d2cb3d
Showing
9 changed files
with
157 additions
and
62 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,16 @@ | ||
import passport from 'passport'; | ||
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'; | ||
import passportCallback from '../middlewares/passportCallback'; | ||
|
||
export default () => { | ||
passport.use( | ||
new GoogleStrategy( | ||
{ | ||
clientID: process.env.GOOGLE_CLIENT_ID, | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
callbackURL: process.env.GOOGLE_REDIRECT_URL | ||
}, | ||
passportCallback | ||
) | ||
); | ||
}; |
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,45 @@ | ||
import chai from 'chai'; | ||
import sinon from 'sinon'; | ||
import google from '../../server/helpers/google'; | ||
import Auth from '../../server/controllers/Auth'; | ||
import models from '../../server/database/models/index'; | ||
import PassportError from '../../server/middlewares/passportError'; | ||
import { request2, users } from './__mocks_'; | ||
|
||
const { expect } = chai; | ||
const { User, Session } = models; | ||
describe('google login test', () => { | ||
context('when a valid user want to login with google', () => { | ||
it('logs in such user successfully', async () => { | ||
const res = { status() {}, json() {} }; | ||
const status = sinon.stub(res, 'status').returnsThis(); | ||
const json = sinon.stub(res, 'json').returnsThis(); | ||
const Sessions = sinon.stub(Session, 'create').returns(false); | ||
const findOrCreate = sinon.stub(User, 'findOrCreate').returns(users); | ||
await Auth.socialLogin(request2, res); | ||
sinon.assert.calledOnce(status); | ||
sinon.assert.calledOnce(json); | ||
Sessions.restore(); | ||
findOrCreate.restore(); | ||
}); | ||
}); | ||
context('when a valid user wants to login using google', () => { | ||
it('logs in the user successfully', async () => { | ||
const response = google(); | ||
expect(response).to.equal(undefined); | ||
}); | ||
}); | ||
context('when an invalid user want to login with google', () => { | ||
it('returns json error message', () => { | ||
const Callbacknext = sinon.stub(); | ||
const Callbackrequest = sinon.stub(); | ||
const res = { status() {}, json() {} }; | ||
const status = sinon.stub(res, 'status').returnsThis(); | ||
const json = sinon.stub(res, 'json').returnsThis(); | ||
PassportError.passportErrors(false, Callbackrequest, res, Callbacknext); | ||
sinon.assert.calledOnce(Callbacknext); | ||
sinon.assert.calledOnce(status); | ||
sinon.assert.calledOnce(json); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import * as SocialMocks from './facebookLogin.test'; | ||
import * as facebookTest from './facebook.test'; | ||
import * as googleTest from './google.test'; | ||
|
||
export default SocialMocks; | ||
export { facebookTest, googleTest }; |