From 7bd32fa21ffebbacc639b96ec165d50945fa6e8e Mon Sep 17 00:00:00 2001 From: Adesoji Daniel Date: Thu, 9 May 2019 14:36:05 +0100 Subject: [PATCH 1/6] chore(profile): update my article controller --- server/controllers/article.controllers.js | 8 +------- tests/article.test.js | 13 ------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/server/controllers/article.controllers.js b/server/controllers/article.controllers.js index 5ab3de9..c3ba732 100644 --- a/server/controllers/article.controllers.js +++ b/server/controllers/article.controllers.js @@ -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, diff --git a/tests/article.test.js b/tests/article.test.js index 72d07fe..fd22273 100644 --- a/tests/article.test.js +++ b/tests/article.test.js @@ -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) From 15c1adfc1b81ea6bb45a4a3a787f125afec92b1c Mon Sep 17 00:00:00 2001 From: Adesoji Daniel Date: Thu, 9 May 2019 16:36:10 +0100 Subject: [PATCH 2/6] chore(bookmark): update bookmark controller --- server/controllers/bookmark.controller.js | 6 ------ tests/user-get-bookmark.test.js | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/server/controllers/bookmark.controller.js b/server/controllers/bookmark.controller.js index 7ae4fe0..434ea95 100644 --- a/server/controllers/bookmark.controller.js +++ b/server/controllers/bookmark.controller.js @@ -83,12 +83,6 @@ 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({ message: 'Articles you bookmarked', data: bookmarkedArticles, diff --git a/tests/user-get-bookmark.test.js b/tests/user-get-bookmark.test.js index a80edb6..785302f 100644 --- a/tests/user-get-bookmark.test.js +++ b/tests/user-get-bookmark.test.js @@ -84,7 +84,7 @@ describe('GET articles authors had bookmarked', () => { .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'); From 0c92bb663aae47fd5220150674535f4b3429f3b3 Mon Sep 17 00:00:00 2001 From: Adesoji Daniel Date: Thu, 9 May 2019 16:37:38 +0100 Subject: [PATCH 3/6] chore(bookmark): update bookmark controller --- server/controllers/bookmark.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controllers/bookmark.controller.js b/server/controllers/bookmark.controller.js index 434ea95..5b4b92e 100644 --- a/server/controllers/bookmark.controller.js +++ b/server/controllers/bookmark.controller.js @@ -83,7 +83,7 @@ const getBookMarkedArticlesForUser = async (req, res) => { ], }); - return res.status(201).json({ + return res.status(200).json({ message: 'Articles you bookmarked', data: bookmarkedArticles, }); From 55ca7e340dfce5d95a50c169afe5129824ac0942 Mon Sep 17 00:00:00 2001 From: Adesoji Daniel Date: Thu, 9 May 2019 16:49:20 +0100 Subject: [PATCH 4/6] chore(profile): update test cases --- tests/user-get-bookmark.test.js | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/tests/user-get-bookmark.test.js b/tests/user-get-bookmark.test.js index 785302f..b545983 100644 --- a/tests/user-get-bookmark.test.js +++ b/tests/user-get-bookmark.test.js @@ -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) @@ -65,19 +50,6 @@ 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) From 8d0f18cc17a00c253685d36aae36a3042d8f1608 Mon Sep 17 00:00:00 2001 From: Adesoji Daniel Date: Thu, 9 May 2019 17:22:44 +0100 Subject: [PATCH 5/6] chore(social): update social encoding --- server/controllers/auth.controller.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/server/controllers/auth.controller.js b/server/controllers/auth.controller.js index ca0b5c8..22638bf 100644 --- a/server/controllers/auth.controller.js +++ b/server/controllers/auth.controller.js @@ -197,8 +197,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}`); }; From e6dcef30336bc8d458dcb3379867bcddad1541fa Mon Sep 17 00:00:00 2001 From: Adesoji Daniel Date: Thu, 9 May 2019 17:27:06 +0100 Subject: [PATCH 6/6] chore(social): update socila login --- server/controllers/auth.controller.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/controllers/auth.controller.js b/server/controllers/auth.controller.js index 22638bf..130029a 100644 --- a/server/controllers/auth.controller.js +++ b/server/controllers/auth.controller.js @@ -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 }; @@ -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 }, @@ -176,7 +175,6 @@ const socialCallback = async (accessToken, refreshToken, profile, done) => { password: id, email: userEmail, social: provider, - image_url: profileImage, }, });