diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index f2166d34e..e1f3ab9c9 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -30,9 +30,9 @@ router.get('/:comment_id', (req, res, next) => { router.get('/action/:action_type', (req, res, next) => { Action.find({'action_type': req.params.action_type, 'item_type': 'comment'}).then((actions) => { - // search all the comments that are in actions by id: item_id - // populate user by user_id - res.status(200).json(actions); + Comment.find({'id': {'$in': actions.map(function(a){return a.item_id;})}}).exec(function(err, comments){ + res.status(200).json(comments); + }); }).catch(error => { next(error); }); diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index 6416d1412..9b43a97c4 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -66,7 +66,7 @@ describe('Get /comments', () => { }); }); -describe('Get moderation queues rejected, pending', () => { +describe('Get moderation queues rejected, pending, flags', () => { const comments = [{ id: 'abc', body: 'comment 10', @@ -95,10 +95,12 @@ describe('Get moderation queues rejected, pending', () => { const actions = [{ action_type: 'flag', - item_id: 'abc' + item_id: 'abc', + item_type: 'comment' }, { action_type: 'like', - item_id: 'hij' + item_id: 'hij', + item_type: 'comment' }]; beforeEach(() => { @@ -132,6 +134,19 @@ describe('Get moderation queues rejected, pending', () => { done(); }); }); + + it('should return all the flagged comments', function(done){ + chai.request(app) + .get('/api/v1/comments/action/flag') + .end(function(err, res){ + expect(res).to.have.status(200); + expect(err).to.be.null; + expect(res.body.length).to.equal(1); + expect(res.body[0]).to.have.property('id'); + expect(res.body[0].id).to.equal('abc'); + done(); + }); + }); }); describe('Post /comments', () => { @@ -196,10 +211,12 @@ describe('Get /:comment_id', () => { const actions = [{ action_type: 'flag', - item_id: 'abc' + item_id: 'abc', + item_type: 'comment' }, { action_type: 'like', - item_id: 'hij' + item_id: 'hij', + item_type: 'comment' }]; beforeEach(() => {