Skip to content

Commit

Permalink
Merge e6879b1 into 7ab8953
Browse files Browse the repository at this point in the history
  • Loading branch information
AnayoOleru committed May 9, 2019
2 parents 7ab8953 + e6879b1 commit 0aaa8aa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 61 deletions.
8 changes: 1 addition & 7 deletions server/controllers/article.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,7 @@ const getUserArticles = async (req, res) => {
is_reported: false,
},
});
if (findMyArticles.length === 0) {
return res.status(404).json({
errors: {
body: ['You have not written any article on this platform'],
},
});
}

return res.status(200).json({
message: 'You have successfully retrieved your articles',
articles: findMyArticles,
Expand Down
20 changes: 15 additions & 5 deletions server/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const verifyEmail = async (req, res) => {

const socialCallback = async (accessToken, refreshToken, profile, done) => {
try {
const { id, displayName, emails, provider, photos } = profile;
const { id, displayName, emails, provider } = profile;

if (!emails) {
const userWithNoEmail = { noEmail: true };
Expand All @@ -166,7 +166,6 @@ const socialCallback = async (accessToken, refreshToken, profile, done) => {

const userEmail = emails[0].value;
const names = displayName.split(' ');
const profileImage = photos[0].value;

const [user] = await User.findOrCreate({
where: { email: userEmail },
Expand All @@ -176,7 +175,6 @@ const socialCallback = async (accessToken, refreshToken, profile, done) => {
password: id,
email: userEmail,
social: provider,
image_url: profileImage,
},
});

Expand All @@ -197,8 +195,20 @@ const socialRedirect = async (req, res) => {
return res.redirect(`${process.env.FRONTEND_URL}/auth/social?error=${400}`);
}

const { id, email } = req.user;
const token = await authHelper.encode({ id, email });
const {
id,
email,
is_admin: isAdmin,
is_reviewer: isReviewer,
is_activated: isActivated,
} = req.user;
const token = await authHelper.encode({
id,
email,
isAdmin,
isReviewer,
isActivated,
});
return res.redirect(`${process.env.FRONTEND_URL}/auth/social?${token}`);
};

Expand Down
8 changes: 1 addition & 7 deletions server/controllers/bookmark.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ const getBookMarkedArticlesForUser = async (req, res) => {
],
});

// check if the user hasn't bookmarked any article yet
if (!bookmarkedArticles.length) {
return res.status(201).json({
message: "You haven't bookmarked any article yet",
});
}
return res.status(201).json({
return res.status(200).json({
message: 'Articles you bookmarked',
data: bookmarkedArticles,
});
Expand Down
13 changes: 0 additions & 13 deletions tests/article.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,6 @@ describe('ARTICLE', () => {
done();
});
});
it('should respond with error: you have not written any article on this platform', done => {
chai
.request(app)
.get('/api/v1/myArticles')
.set('Authorization', userCToken)
.end((err, res) => {
expect(res).to.have.status(404);
expect(res.body.errors.body[0]).to.equal(
'You have not written any article on this platform'
);
done();
});
});
it('should return this user articles', done => {
chai
.request(app)
Expand Down
30 changes: 1 addition & 29 deletions tests/user-get-bookmark.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,8 @@ import app from '../server/app';

chai.use(chaiHttp);

let userBToken;
let userCToken;

before('login user', done => {
chai
.request(app)
.post('/api/v1/auth/login')
.send({
email: 'adesojitest22@gmail.com',
password: '12345678',
})
.end((err, res) => {
userBToken = res.body.user.token;
done();
});
});

before('login user', done => {
chai
.request(app)
Expand Down Expand Up @@ -65,26 +50,13 @@ describe('Check if payload exist and if payload is incorrect', () => {

// controller test
describe('GET articles authors had bookmarked', () => {
it("should respond with 201 when the user hasn't bookmarked any article yet", done => {
chai
.request(app)
.get('/api/v1/bookmarks')
.set('Authorization', userBToken)
.end((err, res) => {
expect(res).to.have.status(201);
expect(res.body.message).to.be.equal(
"You haven't bookmarked any article yet"
);
done();
});
});
it('should respond with 201 with the articles, when the user have bookmarked articles', done => {
chai
.request(app)
.get('/api/v1/bookmarks')
.set('Authorization', userCToken)
.end((err, res) => {
expect(res).to.have.status(201);
expect(res).to.have.status(200);
expect(res.body.message).to.be.equal('Articles you bookmarked');
expect(res.body).to.be.an('object');
expect(res.body.data).to.be.an('array');
Expand Down

0 comments on commit 0aaa8aa

Please sign in to comment.