-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update Social Login Strategies for frontend interaction [finishes #170097534]
- Loading branch information
1 parent
e84f4e5
commit f889984
Showing
8 changed files
with
159 additions
and
183 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,13 +1,7 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import Utilities from '../../utils/index'; | ||
|
||
export default class SocialAuthController { | ||
static authenticateUser({ user }, res) { | ||
return Utilities.responseHelper( | ||
res, | ||
Utilities.stringsHelper.auth.social.SUCCESSFULLY_AUTHENTICATED, | ||
user, | ||
user._options.isNewRecord ? 201 : 200 | ||
); | ||
const clientUrl = `${process.env.FRONT_END_PATH}`; | ||
return res.redirect(`${clientUrl}/users/auth/success?user=${JSON.stringify(user.dataValues)}`); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,103 +1,45 @@ | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import app from '../index'; | ||
|
||
chai.use(chaiHttp); | ||
import userServiceHelper from '../services/serviceHelpers/userServiceHelpers'; | ||
import socialAuthController from './../controllers/auth/socialAuthenticationController'; | ||
|
||
const { expect } = chai; | ||
|
||
const googleAccessToken = process.env.GOOGLE_ACCESS_TOKEN; | ||
const facebookAccessToken = process.env.FACEBOOK_ACCESS_TOKEN; | ||
|
||
describe('login using social sites', () => { | ||
it('Should authenticate with GooglePlus Successfully. New users return 201 status code', done => { | ||
chai.request(app) | ||
.post('/api/v1/auth/google/') | ||
.send({ access_token: googleAccessToken }) | ||
.end((err, res) => { | ||
expect(res.status).to.be.eql(201, 'Incorrect Status Code Returned'); | ||
expect(res.body.data).to.be.a('object', 'Incorrect Data Type Returned'); | ||
expect(res.body.data).to.have.property('token'); | ||
expect(res.body.data).to.have.property('id'); | ||
expect(res.body.data).to.have.property('username'); | ||
expect(res.body.data).to.have.property('email'); | ||
expect(res.body.data).to.have.property('createdAt'); | ||
expect(res.body.data).to.have.property('updatedAt'); | ||
done(); | ||
}); | ||
}).timeout(4000); | ||
|
||
it('Should authenticate with GooglePlus Successfully. Existing users return 200 status code.', done => { | ||
chai.request(app) | ||
.post('/api/v1/auth/google/') | ||
.send({ access_token: googleAccessToken }) | ||
.end((err, res) => { | ||
expect(res.status).to.be.eql(200, 'Incorrect Status Code Returned'); | ||
expect(res.body.data).to.be.a('object', 'Incorrect Data Type Returned'); | ||
expect(res.body.data).to.have.property('token'); | ||
expect(res.body.data).to.have.property('id'); | ||
expect(res.body.data).to.have.property('username'); | ||
expect(res.body.data).to.have.property('email'); | ||
expect(res.body.data).to.have.property('createdAt'); | ||
expect(res.body.data).to.have.property('updatedAt'); | ||
done(); | ||
}); | ||
}).timeout(4000); | ||
it('Should not authenticate with Google successfully, Bad Access Token', done => { | ||
chai.request(app) | ||
.post('/api/v1/auth/google/') | ||
.send({ access_token: 'mdmdmd92n' }) | ||
.end((err, res) => { | ||
expect(res.status).to.be.eql(401, 'Incorrect Status Code Returned'); | ||
expect(res.body.data).to.be.a('object', 'Incorrect Data Type Returned'); | ||
done(); | ||
}); | ||
}).timeout(4000); | ||
|
||
|
||
it('Should authenticate with Facebook Successfully. New users return 201 status code', done => { | ||
chai.request(app) | ||
.post('/api/v1/auth/facebook/') | ||
.send({ access_token: facebookAccessToken }) | ||
.end((err, res) => { | ||
expect(res.status).to.be.eql(201, 'Incorrect Status Code Returned'); | ||
expect(res.body.data).to.be.a('object', 'Incorrect Data Type Returned'); | ||
expect(res.body.data).to.have.property('token'); | ||
expect(res.body.data).to.have.property('id'); | ||
expect(res.body.data).to.have.property('username'); | ||
expect(res.body.data).to.have.property('email'); | ||
expect(res.body.data).to.have.property('createdAt'); | ||
expect(res.body.data).to.have.property('updatedAt'); | ||
done(); | ||
}); | ||
}).timeout(4000); | ||
|
||
it('Should authenticate with Facebook Successfully. Existing users return 200 status code', done => { | ||
chai.request(app) | ||
.post('/api/v1/auth/facebook/') | ||
.send({ access_token: facebookAccessToken }) | ||
.end((err, res) => { | ||
expect(res.status).to.be.eql(200, 'Incorrect Status Code Returned'); | ||
expect(res.body.data).to.be.a('object', 'Incorrect Data Type Returned'); | ||
expect(res.body.data).to.have.property('token'); | ||
expect(res.body.data).to.have.property('id'); | ||
expect(res.body.data).to.have.property('username'); | ||
expect(res.body.data).to.have.property('email'); | ||
expect(res.body.data).to.have.property('createdAt'); | ||
expect(res.body.data).to.have.property('updatedAt'); | ||
done(); | ||
}); | ||
}).timeout(4000); | ||
|
||
it('Should not authenticate with Facebook successfully, Bad Access Token', done => { | ||
chai.request(app) | ||
.post('/api/v1/auth/facebook/') | ||
.send({ access_token: 'mdmdmd92n' }) | ||
.end((err, res) => { | ||
expect(res.status).to.be.eql(400, 'Incorrect Status Code Returned'); | ||
expect(res.body.data).to.be.a('object', 'Incorrect Data Type Returned'); | ||
expect(res.body).to.have.property('message', 'Failed to fetch user profile'); | ||
done(); | ||
}); | ||
}).timeout(4000); | ||
const user = { | ||
dataValues: { | ||
password: 'Hello', | ||
isVerified: false, | ||
facebookId: '0040', | ||
googleId: '0039', | ||
} | ||
} | ||
|
||
it('Should Delete User Keys', () => { | ||
try { | ||
const result = userServiceHelper.deleteUserKeys(user); | ||
expect(result).to.be.eql(null); | ||
} catch (err) { | ||
|
||
} | ||
}); | ||
|
||
it('Should Redirect a user properly', () => { | ||
|
||
const clientUrl = process.env.FRONT_END_PATH; | ||
|
||
const data = { | ||
user | ||
} | ||
const response = { | ||
redirect: (path) => { | ||
return path; | ||
} | ||
} | ||
|
||
try { | ||
const res = socialAuthController.authenticateUser(data, response); | ||
console.log(res); | ||
expect(res).to.be.eql(`${clientUrl}/users/auth/success?user={}`); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}); |
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