Ghost/test/utils/e2e-framework-mock-utils.js
Hannah Wolfe 5210e84b26
Improved e2e-framework API
- 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
2022-02-07 16:09:54 +00:00

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
};