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:
parent
3d6753a54a
commit
4c6a86eca4
3 changed files with 38 additions and 2 deletions
|
@ -64,7 +64,8 @@ const setup = async (playwrightConfig) => {
|
|||
await startGhost({
|
||||
frontend: true,
|
||||
server: true,
|
||||
backend: true
|
||||
backend: true,
|
||||
mockMailgun: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
27
ghost/core/test/utils/mocks/MailgunClientMock.js
Normal file
27
ghost/core/test/utils/mocks/MailgunClientMock.js
Normal 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();
|
Loading…
Add table
Reference in a new issue