From d911e5b30db562ac04a70ea7a3b23178c7e3acef Mon Sep 17 00:00:00 2001 From: gaba Date: Mon, 7 Nov 2016 13:08:23 -0800 Subject: [PATCH] Improve test. --- routes/api/comments/index.js | 2 +- tests/routes/api/comments/index.js | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index b0458ada7..3acca5b3e 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -27,7 +27,7 @@ router.post('/', (req, res, next) => { const {body, author_id, asset_id, parent_id, status} = req.body; let comment = new Comment({body, author_id, asset_id, parent_id, status}); comment.save().then(({id}) => { - res.status(200).send(id); + res.status(200).send({'id': id}); }).catch(error => { next(error); }); diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index 887ad679d..f55ac98af 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -14,7 +14,7 @@ const Comment = require('../../../../models/comment'); const Action = require('../../../../models/action'); const User = require('../../../../models/user'); -describe('Get /:comment_id', () => { +describe('Get /comments', () => { const comments = [{ id: 'abc', body: 'comment 10', @@ -95,6 +95,7 @@ describe('Post /comments', () => { .send({'body': 'Something body.', 'author_id': '123', 'asset_id': '1', 'parent_id': ''}) .end(function(err, res){ expect(res).to.have.status(200); + expect(res.body).to.have.property('id'); done(); }); }); @@ -148,7 +149,8 @@ describe('Get /:comment_id', () => { .end(function(err, res){ expect(err).to.be.null; expect(res).to.have.status(200); - if (err) {return done(err);} + expect(res.body[0]).to.have.property('body'); + expect(res.body[0].body).to.equal('comment 10'); done(); }); }); @@ -201,7 +203,10 @@ describe('Put /:comment_id', () => { .post('/api/v1/comments/abc') .send({'body': 'Something body.', 'author_id': '123', 'asset_id': '1', 'parent_id': ''}) .end(function(err, res){ + expect(err).to.be.null; expect(res).to.have.status(200); + expect(res.body).to.have.property('body'); + expect(res.body.body).to.equal('Something body.'); done(); }); }); @@ -312,6 +317,8 @@ describe('Post /:comment_id/status', () => { expect(err).to.be.null; expect(res).to.have.status(200); expect(res).to.have.body; + expect(res.body).to.have.property('status'); + expect(res.body.status).to.equal('accepted'); done(); }); }); @@ -369,6 +376,15 @@ describe('Post /:comment_id/actions', () => { .end(function(err, res){ expect(err).to.be.null; expect(res).to.have.status(200); + expect(res).to.have.body; + expect(res.body).to.have.property('item_type'); + expect(res.body.item_type).to.equal('comment'); + expect(res.body).to.have.property('action_type'); + expect(res.body.action_type).to.equal('flag'); + expect(res.body).to.have.property('item_id'); + expect(res.body.item_id).to.equal('abc'); + expect(res.body).to.have.property('user_id'); + expect(res.body.user_id).to.equal('456'); done(); }); });