Skip to content

Commit

Permalink
Merge branch 'develop' into ft-delete-book-mark-160681804
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielAdek committed Oct 26, 2018
2 parents 88f9e34 + 58db258 commit 4d45bfe
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
22 changes: 12 additions & 10 deletions server/routes/articleRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import auth from '../middleware/auth';
import ratingValidation from '../middleware/ratingValidation';
import inputValidator from '../middleware/inputValidator';
import reportValidation from '../middleware/reportValidation';

import roleValidator from '../middleware/roleValidator';
import checkParams from '../middleware/checkParams';
import { multerUploads } from '../config/multer/multerConfig';
Expand All @@ -27,7 +26,8 @@ const {
createBookmark,
fetchBookmark,
shareArticle,
deleteBookmark
deleteBookmark,
getSingleArticle
} = articleController;

const { addComment, updateComment, updateReply } = commentController;
Expand All @@ -47,6 +47,13 @@ const {
const { validateViolation, validateRequestObject } = reportValidation;
const { isUser } = roleValidator;


articleRoutes.get('/', auth, paginationParamsValidations, getArticles);
articleRoutes.get('/search', searchController);
articleRoutes.get('/popular', getPopularArticlesForTheWeek);
articleRoutes.get('/featured', getFeaturedArticles);
// FEATURED ARTICLE ENDPOINT

// Comment routes
// Add comment
articleRoutes.post(
Expand Down Expand Up @@ -86,16 +93,16 @@ articleRoutes.put(
// Like comment
// POST ARTICLE ROUTE
articleRoutes.get('/', paginationParamsValidations, getArticles);
articleRoutes.post('/:articleId', validArticleId, validateComments, addComment);
articleRoutes.get('/:articleId', auth, checkParams.id, getSingleArticle);
articleRoutes.post('/:articleId', auth, validArticleId, validateComments, addComment);

articleRoutes.post(
'/:articleId/comments/like',
auth,
validateLikeObject,
likeController
);

// POST ARTICLE ROUTE
articleRoutes.get('/', auth, paginationParamsValidations, isUser, getArticles);

// RATE ARTICLE ENDPOINT
articleRoutes.post(
Expand Down Expand Up @@ -137,11 +144,6 @@ articleRoutes.post(
);

// SEARCH ARTICLE ENDPOINT
articleRoutes.get('/search', searchController);

// FEATURED ARTICLE ENDPOINT
articleRoutes.get('/featured', getFeaturedArticles);
articleRoutes.get('/popular', getPopularArticlesForTheWeek);

// CREATE BOOKMARK ROUTE
articleRoutes.post('/bookmarks/add/:articleId', auth, createBookmark);
Expand Down
5 changes: 2 additions & 3 deletions server/routes/tagRoutes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import express from 'express';
import tagController from '../controllers/tagController';
import auth from '../middleware/auth';

const route = express.Router();

// GET TAG ROUTE
route.get('/', auth, tagController.all);
route.get('/:tagName', auth, tagController.single);
route.get('/', tagController.all);
route.get('/:tagName', tagController.single);

export default route;
38 changes: 38 additions & 0 deletions test/articles.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('ARTICLE ENDPOINT TESTS', () => {
.set('authorization', hashedToken)
.set('Content-Type', 'multipart/form-data')
.field('title', 'How I Learnt React in Andela')
.field('categoryId', 1)
.field('description', 'How I Learnt React in Andela, a very descriptive way to introduce an article')
.field('body', 'How I Learnt React in Andela. Now tell us everthing you know about how you learnt reactjs in andela')
.field('categoryId', 2)
Expand All @@ -65,6 +66,7 @@ describe('ARTICLE ENDPOINT TESTS', () => {
.set('Content-Type', 'multipart/form-data')
.attach('image', fs.readFileSync(`${__dirname}/images/test.png`), 'test.png')
.field('title', 'How I Learnt React in Andela')
.field('categoryId', 1)
.field('description', 'How I Learnt React in Andela, a very descriptive way to introduce an article')
.field('body', 'How I Learnt React in Andela. Now tell us everthing you know about how you learnt reactjs in andela')
.type('form')
Expand All @@ -83,6 +85,7 @@ describe('ARTICLE ENDPOINT TESTS', () => {
.set('authorization', 'some43tinvalidtoken324')
.attach('image', fs.readFileSync(`${__dirname}/images/test.png`), 'test.png')
.field('title', 'How I Learnt React in Andela')
.field('categoryId', 1)
.field('description', 'How I Learnt React in Andela, a very descriptive way to introduce an article')
.field('body', 'How I Learnt React in Andela. Now tell us everthing you know about how you learnt reactjs in andela')
.end((err, res) => {
Expand All @@ -101,6 +104,7 @@ describe('ARTICLE ENDPOINT TESTS', () => {
.field('title', '')
.field('description', '')
.field('body', '')
.field('categoryId', 1)
.end((err, res) => {
res.status.should.equal(400);
res.body.data.should.have.property('error');
Expand All @@ -117,6 +121,7 @@ describe('ARTICLE ENDPOINT TESTS', () => {
.set('authorization', hashedToken)
.set('Content-Type', 'multipart/form-data')
.field('description', 'How I Learnt React in Andela, a very descriptive way to introduce an article')
.field('categoryId', 1)
.field('body', 'How I Learnt React in Andela. Now tell us everthing you know about how you learnt reactjs in andela')
.end((err, res) => {
res.status.should.equal(400);
Expand Down Expand Up @@ -645,3 +650,36 @@ describe('FETCH ALL BOOKMARK', () => {
});
});
});

describe('GET SINGLE ARTICLE TEST', () => {
it('should fail when article is not found', (done) => {
chai
.request(app)
.get('/api/v1/articles/1008790')
.set('authorization', hashedToken)
.send()
.end((err, res) => {
expect(res.body.status).to.equal('fail');
expect(res.status).to.equal(404);
expect(res.body.data.message).to.equal('Article not found');
done();
});
});

it('should return successfully when article is found', (done) => {
chai
.request(app)
.get('/api/v1/articles/2')
.set('authorization', hashedToken)
.end((err, res) => {
res.status.should.equal(200);
res.body.status.should.equal('success');
res.body.data.should.have.property('articleData');
res.body.data.should.have.property('metadata');
res.body.data.should.have.property('message');
res.body.data.articleData.should.have.property('body');
res.body.data.articleData.id.should.equal(2);
done();
});
});
});

0 comments on commit 4d45bfe

Please sign in to comment.