0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added mocked Mailgun client to browser test env

refs https://github.com/TryGhost/Ghost/pull/15959

- To be able to test and intercept emails we need a mock in test environment - avoids making calls to the Mailgun API
This commit is contained in:
Naz 2022-12-08 17:13:51 +07:00 committed by Sam Lord
parent 3d6753a54a
commit 4c6a86eca4
3 changed files with 38 additions and 2 deletions

View file

@ -64,7 +64,8 @@ const setup = async (playwrightConfig) => {
await startGhost({
frontend: true,
server: true,
backend: true
backend: true,
mockMailgun: true
});
}

View file

@ -40,6 +40,7 @@ const supertest = require('supertest');
* @param {Boolean} [options.backend] Boot the backend
* @param {Boolean} [options.frontend] Boot the frontend
* @param {Boolean} [options.server] Start a server
* @param {Boolean} [options.mockMailgun] Mock mailgun client module
* @returns {Promise<Express.Application>} ghost
*/
const startGhost = async (options = {}) => {
@ -56,13 +57,20 @@ const startGhost = async (options = {}) => {
const defaults = {
backend: true,
frontend: false,
server: false
server: false,
mockMailgun: false
};
// Ensure the state of all data, including DB and caches
await resetData();
const bootOptions = Object.assign({}, defaults, options);
if (bootOptions.mockMailgun) {
const rewire = require('rewire');
const bulkEmail = rewire('../../core/server/services/bulk-email');
let mockMailgunClient = require('./mocks/MailgunClientMock');
bulkEmail.__set__('_mailgunClient', mockMailgunClient);
}
const ghostServer = await boot(bootOptions);

View file

@ -0,0 +1,27 @@
const ObjectID = require('bson-objectid').default;
class MockMailgunClient {
getInstance() {
return {};
}
/**
*
* @param {Promise<{id}>}
*/
async send() {
return {
id: `mailgun-mock-id-${ObjectID().toHexString()}`
};
}
/**
* Act as if always configured on test environment
* @returns true
*/
isConfigured() {
return true;
}
}
module.exports = new MockMailgunClient();