Skip to content

Commit

Permalink
rating(refactor) add testing for rating and its pagination
Browse files Browse the repository at this point in the history
[Finishes #167313406]
  • Loading branch information
salviosage committed Aug 29, 2019
1 parent fe0cfec commit b7c1fce
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 125 deletions.
2 changes: 1 addition & 1 deletion src/controllers/rating.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class rateController {
where: { articleSlug }
});
if (count === 0) {
util.setError(404, `Rating for article with slug ${articleSlug} not found`);
util.setError(404, `Article with slug ${articleSlug} not yet Rated`);
return util.send(res);
}
const rating = await RateService.getArticleRatingStatistic(articleSlug);
Expand Down
1 change: 0 additions & 1 deletion src/middlewares/rate.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default async (req, res, next) => {
try {
const ArticleSlug = req.params.articleSlug;
const post = await models.Article.findOne({ where: { slug: ArticleSlug } });

if (!post) {
util.setError(404, 'post not found');
return util.send(res);
Expand Down
6 changes: 4 additions & 2 deletions src/routes/api/rate/rate.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import confirmEmaiAuth from '../../../middlewares/emailVarification.middleware';
import rateController from '../../../controllers/rating.controller';
import sanitizeRate from '../../../middlewares/validators/rate.validation';
import { checkQuery } from '../../../middlewares/query.check';
import rateMiddleware from '../../../middlewares/rate.middleware';
import admin from '../../../middlewares/admin';

const router = express.Router();
router.get('/', checkQuery, rateController.getAllRating);
router.get('/', [validateToken, confirmEmaiAuth, checkQuery, admin], rateController.getAllRating);
router.get('/:articleSlug', checkQuery, [validateToken, confirmEmaiAuth], rateController.getArticleRating);
router.put('/:articleSlug', [validateToken, sanitizeRate, confirmEmaiAuth], rateController.createOrUpdateRate);
router.put('/:articleSlug', [validateToken, sanitizeRate, confirmEmaiAuth, rateMiddleware], rateController.createOrUpdateRate);

export default router;
4 changes: 2 additions & 2 deletions src/routes/api/reports/reports.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const router = express.Router();
// routes for reporting artiles
router.post('/:Article', [auth, confirmEmailAuth, reportValidator, reportMiddleware], reportController.reportArticle);
router.delete('/:reportId', [auth, confirmEmailAuth], reportController.deleteReport);
router.get('/', [auth, confirmEmailAuth], reportController.getMyReport);
router.get('/', [auth, confirmEmailAuth, checkQuery], reportController.getMyReport);
router.get('/all', [auth, confirmEmailAuth, admin, checkQuery], reportController.getAllReport);
router.get('/:Article', [auth, confirmEmailAuth, admin], reportController.getReportsForArticle);
router.get('/:Article', [auth, confirmEmailAuth, admin, checkQuery], reportController.getReportsForArticle);


export default router;
Loading

0 comments on commit b7c1fce

Please sign in to comment.