mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-10 14:10:29 +01:00
fix failing tests
This commit is contained in:
@@ -16,8 +16,8 @@ var app, agent, credentials, user, article;
|
||||
/**
|
||||
* Article routes tests
|
||||
*/
|
||||
describe('Article CRUD tests', function() {
|
||||
before(function(done) {
|
||||
describe('Article CRUD tests', function () {
|
||||
before(function (done) {
|
||||
// Get application
|
||||
app = express.init(mongoose);
|
||||
agent = request.agent(app);
|
||||
@@ -25,7 +25,7 @@ describe('Article CRUD tests', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
beforeEach(function(done) {
|
||||
beforeEach(function (done) {
|
||||
// Create user credentials
|
||||
credentials = {
|
||||
username: 'username',
|
||||
@@ -44,7 +44,7 @@ describe('Article CRUD tests', function() {
|
||||
});
|
||||
|
||||
// Save a user to the test db and create new article
|
||||
user.save(function() {
|
||||
user.save(function () {
|
||||
article = {
|
||||
title: 'Article Title',
|
||||
content: 'Article Content'
|
||||
@@ -54,11 +54,11 @@ describe('Article CRUD tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to save an article if logged in', function(done) {
|
||||
it('should be able to save an article if logged in', function (done) {
|
||||
agent.post('/api/auth/signin')
|
||||
.send(credentials)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
.end(function (signinErr, signinRes) {
|
||||
// Handle signin error
|
||||
if (signinErr) done(signinErr);
|
||||
|
||||
@@ -69,13 +69,13 @@ describe('Article CRUD tests', function() {
|
||||
agent.post('/api/articles')
|
||||
.send(article)
|
||||
.expect(200)
|
||||
.end(function(articleSaveErr, articleSaveRes) {
|
||||
.end(function (articleSaveErr, articleSaveRes) {
|
||||
// Handle article save error
|
||||
if (articleSaveErr) done(articleSaveErr);
|
||||
|
||||
// Get a list of articles
|
||||
agent.get('/api/articles')
|
||||
.end(function(articlesGetErr, articlesGetRes) {
|
||||
.end(function (articlesGetErr, articlesGetRes) {
|
||||
// Handle article save error
|
||||
if (articlesGetErr) done(articlesGetErr);
|
||||
|
||||
@@ -93,24 +93,24 @@ describe('Article CRUD tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not be able to save an article if not logged in', function(done) {
|
||||
it('should not be able to save an article if not logged in', function (done) {
|
||||
agent.post('/api/articles')
|
||||
.send(article)
|
||||
.expect(403)
|
||||
.end(function(articleSaveErr, articleSaveRes) {
|
||||
.end(function (articleSaveErr, articleSaveRes) {
|
||||
// Call the assertion callback
|
||||
done(articleSaveErr);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not be able to save an article if no title is provided', function(done) {
|
||||
it('should not be able to save an article if no title is provided', function (done) {
|
||||
// Invalidate title field
|
||||
article.title = '';
|
||||
|
||||
agent.post('/api/auth/signin')
|
||||
.send(credentials)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
.end(function (signinErr, signinRes) {
|
||||
// Handle signin error
|
||||
if (signinErr) done(signinErr);
|
||||
|
||||
@@ -121,7 +121,7 @@ describe('Article CRUD tests', function() {
|
||||
agent.post('/api/articles')
|
||||
.send(article)
|
||||
.expect(400)
|
||||
.end(function(articleSaveErr, articleSaveRes) {
|
||||
.end(function (articleSaveErr, articleSaveRes) {
|
||||
// Set message assertion
|
||||
(articleSaveRes.body.message).should.match('Title cannot be blank');
|
||||
|
||||
@@ -131,11 +131,11 @@ describe('Article CRUD tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to update an article if signed in', function(done) {
|
||||
it('should be able to update an article if signed in', function (done) {
|
||||
agent.post('/api/auth/signin')
|
||||
.send(credentials)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
.end(function (signinErr, signinRes) {
|
||||
// Handle signin error
|
||||
if (signinErr) done(signinErr);
|
||||
|
||||
@@ -146,7 +146,7 @@ describe('Article CRUD tests', function() {
|
||||
agent.post('/api/articles')
|
||||
.send(article)
|
||||
.expect(200)
|
||||
.end(function(articleSaveErr, articleSaveRes) {
|
||||
.end(function (articleSaveErr, articleSaveRes) {
|
||||
// Handle article save error
|
||||
if (articleSaveErr) done(articleSaveErr);
|
||||
|
||||
@@ -157,7 +157,7 @@ describe('Article CRUD tests', function() {
|
||||
agent.put('/api/articles/' + articleSaveRes.body._id)
|
||||
.send(article)
|
||||
.expect(200)
|
||||
.end(function(articleUpdateErr, articleUpdateRes) {
|
||||
.end(function (articleUpdateErr, articleUpdateRes) {
|
||||
// Handle article update error
|
||||
if (articleUpdateErr) done(articleUpdateErr);
|
||||
|
||||
@@ -172,17 +172,17 @@ describe('Article CRUD tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to get a list of articles if not signed in', function(done) {
|
||||
it('should be able to get a list of articles if not signed in', function (done) {
|
||||
// Create new article model instance
|
||||
var articleObj = new Article(article);
|
||||
|
||||
// Save the article
|
||||
articleObj.save(function() {
|
||||
articleObj.save(function () {
|
||||
// Request articles
|
||||
request(app).get('/api/articles')
|
||||
.end(function(req, res) {
|
||||
.end(function (req, res) {
|
||||
// Set assertion
|
||||
res.body.should.be.an.Array.with.lengthOf(1);
|
||||
res.body.should.be.instanceof(Array).and.have.lengthOf(1);
|
||||
|
||||
// Call the assertion callback
|
||||
done();
|
||||
@@ -192,16 +192,16 @@ describe('Article CRUD tests', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should be able to get a single article if not signed in', function(done) {
|
||||
it('should be able to get a single article if not signed in', function (done) {
|
||||
// Create new article model instance
|
||||
var articleObj = new Article(article);
|
||||
|
||||
// Save the article
|
||||
articleObj.save(function() {
|
||||
articleObj.save(function () {
|
||||
request(app).get('/api/articles/' + articleObj._id)
|
||||
.end(function(req, res) {
|
||||
.end(function (req, res) {
|
||||
// Set assertion
|
||||
res.body.should.be.an.Object.with.property('title', article.title);
|
||||
res.body.should.be.instanceof(Object).and.have.property('title', article.title);
|
||||
|
||||
// Call the assertion callback
|
||||
done();
|
||||
@@ -209,22 +209,23 @@ describe('Article CRUD tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return proper error for single article which doesnt exist, if not signed in', function(done) {
|
||||
request(app).get('/articles/test')
|
||||
.end(function(req, res) {
|
||||
it('should return proper error for single article which doesnt exist, if not signed in', function (done) {
|
||||
request(app).get('/api/articles/test')
|
||||
.end(function (req, res) {
|
||||
console.log(res.body);
|
||||
// Set assertion
|
||||
res.body.should.be.an.Object.with.property('message', 'Article is invalid');
|
||||
res.body.should.be.instanceof(Object).and.have.property('message', 'Article is invalid');
|
||||
|
||||
// Call the assertion callback
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to delete an article if signed in', function(done) {
|
||||
it('should be able to delete an article if signed in', function (done) {
|
||||
agent.post('/api/auth/signin')
|
||||
.send(credentials)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
.end(function (signinErr, signinRes) {
|
||||
// Handle signin error
|
||||
if (signinErr) done(signinErr);
|
||||
|
||||
@@ -235,7 +236,7 @@ describe('Article CRUD tests', function() {
|
||||
agent.post('/api/articles')
|
||||
.send(article)
|
||||
.expect(200)
|
||||
.end(function(articleSaveErr, articleSaveRes) {
|
||||
.end(function (articleSaveErr, articleSaveRes) {
|
||||
// Handle article save error
|
||||
if (articleSaveErr) done(articleSaveErr);
|
||||
|
||||
@@ -243,7 +244,7 @@ describe('Article CRUD tests', function() {
|
||||
agent.delete('/api/articles/' + articleSaveRes.body._id)
|
||||
.send(article)
|
||||
.expect(200)
|
||||
.end(function(articleDeleteErr, articleDeleteRes) {
|
||||
.end(function (articleDeleteErr, articleDeleteRes) {
|
||||
// Handle article error error
|
||||
if (articleDeleteErr) done(articleDeleteErr);
|
||||
|
||||
@@ -257,7 +258,7 @@ describe('Article CRUD tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not be able to delete an article if not signed in', function(done) {
|
||||
it('should not be able to delete an article if not signed in', function (done) {
|
||||
// Set article user
|
||||
article.user = user;
|
||||
|
||||
@@ -265,23 +266,23 @@ describe('Article CRUD tests', function() {
|
||||
var articleObj = new Article(article);
|
||||
|
||||
// Save the article
|
||||
articleObj.save(function() {
|
||||
articleObj.save(function () {
|
||||
// Try deleting article
|
||||
request(app).delete('/api/articles/' + articleObj._id)
|
||||
.expect(403)
|
||||
.end(function(articleDeleteErr, articleDeleteRes) {
|
||||
// Set message assertion
|
||||
(articleDeleteRes.body.message).should.match('User is not authorized');
|
||||
.expect(403)
|
||||
.end(function (articleDeleteErr, articleDeleteRes) {
|
||||
// Set message assertion
|
||||
(articleDeleteRes.body.message).should.match('User is not authorized');
|
||||
|
||||
// Handle article error error
|
||||
done(articleDeleteErr);
|
||||
});
|
||||
// Handle article error error
|
||||
done(articleDeleteErr);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
User.remove().exec(function() {
|
||||
afterEach(function (done) {
|
||||
User.remove().exec(function () {
|
||||
Article.remove().exec(done);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user