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

Commit

Permalink
feat(articles): Promisifies article server test set up and clean up (#…
Browse files Browse the repository at this point in the history
…1774)

Promisifies object creation in beforeEach and afterEach hooks in article server tests.

Fixes #1773
  • Loading branch information
aanev authored and lirantal committed Jun 12, 2017
1 parent c6215a0 commit d72da37
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
25 changes: 14 additions & 11 deletions modules/articles/tests/server/admin.article.server.routes.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ describe('Article Admin CRUD tests', function () {
});

// Save a user to the test db and create new article
user.save(function () {
article = {
title: 'Article Title',
content: 'Article Content'
};

done();
});
user.save()
.then(function () {
article = {
title: 'Article Title',
content: 'Article Content'
};

done();
})
.catch(done);
});

it('should be able to save an article if logged in', function (done) {
Expand Down Expand Up @@ -275,8 +277,9 @@ describe('Article Admin CRUD tests', function () {
});

afterEach(function (done) {
User.remove().exec(function () {
Article.remove().exec(done);
});
Article.remove().exec()
.then(User.remove().exec())
.then(done())
.catch(done);
});
});
28 changes: 16 additions & 12 deletions modules/articles/tests/server/article.server.model.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ describe('Article Model Unit Tests:', function () {
displayName: 'Full Name',
email: 'test@test.com',
username: 'username',
password: 'M3@n.jsI$Aw3$0m3'
password: 'M3@n.jsI$Aw3$0m3',
provider: 'local'
});

user.save(function () {
article = new Article({
title: 'Article Title',
content: 'Article Content',
user: user
});
user.save()
.then(function () {
article = new Article({
title: 'Article Title',
content: 'Article Content',
user: user
});

done();
});
done();
})
.catch(done);
});

describe('Method Save', function () {
Expand All @@ -60,8 +63,9 @@ describe('Article Model Unit Tests:', function () {
});

afterEach(function (done) {
Article.remove().exec(function () {
User.remove().exec(done);
});
Article.remove().exec()
.then(User.remove().exec())
.then(done())
.catch(done);
});
});
23 changes: 13 additions & 10 deletions modules/articles/tests/server/article.server.routes.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ describe('Article CRUD tests', function () {
});

// Save a user to the test db and create new article
user.save(function () {
article = {
title: 'Article Title',
content: 'Article Content'
};
user.save()
.then(function () {
article = {
title: 'Article Title',
content: 'Article Content'
};

done();
});
done();
})
.catch(done);
});

it('should not be able to save an article if logged in without the "admin" role', function (done) {
Expand Down Expand Up @@ -407,8 +409,9 @@ describe('Article CRUD tests', function () {
});

afterEach(function (done) {
User.remove().exec(function () {
Article.remove().exec(done);
});
Article.remove().exec()
.then(User.remove().exec())
.then(done())
.catch(done);
});
});

0 comments on commit d72da37

Please sign in to comment.