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