Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit 67e38ae

Browse files
committed
fix failing tests
1 parent 9ca71c8 commit 67e38ae

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

modules/articles/tests/server/article.server.routes.tests.js

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ var app, agent, credentials, user, article;
1616
/**
1717
* Article routes tests
1818
*/
19-
describe('Article CRUD tests', function() {
20-
before(function(done) {
19+
describe('Article CRUD tests', function () {
20+
before(function (done) {
2121
// Get application
2222
app = express.init(mongoose);
2323
agent = request.agent(app);
2424

2525
done();
2626
});
2727

28-
beforeEach(function(done) {
28+
beforeEach(function (done) {
2929
// Create user credentials
3030
credentials = {
3131
username: 'username',
@@ -44,7 +44,7 @@ describe('Article CRUD tests', function() {
4444
});
4545

4646
// Save a user to the test db and create new article
47-
user.save(function() {
47+
user.save(function () {
4848
article = {
4949
title: 'Article Title',
5050
content: 'Article Content'
@@ -54,11 +54,11 @@ describe('Article CRUD tests', function() {
5454
});
5555
});
5656

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) {
5858
agent.post('/api/auth/signin')
5959
.send(credentials)
6060
.expect(200)
61-
.end(function(signinErr, signinRes) {
61+
.end(function (signinErr, signinRes) {
6262
// Handle signin error
6363
if (signinErr) done(signinErr);
6464

@@ -69,13 +69,13 @@ describe('Article CRUD tests', function() {
6969
agent.post('/api/articles')
7070
.send(article)
7171
.expect(200)
72-
.end(function(articleSaveErr, articleSaveRes) {
72+
.end(function (articleSaveErr, articleSaveRes) {
7373
// Handle article save error
7474
if (articleSaveErr) done(articleSaveErr);
7575

7676
// Get a list of articles
7777
agent.get('/api/articles')
78-
.end(function(articlesGetErr, articlesGetRes) {
78+
.end(function (articlesGetErr, articlesGetRes) {
7979
// Handle article save error
8080
if (articlesGetErr) done(articlesGetErr);
8181

@@ -93,24 +93,24 @@ describe('Article CRUD tests', function() {
9393
});
9494
});
9595

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) {
9797
agent.post('/api/articles')
9898
.send(article)
9999
.expect(403)
100-
.end(function(articleSaveErr, articleSaveRes) {
100+
.end(function (articleSaveErr, articleSaveRes) {
101101
// Call the assertion callback
102102
done(articleSaveErr);
103103
});
104104
});
105105

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) {
107107
// Invalidate title field
108108
article.title = '';
109109

110110
agent.post('/api/auth/signin')
111111
.send(credentials)
112112
.expect(200)
113-
.end(function(signinErr, signinRes) {
113+
.end(function (signinErr, signinRes) {
114114
// Handle signin error
115115
if (signinErr) done(signinErr);
116116

@@ -121,7 +121,7 @@ describe('Article CRUD tests', function() {
121121
agent.post('/api/articles')
122122
.send(article)
123123
.expect(400)
124-
.end(function(articleSaveErr, articleSaveRes) {
124+
.end(function (articleSaveErr, articleSaveRes) {
125125
// Set message assertion
126126
(articleSaveRes.body.message).should.match('Title cannot be blank');
127127

@@ -131,11 +131,11 @@ describe('Article CRUD tests', function() {
131131
});
132132
});
133133

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) {
135135
agent.post('/api/auth/signin')
136136
.send(credentials)
137137
.expect(200)
138-
.end(function(signinErr, signinRes) {
138+
.end(function (signinErr, signinRes) {
139139
// Handle signin error
140140
if (signinErr) done(signinErr);
141141

@@ -146,7 +146,7 @@ describe('Article CRUD tests', function() {
146146
agent.post('/api/articles')
147147
.send(article)
148148
.expect(200)
149-
.end(function(articleSaveErr, articleSaveRes) {
149+
.end(function (articleSaveErr, articleSaveRes) {
150150
// Handle article save error
151151
if (articleSaveErr) done(articleSaveErr);
152152

@@ -157,7 +157,7 @@ describe('Article CRUD tests', function() {
157157
agent.put('/api/articles/' + articleSaveRes.body._id)
158158
.send(article)
159159
.expect(200)
160-
.end(function(articleUpdateErr, articleUpdateRes) {
160+
.end(function (articleUpdateErr, articleUpdateRes) {
161161
// Handle article update error
162162
if (articleUpdateErr) done(articleUpdateErr);
163163

@@ -172,17 +172,17 @@ describe('Article CRUD tests', function() {
172172
});
173173
});
174174

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) {
176176
// Create new article model instance
177177
var articleObj = new Article(article);
178178

179179
// Save the article
180-
articleObj.save(function() {
180+
articleObj.save(function () {
181181
// Request articles
182182
request(app).get('/api/articles')
183-
.end(function(req, res) {
183+
.end(function (req, res) {
184184
// Set assertion
185-
res.body.should.be.an.Array.with.lengthOf(1);
185+
res.body.should.be.instanceof(Array).and.have.lengthOf(1);
186186

187187
// Call the assertion callback
188188
done();
@@ -192,39 +192,40 @@ describe('Article CRUD tests', function() {
192192
});
193193

194194

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) {
196196
// Create new article model instance
197197
var articleObj = new Article(article);
198198

199199
// Save the article
200-
articleObj.save(function() {
200+
articleObj.save(function () {
201201
request(app).get('/api/articles/' + articleObj._id)
202-
.end(function(req, res) {
202+
.end(function (req, res) {
203203
// 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);
205205

206206
// Call the assertion callback
207207
done();
208208
});
209209
});
210210
});
211211

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);
215216
// 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');
217218

218219
// Call the assertion callback
219220
done();
220221
});
221222
});
222223

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) {
224225
agent.post('/api/auth/signin')
225226
.send(credentials)
226227
.expect(200)
227-
.end(function(signinErr, signinRes) {
228+
.end(function (signinErr, signinRes) {
228229
// Handle signin error
229230
if (signinErr) done(signinErr);
230231

@@ -235,15 +236,15 @@ describe('Article CRUD tests', function() {
235236
agent.post('/api/articles')
236237
.send(article)
237238
.expect(200)
238-
.end(function(articleSaveErr, articleSaveRes) {
239+
.end(function (articleSaveErr, articleSaveRes) {
239240
// Handle article save error
240241
if (articleSaveErr) done(articleSaveErr);
241242

242243
// Delete an existing article
243244
agent.delete('/api/articles/' + articleSaveRes.body._id)
244245
.send(article)
245246
.expect(200)
246-
.end(function(articleDeleteErr, articleDeleteRes) {
247+
.end(function (articleDeleteErr, articleDeleteRes) {
247248
// Handle article error error
248249
if (articleDeleteErr) done(articleDeleteErr);
249250

@@ -257,31 +258,31 @@ describe('Article CRUD tests', function() {
257258
});
258259
});
259260

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) {
261262
// Set article user
262263
article.user = user;
263264

264265
// Create new article model instance
265266
var articleObj = new Article(article);
266267

267268
// Save the article
268-
articleObj.save(function() {
269+
articleObj.save(function () {
269270
// Try deleting article
270271
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');
275276

276-
// Handle article error error
277-
done(articleDeleteErr);
278-
});
277+
// Handle article error error
278+
done(articleDeleteErr);
279+
});
279280

280281
});
281282
});
282283

283-
afterEach(function(done) {
284-
User.remove().exec(function() {
284+
afterEach(function (done) {
285+
User.remove().exec(function () {
285286
Article.remove().exec(done);
286287
});
287288
});

0 commit comments

Comments
 (0)