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.
This commit is contained in:
Simon Backx 2023-03-17 17:34:01 +01:00
parent 7f1f6a7249
commit a6654b5e6c

View File

@ -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/);
});
});