3 var app = require('../..');
4 var request = require('supertest');
8 describe('Comment API:', function() {
10 describe('GET /api/comments', function() {
13 beforeEach(function(done) {
17 .expect('Content-Type', /json/)
18 .end(function(err, res) {
27 it('should respond with JSON array', function() {
28 comments.should.be.instanceOf(Array);
33 describe('POST /api/comments', function() {
34 beforeEach(function(done) {
36 .post('/api/comments')
39 info: 'This is the brand new comment!!!'
42 .expect('Content-Type', /json/)
43 .end(function(err, res) {
47 newComment = res.body;
52 it('should respond with the newly created comment', function() {
53 newComment.name.should.equal('New Comment');
54 newComment.info.should.equal('This is the brand new comment!!!');
59 describe('GET /api/comments/:id', function() {
62 beforeEach(function(done) {
64 .get('/api/comments/' + newComment._id)
66 .expect('Content-Type', /json/)
67 .end(function(err, res) {
76 afterEach(function() {
80 it('should respond with the requested comment', function() {
81 comment.name.should.equal('New Comment');
82 comment.info.should.equal('This is the brand new comment!!!');
87 describe('PUT /api/comments/:id', function() {
90 beforeEach(function(done) {
92 .put('/api/comments/' + newComment._id)
94 name: 'Updated Comment',
95 info: 'This is the updated comment!!!'
98 .expect('Content-Type', /json/)
99 .end(function(err, res) {
103 updatedComment = res.body;
108 afterEach(function() {
112 it('should respond with the updated comment', function() {
113 updatedComment.name.should.equal('Updated Comment');
114 updatedComment.info.should.equal('This is the updated comment!!!');
119 describe('DELETE /api/comments/:id', function() {
121 it('should respond with 204 on successful removal', function(done) {
123 .delete('/api/comments/' + newComment._id)
125 .end(function(err, res) {
133 it('should respond with 404 when comment does not exist', function(done) {
135 .delete('/api/comments/' + newComment._id)
137 .end(function(err, res) {