From d72da37e9bc1243ab0f6e50cf1b6c92fde4281e4 Mon Sep 17 00:00:00 2001 From: aanev Date: Mon, 12 Jun 2017 11:19:11 +0300 Subject: [PATCH] feat(articles): Promisifies article server test set up and clean up (#1774) Promisifies object creation in beforeEach and afterEach hooks in article server tests. Fixes #1773 --- .../admin.article.server.routes.tests.js | 25 +++++++++-------- .../server/article.server.model.tests.js | 28 +++++++++++-------- .../server/article.server.routes.tests.js | 23 ++++++++------- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/modules/articles/tests/server/admin.article.server.routes.tests.js b/modules/articles/tests/server/admin.article.server.routes.tests.js index 0322dd14bc..ea9b9e14f1 100644 --- a/modules/articles/tests/server/admin.article.server.routes.tests.js +++ b/modules/articles/tests/server/admin.article.server.routes.tests.js @@ -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) { @@ -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); }); }); diff --git a/modules/articles/tests/server/article.server.model.tests.js b/modules/articles/tests/server/article.server.model.tests.js index 49463a16f4..54bb67ca33 100644 --- a/modules/articles/tests/server/article.server.model.tests.js +++ b/modules/articles/tests/server/article.server.model.tests.js @@ -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 () { @@ -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); }); }); diff --git a/modules/articles/tests/server/article.server.routes.tests.js b/modules/articles/tests/server/article.server.routes.tests.js index 6f35907e6a..a243319c17 100644 --- a/modules/articles/tests/server/article.server.routes.tests.js +++ b/modules/articles/tests/server/article.server.routes.tests.js @@ -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) { @@ -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); }); });