From a45a5f7296d482028189bdd3cd6253532a05138b Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 21 Nov 2016 12:49:04 -0700 Subject: [PATCH] Updated test to verify middleware is working --- routes/api/comments/index.js | 2 +- tests/routes/api/comments/index.js | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index 1bd77116f..d318857d6 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -42,7 +42,7 @@ router.post('/', wordlist.filter('body'), (req, res, next) => { }) .then((comment) => { - res.status(200).send(comment); + res.status(201).send(comment); }) .catch((err) => { next(err); diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index b8760f3e1..ec9e05d03 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -10,6 +10,7 @@ const expect = chai.expect; chai.should(); chai.use(require('chai-http')); +const wordlist = require('../../../../services/wordlist'); const Comment = require('../../../../models/comment'); const Action = require('../../../../models/action'); const User = require('../../../../models/user'); @@ -184,12 +185,15 @@ describe('Post /comments', () => { beforeEach(() => { return Promise.all([ User.createLocalUsers(users), - Action.create(actions) + Action.create(actions), + wordlist.insert([ + 'bad words' + ]) ]); }); - it('it should create a comment', () => { - chai.request(app) + it('should create a comment', () => { + return chai.request(app) .post('/api/v1/comments') .send({'body': 'Something body.', 'author_id': '123', 'asset_id': '1', 'parent_id': ''}) .then((res) => { @@ -197,6 +201,17 @@ describe('Post /comments', () => { expect(res.body).to.have.property('id'); }); }); + + it('should create a comment with a rejected status if it contains a bad word', () => { + return chai.request(app) + .post('/api/v1/comments') + .send({'body': 'bad words are the baddest', 'author_id': '123', 'asset_id': '1', 'parent_id': ''}) + .then((res) => { + expect(res).to.have.status(201); + expect(res.body).to.have.property('id'); + expect(res.body).to.have.property('status', 'rejected'); + }); + }); }); describe('Get /:comment_id', () => {