Skip to content

Commit

Permalink
Merge 7be1000 into 52fb59e
Browse files Browse the repository at this point in the history
  • Loading branch information
shaolinmkz committed Apr 16, 2019
2 parents 52fb59e + 7be1000 commit eaa752c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 50 deletions.
27 changes: 8 additions & 19 deletions server/config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ const validateUsername = async (username) => {
* @param {callback} cb - Callback function\
* @returns {method} - A callback function
*/
export const handleSocialLogin = async (email,
firstname,
lastname,
username,
photo,
cb) => {
export const handleSocialLogin = async (email, firstname, lastname, username, photo, cb) => {
try {
const existingUser = await User.findOne({ where: { email } });
return cb(null, {
Expand All @@ -82,7 +77,11 @@ export const handleSocialLogin = async (email,
lastname,
username: username
? await validateUsername(username)
: `${firstname ? await validateUsername(firstname.toLowerCase()) : await validateUsername(email.split('@')[0].split('.')[0])}`,
: `${
firstname
? await validateUsername(firstname.toLowerCase())
: await validateUsername(email.split('@')[0].split('.')[0])
}`,
image: photo
});
return cb(null, { data: user.dataValues });
Expand Down Expand Up @@ -118,12 +117,7 @@ passport.use(new TwitterStrategy({
},
(token, tokenSecret, profile, cb) => {
const { username, emails, photos } = profile;
handleSocialLogin(emails[0].value,
null,
null,
username,
photos[0].value,
cb);
handleSocialLogin(emails[0].value, null, null, username, photos[0].value, cb);
}));

passport.use(new FacebookStrategy({
Expand All @@ -137,12 +131,7 @@ passport.use(new FacebookStrategy({
const splitnames = displayName.split(' ');
const firstname = splitnames[0];
const lastname = splitnames.length > 1 ? splitnames[1] : '';
handleSocialLogin(emails[0].value,
firstname,
lastname,
null,
photos[0].value,
cb);
handleSocialLogin(emails[0].value, firstname, lastname, null, photos[0].value, cb);
}));

export default passport;
5 changes: 0 additions & 5 deletions server/controllers/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,6 @@ class ArticleController {
// Calculate reading time.
const readTime = HelperUtils.estimateReadingTime(article.body);
article.dataValues.readTime = readTime;

// Hide body as body is not needed when fetching all articles.
// You only see the body when viewing a single article.
article.dataValues.body = undefined;

return article;
}),
total: totalArticles,
Expand Down
41 changes: 15 additions & 26 deletions server/test/user.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ describe('Test reset password mail endpoint and password link endpoint', () => {
});
});

it('It should return a 404 if user doesn\'t exist', (done) => {
it("It should return a 404 if user doesn't exist", (done) => {
const data = { newPassword: 'hello2qwerr', confirmPassword: 'hello2qwerr' };
chai
.request(app)
Expand Down Expand Up @@ -442,12 +442,7 @@ describe('Social Login', () => {
expect(active).to.equal(true);
done();
};
handleSocialLogin('thanosxxl@yahoo.com',
null,
null,
null,
null,
mockCb);
handleSocialLogin('thanosxxl@yahoo.com', null, null, null, null, mockCb);
});

it('should generate a serial username if social username is already taken', (done) => {
Expand Down Expand Up @@ -484,12 +479,7 @@ describe('Social Login', () => {
expect(active).to.equal(true);
done();
};
handleSocialLogin('thanosl@yahoo.com',
'tatiana',
'Stormborn',
null,
'hsgdfdg.jpg',
mockCb);
handleSocialLogin('thanosl@yahoo.com', 'tatiana', 'Stormborn', null, 'hsgdfdg.jpg', mockCb);
});

it('should generate a username with email if social network provides no username or firstname', (done) => {
Expand All @@ -504,12 +494,7 @@ describe('Social Login', () => {
expect(active).to.equal(true);
done();
};
handleSocialLogin('thanosxl@yahoo.com',
null,
'Stormborn',
null,
'hsgdfdg.jpg',
mockCb);
handleSocialLogin('thanosxl@yahoo.com', null, 'Stormborn', null, 'hsgdfdg.jpg', mockCb);
});
});

Expand Down Expand Up @@ -719,7 +704,7 @@ describe('Toggle notification', () => {
it('should update my notifications settings', (done) => {
const newSettings = {
emailNotification: false,
inAppNotification: false,
inAppNotification: false
};
chai
.request(app)
Expand All @@ -743,7 +728,7 @@ describe('Toggle notification', () => {
it('should fail if emailNotification is not true or false', (done) => {
const newSettings = {
emailNotification: 'djfhfhf',
inAppNotification: false,
inAppNotification: false
};
chai
.request(app)
Expand All @@ -759,7 +744,7 @@ describe('Toggle notification', () => {
it('should fail if inAppNotification is not true or false', (done) => {
const newSettings = {
emailNotification: true,
inAppNotification: 'nhfhjfj',
inAppNotification: 'nhfhjfj'
};
chai
.request(app)
Expand All @@ -774,7 +759,7 @@ describe('Toggle notification', () => {
});
it('should fail if emailNotification is missing', (done) => {
const newSettings = {
inAppNotification: true,
inAppNotification: true
};
chai
.request(app)
Expand All @@ -789,7 +774,7 @@ describe('Toggle notification', () => {
});
it('should fail if inAppNotification is missing', (done) => {
const newSettings = {
emailNotification: true,
emailNotification: true
};
chai
.request(app)
Expand All @@ -811,7 +796,9 @@ describe('Test wild card route', () => {
.get('/api/reportadmin')
.end((req, res) => {
expect(res.status).to.equal(404);
expect(res.body.message).to.be.a('string').to.equal('Route not found');
expect(res.body.message)
.to.be.a('string')
.to.equal('Route not found');
done();
});
});
Expand All @@ -824,7 +811,9 @@ describe('Test welcome route', () => {
.get('/')
.end((req, res) => {
expect(res.status).to.equal(200);
expect(res.body.message).to.be.a('string').to.equal('Authors Haven.');
expect(res.body.message)
.to.be.a('string')
.to.equal('Authors Haven.');
done();
});
});
Expand Down

0 comments on commit eaa752c

Please sign in to comment.