From a6654b5e6c7e2870d71a7c83507f00993068aa18 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Fri, 17 Mar 2023 17:34:01 +0100 Subject: [PATCH] Updated GhostMailer Direct unit tests to async await style no issue Tests were timing out for some users, probably because not all errors are caught. --- .../server/services/mail/GhostMailer.test.js | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/ghost/core/test/unit/server/services/mail/GhostMailer.test.js b/ghost/core/test/unit/server/services/mail/GhostMailer.test.js index a56051945b..38d9a832ad 100644 --- a/ghost/core/test/unit/server/services/mail/GhostMailer.test.js +++ b/ghost/core/test/unit/server/services/mail/GhostMailer.test.js @@ -5,6 +5,7 @@ const settingsCache = require('../../../../../core/shared/settings-cache'); const configUtils = require('../../../../utils/configUtils'); const urlUtils = require('../../../../../core/shared/url-utils'); let mailer; +const assert = require('assert'); // Mock SMTP config const SMTP = { @@ -120,37 +121,19 @@ describe('Mail: Ghostmailer', function () { mailer = null; }); - it('return correct failure message for domain doesn\'t exist', function (done) { + it('return correct failure message for domain doesn\'t exist', async function () { mailer.transport.transporter.name.should.eql('SMTP (direct)'); - - mailer.send(mailDataNoDomain).then(function () { - done(new Error('Error message not shown.')); - }, function (error) { - error.message.should.startWith('Failed to send email.'); - done(); - }).catch(done); + await assert.rejects(mailer.send(mailDataNoDomain), /Failed to send email/); }); - it('return correct failure message for no mail server at this address', function (done) { + it('return correct failure message for no mail server at this address', async function () { mailer.transport.transporter.name.should.eql('SMTP (direct)'); - - mailer.send(mailDataNoServer).then(function () { - done(new Error('Error message not shown.')); - }, function (error) { - error.message.should.startWith('Failed to send email.'); - done(); - }).catch(done); + await assert.rejects(mailer.send(mailDataNoServer), /Failed to send email/); }); - it('return correct failure message for incomplete data', function (done) { + it('return correct failure message for incomplete data', async function () { mailer.transport.transporter.name.should.eql('SMTP (direct)'); - - mailer.send(mailDataIncomplete).then(function () { - done(new Error('Error message not shown.')); - }, function (error) { - error.message.should.eql('Incomplete message data.'); - done(); - }).catch(done); + await assert.rejects(mailer.send(mailDataIncomplete), /Incomplete message data/); }); });