@@ -16,16 +16,16 @@ var app, agent, credentials, user, article;
16
16
/**
17
17
* Article routes tests
18
18
*/
19
- describe ( 'Article CRUD tests' , function ( ) {
20
- before ( function ( done ) {
19
+ describe ( 'Article CRUD tests' , function ( ) {
20
+ before ( function ( done ) {
21
21
// Get application
22
22
app = express . init ( mongoose ) ;
23
23
agent = request . agent ( app ) ;
24
24
25
25
done ( ) ;
26
26
} ) ;
27
27
28
- beforeEach ( function ( done ) {
28
+ beforeEach ( function ( done ) {
29
29
// Create user credentials
30
30
credentials = {
31
31
username : 'username' ,
@@ -44,7 +44,7 @@ describe('Article CRUD tests', function() {
44
44
} ) ;
45
45
46
46
// Save a user to the test db and create new article
47
- user . save ( function ( ) {
47
+ user . save ( function ( ) {
48
48
article = {
49
49
title : 'Article Title' ,
50
50
content : 'Article Content'
@@ -54,11 +54,11 @@ describe('Article CRUD tests', function() {
54
54
} ) ;
55
55
} ) ;
56
56
57
- it ( 'should be able to save an article if logged in' , function ( done ) {
57
+ it ( 'should be able to save an article if logged in' , function ( done ) {
58
58
agent . post ( '/api/auth/signin' )
59
59
. send ( credentials )
60
60
. expect ( 200 )
61
- . end ( function ( signinErr , signinRes ) {
61
+ . end ( function ( signinErr , signinRes ) {
62
62
// Handle signin error
63
63
if ( signinErr ) done ( signinErr ) ;
64
64
@@ -69,13 +69,13 @@ describe('Article CRUD tests', function() {
69
69
agent . post ( '/api/articles' )
70
70
. send ( article )
71
71
. expect ( 200 )
72
- . end ( function ( articleSaveErr , articleSaveRes ) {
72
+ . end ( function ( articleSaveErr , articleSaveRes ) {
73
73
// Handle article save error
74
74
if ( articleSaveErr ) done ( articleSaveErr ) ;
75
75
76
76
// Get a list of articles
77
77
agent . get ( '/api/articles' )
78
- . end ( function ( articlesGetErr , articlesGetRes ) {
78
+ . end ( function ( articlesGetErr , articlesGetRes ) {
79
79
// Handle article save error
80
80
if ( articlesGetErr ) done ( articlesGetErr ) ;
81
81
@@ -93,24 +93,24 @@ describe('Article CRUD tests', function() {
93
93
} ) ;
94
94
} ) ;
95
95
96
- it ( 'should not be able to save an article if not logged in' , function ( done ) {
96
+ it ( 'should not be able to save an article if not logged in' , function ( done ) {
97
97
agent . post ( '/api/articles' )
98
98
. send ( article )
99
99
. expect ( 403 )
100
- . end ( function ( articleSaveErr , articleSaveRes ) {
100
+ . end ( function ( articleSaveErr , articleSaveRes ) {
101
101
// Call the assertion callback
102
102
done ( articleSaveErr ) ;
103
103
} ) ;
104
104
} ) ;
105
105
106
- it ( 'should not be able to save an article if no title is provided' , function ( done ) {
106
+ it ( 'should not be able to save an article if no title is provided' , function ( done ) {
107
107
// Invalidate title field
108
108
article . title = '' ;
109
109
110
110
agent . post ( '/api/auth/signin' )
111
111
. send ( credentials )
112
112
. expect ( 200 )
113
- . end ( function ( signinErr , signinRes ) {
113
+ . end ( function ( signinErr , signinRes ) {
114
114
// Handle signin error
115
115
if ( signinErr ) done ( signinErr ) ;
116
116
@@ -121,7 +121,7 @@ describe('Article CRUD tests', function() {
121
121
agent . post ( '/api/articles' )
122
122
. send ( article )
123
123
. expect ( 400 )
124
- . end ( function ( articleSaveErr , articleSaveRes ) {
124
+ . end ( function ( articleSaveErr , articleSaveRes ) {
125
125
// Set message assertion
126
126
( articleSaveRes . body . message ) . should . match ( 'Title cannot be blank' ) ;
127
127
@@ -131,11 +131,11 @@ describe('Article CRUD tests', function() {
131
131
} ) ;
132
132
} ) ;
133
133
134
- it ( 'should be able to update an article if signed in' , function ( done ) {
134
+ it ( 'should be able to update an article if signed in' , function ( done ) {
135
135
agent . post ( '/api/auth/signin' )
136
136
. send ( credentials )
137
137
. expect ( 200 )
138
- . end ( function ( signinErr , signinRes ) {
138
+ . end ( function ( signinErr , signinRes ) {
139
139
// Handle signin error
140
140
if ( signinErr ) done ( signinErr ) ;
141
141
@@ -146,7 +146,7 @@ describe('Article CRUD tests', function() {
146
146
agent . post ( '/api/articles' )
147
147
. send ( article )
148
148
. expect ( 200 )
149
- . end ( function ( articleSaveErr , articleSaveRes ) {
149
+ . end ( function ( articleSaveErr , articleSaveRes ) {
150
150
// Handle article save error
151
151
if ( articleSaveErr ) done ( articleSaveErr ) ;
152
152
@@ -157,7 +157,7 @@ describe('Article CRUD tests', function() {
157
157
agent . put ( '/api/articles/' + articleSaveRes . body . _id )
158
158
. send ( article )
159
159
. expect ( 200 )
160
- . end ( function ( articleUpdateErr , articleUpdateRes ) {
160
+ . end ( function ( articleUpdateErr , articleUpdateRes ) {
161
161
// Handle article update error
162
162
if ( articleUpdateErr ) done ( articleUpdateErr ) ;
163
163
@@ -172,17 +172,17 @@ describe('Article CRUD tests', function() {
172
172
} ) ;
173
173
} ) ;
174
174
175
- it ( 'should be able to get a list of articles if not signed in' , function ( done ) {
175
+ it ( 'should be able to get a list of articles if not signed in' , function ( done ) {
176
176
// Create new article model instance
177
177
var articleObj = new Article ( article ) ;
178
178
179
179
// Save the article
180
- articleObj . save ( function ( ) {
180
+ articleObj . save ( function ( ) {
181
181
// Request articles
182
182
request ( app ) . get ( '/api/articles' )
183
- . end ( function ( req , res ) {
183
+ . end ( function ( req , res ) {
184
184
// Set assertion
185
- res . body . should . be . an . Array . with . lengthOf ( 1 ) ;
185
+ res . body . should . be . instanceof ( Array ) . and . have . lengthOf ( 1 ) ;
186
186
187
187
// Call the assertion callback
188
188
done ( ) ;
@@ -192,39 +192,40 @@ describe('Article CRUD tests', function() {
192
192
} ) ;
193
193
194
194
195
- it ( 'should be able to get a single article if not signed in' , function ( done ) {
195
+ it ( 'should be able to get a single article if not signed in' , function ( done ) {
196
196
// Create new article model instance
197
197
var articleObj = new Article ( article ) ;
198
198
199
199
// Save the article
200
- articleObj . save ( function ( ) {
200
+ articleObj . save ( function ( ) {
201
201
request ( app ) . get ( '/api/articles/' + articleObj . _id )
202
- . end ( function ( req , res ) {
202
+ . end ( function ( req , res ) {
203
203
// Set assertion
204
- res . body . should . be . an . Object . with . property ( 'title' , article . title ) ;
204
+ res . body . should . be . instanceof ( Object ) . and . have . property ( 'title' , article . title ) ;
205
205
206
206
// Call the assertion callback
207
207
done ( ) ;
208
208
} ) ;
209
209
} ) ;
210
210
} ) ;
211
211
212
- it ( 'should return proper error for single article which doesnt exist, if not signed in' , function ( done ) {
213
- request ( app ) . get ( '/articles/test' )
214
- . end ( function ( req , res ) {
212
+ it ( 'should return proper error for single article which doesnt exist, if not signed in' , function ( done ) {
213
+ request ( app ) . get ( '/api/articles/test' )
214
+ . end ( function ( req , res ) {
215
+ console . log ( res . body ) ;
215
216
// Set assertion
216
- res . body . should . be . an . Object . with . property ( 'message' , 'Article is invalid' ) ;
217
+ res . body . should . be . instanceof ( Object ) . and . have . property ( 'message' , 'Article is invalid' ) ;
217
218
218
219
// Call the assertion callback
219
220
done ( ) ;
220
221
} ) ;
221
222
} ) ;
222
223
223
- it ( 'should be able to delete an article if signed in' , function ( done ) {
224
+ it ( 'should be able to delete an article if signed in' , function ( done ) {
224
225
agent . post ( '/api/auth/signin' )
225
226
. send ( credentials )
226
227
. expect ( 200 )
227
- . end ( function ( signinErr , signinRes ) {
228
+ . end ( function ( signinErr , signinRes ) {
228
229
// Handle signin error
229
230
if ( signinErr ) done ( signinErr ) ;
230
231
@@ -235,15 +236,15 @@ describe('Article CRUD tests', function() {
235
236
agent . post ( '/api/articles' )
236
237
. send ( article )
237
238
. expect ( 200 )
238
- . end ( function ( articleSaveErr , articleSaveRes ) {
239
+ . end ( function ( articleSaveErr , articleSaveRes ) {
239
240
// Handle article save error
240
241
if ( articleSaveErr ) done ( articleSaveErr ) ;
241
242
242
243
// Delete an existing article
243
244
agent . delete ( '/api/articles/' + articleSaveRes . body . _id )
244
245
. send ( article )
245
246
. expect ( 200 )
246
- . end ( function ( articleDeleteErr , articleDeleteRes ) {
247
+ . end ( function ( articleDeleteErr , articleDeleteRes ) {
247
248
// Handle article error error
248
249
if ( articleDeleteErr ) done ( articleDeleteErr ) ;
249
250
@@ -257,31 +258,31 @@ describe('Article CRUD tests', function() {
257
258
} ) ;
258
259
} ) ;
259
260
260
- it ( 'should not be able to delete an article if not signed in' , function ( done ) {
261
+ it ( 'should not be able to delete an article if not signed in' , function ( done ) {
261
262
// Set article user
262
263
article . user = user ;
263
264
264
265
// Create new article model instance
265
266
var articleObj = new Article ( article ) ;
266
267
267
268
// Save the article
268
- articleObj . save ( function ( ) {
269
+ articleObj . save ( function ( ) {
269
270
// Try deleting article
270
271
request ( app ) . delete ( '/api/articles/' + articleObj . _id )
271
- . expect ( 403 )
272
- . end ( function ( articleDeleteErr , articleDeleteRes ) {
273
- // Set message assertion
274
- ( articleDeleteRes . body . message ) . should . match ( 'User is not authorized' ) ;
272
+ . expect ( 403 )
273
+ . end ( function ( articleDeleteErr , articleDeleteRes ) {
274
+ // Set message assertion
275
+ ( articleDeleteRes . body . message ) . should . match ( 'User is not authorized' ) ;
275
276
276
- // Handle article error error
277
- done ( articleDeleteErr ) ;
278
- } ) ;
277
+ // Handle article error error
278
+ done ( articleDeleteErr ) ;
279
+ } ) ;
279
280
280
281
} ) ;
281
282
} ) ;
282
283
283
- afterEach ( function ( done ) {
284
- User . remove ( ) . exec ( function ( ) {
284
+ afterEach ( function ( done ) {
285
+ User . remove ( ) . exec ( function ( ) {
285
286
Article . remove ( ) . exec ( done ) ;
286
287
} ) ;
287
288
} ) ;
0 commit comments