Add tests for stream. Move to promises the rightway.

This commit is contained in:
gaba
2016-11-04 14:45:46 -07:00
parent 3cff52d72f
commit 43a70ea71c
2 changed files with 27 additions and 6 deletions
+9 -5
View File
@@ -8,16 +8,20 @@ const router = express.Router();
router.get('/', (req, res, next) => {
const comments = Comment.findByAssetId(req.query.asset_id);
const users = User.findByIdArray(comments.map((comment) => comment.author_id));
const actions = Action.findByItemIdArray(comments.map((comment) => comment.id));
const commentsPromise = Comment.findByAssetId(req.query.asset_id);
Promise.all([comments, users, actions]).then(([comments, users, actions]) => {
commentsPromise.then(comments => {
return Promise.all([
comments,
User.findByIdArray(comments.map((comment) => comment.author_id)),
Action.findByItemIdArray(comments.map((comment) => comment.id))
]);
}).then(([comments, users, actions]) => {
res.json([...comments,...users,...actions]);
}).catch(error => {
console.log(error);
next(error);
});
});
module.exports = router;
+18 -1
View File
@@ -1,4 +1,11 @@
require('../../../utils/mongoose');
const app = require('../../../../app');
const chai = require('chai');
const chaiHttp = require('chai-http');
chai.use(chaiHttp);
var expect = chai.expect;
const Action = require('../../../../models/action');
const User = require('../../../../models/user');
const Comment = require('../../../../models/comment');
@@ -44,5 +51,15 @@ describe('api/stream: routes', () => {
})
})
it('should return a stream with comments, users and actions')
it('should return a stream with comments, users and actions', function(done){
chai.request(app)
.get('/api/v1/stream')
.query({'asset_id': 'asset'})
.end(function(err, res){
expect(err).to.be.null;
expect(res).to.have.status(200);
if (err) return done(err);
done();
});
})
})