TwoToc code
[YouAndWeb_TwoToc] / server / api / show / show.integration.js
1 'use strict';
2
3 var app = require('../..');
4 var request = require('supertest');
5
6 var newShow;
7
8 describe('Show API:', function() {
9
10   describe('GET /api/shows', function() {
11     var shows;
12
13     beforeEach(function(done) {
14       request(app)
15         .get('/api/shows')
16         .expect(200)
17         .expect('Content-Type', /json/)
18         .end(function(err, res) {
19           if (err) {
20             return done(err);
21           }
22           shows = res.body;
23           done();
24         });
25     });
26
27     it('should respond with JSON array', function() {
28       shows.should.be.instanceOf(Array);
29     });
30
31   });
32
33   describe('POST /api/shows', function() {
34     beforeEach(function(done) {
35       request(app)
36         .post('/api/shows')
37         .send({
38           name: 'New Show',
39           info: 'This is the brand new show!!!'
40         })
41         .expect(201)
42         .expect('Content-Type', /json/)
43         .end(function(err, res) {
44           if (err) {
45             return done(err);
46           }
47           newShow = res.body;
48           done();
49         });
50     });
51
52     it('should respond with the newly created show', function() {
53       newShow.name.should.equal('New Show');
54       newShow.info.should.equal('This is the brand new show!!!');
55     });
56
57   });
58
59   describe('GET /api/shows/:id', function() {
60     var show;
61
62     beforeEach(function(done) {
63       request(app)
64         .get('/api/shows/' + newShow._id)
65         .expect(200)
66         .expect('Content-Type', /json/)
67         .end(function(err, res) {
68           if (err) {
69             return done(err);
70           }
71           show = res.body;
72           done();
73         });
74     });
75
76     afterEach(function() {
77       show = {};
78     });
79
80     it('should respond with the requested show', function() {
81       show.name.should.equal('New Show');
82       show.info.should.equal('This is the brand new show!!!');
83     });
84
85   });
86
87   describe('PUT /api/shows/:id', function() {
88     var updatedShow
89
90     beforeEach(function(done) {
91       request(app)
92         .put('/api/shows/' + newShow._id)
93         .send({
94           name: 'Updated Show',
95           info: 'This is the updated show!!!'
96         })
97         .expect(200)
98         .expect('Content-Type', /json/)
99         .end(function(err, res) {
100           if (err) {
101             return done(err);
102           }
103           updatedShow = res.body;
104           done();
105         });
106     });
107
108     afterEach(function() {
109       updatedShow = {};
110     });
111
112     it('should respond with the updated show', function() {
113       updatedShow.name.should.equal('Updated Show');
114       updatedShow.info.should.equal('This is the updated show!!!');
115     });
116
117   });
118
119   describe('DELETE /api/shows/:id', function() {
120
121     it('should respond with 204 on successful removal', function(done) {
122       request(app)
123         .delete('/api/shows/' + newShow._id)
124         .expect(204)
125         .end(function(err, res) {
126           if (err) {
127             return done(err);
128           }
129           done();
130         });
131     });
132
133     it('should respond with 404 when show does not exist', function(done) {
134       request(app)
135         .delete('/api/shows/' + newShow._id)
136         .expect(404)
137         .end(function(err, res) {
138           if (err) {
139             return done(err);
140           }
141           done();
142         });
143     });
144
145   });
146
147 });