diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index a884c01e2..7a8202cba 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -8,7 +8,6 @@ const router = express.Router(); //============================================================================== router.param('comment_id', function(res, req, next, comment_id) { - console.log('validations on comment id '); req.comment_id = comment_id; next(); }); @@ -22,8 +21,16 @@ router.get('/', (req, res) => { res.send('Read all of the comments ever'); }); -router.get('/:comment_id', (req, res) => { - res.send('Read a comment'); +router.get('/:comment_id', (req, res, next) => { + Comment.findById(req.params.comment_id, function(err, comment) { + if(err) { + res.status(500); + return next(err); + } + res.status(200); + res.send(comment); + next(); + }); }); router.post('/', (req, res, next) => { diff --git a/tests/models/comment.js b/tests/models/comment.js index 4198f626a..a8a543183 100644 --- a/tests/models/comment.js +++ b/tests/models/comment.js @@ -35,9 +35,13 @@ describe('Comment: models', () => { it('should find an array of comments by asset id', () => { return Comment.findByAssetId('123').then((result) => { expect(result).to.have.length(2); - expect(result.sort()[0]).to.have.property('body') + result.sort((a,b) => { + if (a.body < b.body) {return -1;} + else {return 1;} + }); + expect(result[0]).to.have.property('body') .and.to.equal('comment 10'); - expect(result.sort()[1]).to.have.property('body') + expect(result[1]).to.have.property('body') .and.to.equal('comment 20'); }); }); diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js new file mode 100644 index 000000000..21010d2ab --- /dev/null +++ b/tests/routes/api/comments/index.js @@ -0,0 +1,31 @@ +require('../../../utils/mongoose'); + +const Action = require('../../../../models/action'); +const User = require('../../../../models/user'); + +describe('Post a Comment: /comments', () => { + const users = [{ + id: '123', + display_name: 'John', + },{ + id: '456', + display_name: 'Paul', + }] + + const actions = [{ + action_type: 'flag', + item_id: 'abc' + },{ + action_type: 'like', + item_id: 'hij' + }] + + beforeEach(() => { + return User.create(users).then(() => { + return Action.create(actions) + }) + }) + + it('it should create a comment') + +})