mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-08 04:03:12 +03:00
5210e84b26
- encapsulated concerns within individual objects - this will allow us to refactor these into classes or move them around later - also makes it clearer how methods like restore relate to other methods - e.g mocks.restore() restores mocks, whilst fixtureManager.restore() restores the database
33 lines
655 B
JavaScript
33 lines
655 B
JavaScript
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
|
|
};
|