Skip to content

Commit

Permalink
[#164428066] Refactor code from team feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
shaolinmkz committed Mar 12, 2019
1 parent bd35353 commit 5fb0abd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
9 changes: 1 addition & 8 deletions server/controllers/articleComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import host from '../utils/markups';

const {
ArticleComment,
Article,
Bookmark,
User,
Notification,
Expand Down Expand Up @@ -50,15 +49,9 @@ class Comment {
const { username } = req.user;
const { comment } = req.body;
const { slug } = req.params;
const { article } = req;

try {
const article = await Article.findOne({
attributes: ['id', 'title'],
where: {
slug
}
});

const articleId = article.id;
const userComment = await ArticleComment.create({ articleId, comment, userId });

Expand Down
4 changes: 2 additions & 2 deletions server/routes/bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AuthenticateUser, AuthenticateArticle } from '../middlewares';

const bookmarkRoutes = express.Router();

bookmarkRoutes.post('/bookmark/:slug',
bookmarkRoutes.post('/articles/:slug/bookmark',
AuthenticateUser.verifyUser,
AuthenticateArticle.verifyArticle,
BookmarkController.createBookmark);
Expand All @@ -14,7 +14,7 @@ bookmarkRoutes.delete('/articles/:slug/bookmark',
AuthenticateArticle.verifyArticle,
BookmarkController.removeBookmark);

bookmarkRoutes.get('/bookmark',
bookmarkRoutes.get('/articles/bookmarks',
AuthenticateUser.verifyUser,
BookmarkController.getBookmarks);

Expand Down
2 changes: 1 addition & 1 deletion server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import notificationRoutes from './notifications';

const router = express.Router();

router.use(bookmarkRoutes);
router.use(articleRoutes);
router.use(authRoute);
router.use(profileRoutes);
router.use(reportRoutes);
router.use(bookmarkRoutes);
router.use(articleClapRoute);
router.use(articleSearchRoute);
router.use(notificationRoutes);
Expand Down
14 changes: 7 additions & 7 deletions server/test/bookmark.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Test for the bookmark route', () => {
it('It should return 201 if the bookmark is created', (done) => {
chai
.request(app)
.post(`/api/bookmark/${testData[0]}`)
.post(`/api/articles/${testData[0]}/bookmark`)
.set('authorization', `Bearer ${testData[1]}`)
.end((err, res) => {
expect(res.status).to.equal(201);
Expand All @@ -31,7 +31,7 @@ describe('Test for the bookmark route', () => {
it('It should return 400 if you have already bookmarked an article', (done) => {
chai
.request(app)
.post(`/api/bookmark/${testData[0]}`)
.post(`/api/articles/${testData[0]}/bookmark`)
.set('authorization', `Bearer ${testData[1]}`)
.end((err, res) => {
expect(res.status).to.equal(400);
Expand All @@ -44,7 +44,7 @@ describe('Test for the bookmark route', () => {
it('It should return 401 if token is invalid', (done) => {
chai
.request(app)
.post(`/api/bookmark/${testData[0]}`)
.post(`/api/articles/${testData[0]}/bookmark`)
.set('authorization', `Bearer ${invalidUser}`)
.end((err, res) => {
expect(res.status).to.equal(401);
Expand All @@ -56,7 +56,7 @@ describe('Test for the bookmark route', () => {
it('It should return 404 if the article doesn\'t exist', (done) => {
chai
.request(app)
.post(`/api/bookmark/${'this-is-not-in-existence-10000'}`)
.post(`/api/articles/${'this-is-not-in-existence-10000'}/bookmark`)
.set('authorization', `Bearer ${testData[1]}`)
.end((err, res) => {
expect(res.status).to.equal(404);
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('Test for the bookmark route', () => {
it('It should return 401 if token is invalid', (done) => {
chai
.request(app)
.get('/api/bookmark')
.get('/api/articles/bookmarks')
.set('authorization', `Bearer ${invalidUser}`)
.end((err, res) => {
expect(res.status).to.equal(401);
Expand All @@ -107,7 +107,7 @@ describe('Test for the bookmark route', () => {
it('It should return 200 if a has no bookmark', (done) => {
chai
.request(app)
.get('/api/bookmark')
.get('/api/articles/bookmarks')
.set('authorization', `Bearer ${testData[2]}`)
.end((err, res) => {
expect(res.status).to.equal(200);
Expand All @@ -120,7 +120,7 @@ describe('Test for the bookmark route', () => {
it('It should return 200 if the bookmarks are fetched successfully', (done) => {
chai
.request(app)
.get('/api/bookmark')
.get('/api/articles/bookmarks')
.set('authorization', `Bearer ${testData[1]}`)
.end((err, res) => {
expect(res.status).to.equal(200);
Expand Down
2 changes: 1 addition & 1 deletion server/utils/HelperUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const secretKey = process.env.SECRET_KEY;
/**
* @class HelperUtils
* @description Specifies reusable helper methods
* @exports HelperUtils4
* @exports HelperUtils
*/
class HelperUtils {
/**
Expand Down

0 comments on commit 5fb0abd

Please sign in to comment.