Ghost/test/utils/e2e-framework-mock-utils.js

33 lines
655 B
JavaScript
Raw Normal View History

const errors = require('@tryghost/errors');
const sinon = require('sinon');
let mocks = {};
const mailService = require('../../core/server/services/mail/index');
const mockMail = () => {
mocks.mail = sinon
.stub(mailService.GhostMailer.prototype, 'send')
.resolves('Mail is disabled');
return mocks.mail;
};
const assertMailSentTo = (email) => {
if (!mocks.mail) {
throw new errors.IncorrectUsageError({
message: 'Cannot assert on mail when mail has not been mocked'
});
}
};
const restore = () => {
sinon.restore();
mocks = {};
};
module.exports = {
mockMail,
restore
};