2022-02-07 19:02:04 +03:00
|
|
|
const errors = require('@tryghost/errors');
|
2021-12-09 14:10:06 +03:00
|
|
|
const sinon = require('sinon');
|
|
|
|
|
2022-02-07 19:02:04 +03:00
|
|
|
let mocks = {};
|
|
|
|
|
2021-12-09 14:10:06 +03:00
|
|
|
const mailService = require('../../core/server/services/mail/index');
|
|
|
|
|
2022-02-07 19:02:04 +03:00
|
|
|
const mockMail = () => {
|
|
|
|
mocks.mail = sinon
|
2021-12-09 14:10:06 +03:00
|
|
|
.stub(mailService.GhostMailer.prototype, 'send')
|
|
|
|
.resolves('Mail is disabled');
|
2022-02-07 19:02:04 +03:00
|
|
|
|
|
|
|
return mocks.mail;
|
|
|
|
};
|
|
|
|
|
|
|
|
const assertMailSentTo = (email) => {
|
|
|
|
if (!mocks.mail) {
|
|
|
|
throw new errors.IncorrectUsageError({
|
|
|
|
message: 'Cannot assert on mail when mail has not been mocked'
|
|
|
|
});
|
|
|
|
}
|
2021-12-09 14:10:06 +03:00
|
|
|
};
|
|
|
|
|
2022-02-07 19:02:04 +03:00
|
|
|
const restore = () => {
|
|
|
|
sinon.restore();
|
|
|
|
mocks = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
mockMail,
|
|
|
|
restore
|
|
|
|
};
|