Get comment

This commit is contained in:
gaba
2016-11-04 10:51:17 -07:00
3 changed files with 47 additions and 5 deletions
+10 -3
View File
@@ -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) => {
+6 -2
View File
@@ -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');
});
});
+31
View File
@@ -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')
})