From 86d65956d945bfa8b0c09f679200da9c8161a764 Mon Sep 17 00:00:00 2001 From: Valeriy Date: Tue, 24 Jan 2017 12:14:27 +0300 Subject: [PATCH] fixed recoverCron tests failure when using mocha v3+ (#8407) * fixed recoverCron tests * type'o fix * grammar nazi fix * lint fix * reverted to async/await (but done call removed) * fixed Tasks tests failure on Mocha 3+ --- test/api/v3/unit/libs/cron.test.js | 14 +++++--------- test/api/v3/unit/models/task.test.js | 10 ++++------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/test/api/v3/unit/libs/cron.test.js b/test/api/v3/unit/libs/cron.test.js index 180a635a07..8664874b8c 100644 --- a/test/api/v3/unit/libs/cron.test.js +++ b/test/api/v3/unit/libs/cron.test.js @@ -975,19 +975,18 @@ describe('recoverCron', () => { sandbox.restore(); }); - it('throws an error if user cannot be found', async (done) => { + it('throws an error if user cannot be found', async () => { execStub.returns(Bluebird.resolve(null)); try { await recoverCron(status, locals); + throw new Error('no exception when user cannot be found'); } catch (err) { expect(err.message).to.eql(`User ${locals.user._id} not found while recovering.`); - - done(); } }); - it('increases status.times count and reruns up to 4 times', async (done) => { + it('increases status.times count and reruns up to 4 times', async () => { execStub.returns(Bluebird.resolve({_cronSignature: 'RUNNING_CRON'})); execStub.onCall(4).returns(Bluebird.resolve({_cronSignature: 'NOT_RUNNING'})); @@ -995,20 +994,17 @@ describe('recoverCron', () => { expect(status.times).to.eql(4); expect(locals.user).to.eql({_cronSignature: 'NOT_RUNNING'}); - - done(); }); - it('throws an error if recoverCron runs 5 times', async (done) => { + it('throws an error if recoverCron runs 5 times', async () => { execStub.returns(Bluebird.resolve({_cronSignature: 'RUNNING_CRON'})); try { await recoverCron(status, locals); + throw new Error('no exception when recoverCron runs 5 times'); } catch (err) { expect(status.times).to.eql(5); expect(err.message).to.eql(`Impossible to recover from cron for user ${locals.user._id}.`); - - done(); } }); }); diff --git a/test/api/v3/unit/models/task.test.js b/test/api/v3/unit/models/task.test.js index cd097144eb..ddab40b26f 100644 --- a/test/api/v3/unit/models/task.test.js +++ b/test/api/v3/unit/models/task.test.js @@ -91,25 +91,23 @@ describe('Task Model', () => { sandbox.spy(Tasks.Task, 'findOne'); }); - it('throws an error if task identifier is not passed in', async (done) => { + it('throws an error if task identifier is not passed in', async () => { try { await Tasks.Task.findByIdOrAlias(null, user._id); + throw new Error('No exception when Id is None'); } catch (err) { expect(err).to.exist; expect(err).to.eql(new InternalServerError('Task identifier is a required argument')); - - done(); } }); - it('throws an error if user identifier is not passed in', async (done) => { + it('throws an error if user identifier is not passed in', async () => { try { await Tasks.Task.findByIdOrAlias(taskWithAlias._id); + throw new Error('No exception when user_id is undefined'); } catch (err) { expect(err).to.exist; expect(err).to.eql(new InternalServerError('User identifier is a required argument')); - - done(); } });