mirror of
https://github.com/wassname/talk.git
synced 2026-07-01 08:54:37 +08:00
Adds implementation for get all comments
This commit is contained in:
@@ -8,8 +8,12 @@ const router = express.Router();
|
||||
//==============================================================================
|
||||
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.send('Read all of the comments ever');
|
||||
router.get('/', (req, res, next) => {
|
||||
Comment.find({}).then((comments) => {
|
||||
res.status(200).json(comments);
|
||||
}).catch(error => {
|
||||
next(error);
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/:comment_id', (req, res, next) => {
|
||||
|
||||
@@ -13,6 +13,60 @@ const Comment = require('../../../../models/comment');
|
||||
const Action = require('../../../../models/action');
|
||||
const User = require('../../../../models/user');
|
||||
|
||||
|
||||
describe('Get /:comment_id', () => {
|
||||
const comments = [{
|
||||
id: 'abc',
|
||||
body: 'comment 10',
|
||||
asset_id: 'asset',
|
||||
author_id: '123'
|
||||
},{
|
||||
id: 'def',
|
||||
body: 'comment 20',
|
||||
asset_id: 'asset',
|
||||
author_id: '456'
|
||||
},{
|
||||
id: 'hij',
|
||||
body: 'comment 30',
|
||||
asset_id: '456'
|
||||
}]
|
||||
|
||||
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 Comment.create(comments).then(() => {
|
||||
return User.create(users)
|
||||
}).then(() => {
|
||||
return Action.create(actions)
|
||||
})
|
||||
})
|
||||
|
||||
it('should return all the comments', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/comments')
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
if (err) return done(err);
|
||||
done();
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
describe('Post /comments', () => {
|
||||
const users = [{
|
||||
id: '123',
|
||||
|
||||
Reference in New Issue
Block a user