0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Mocked GhostMailer in browser e2e tests

refs: https://github.com/TryGhost/DevOps/issues/78
This commit is contained in:
Sam Lord 2023-10-09 21:22:01 +01:00 committed by Sam Lord
parent cb38a2d997
commit 7aa7447db9

View file

@ -4,7 +4,7 @@ const base = require('@playwright/test');
const {promisify} = require('util');
const {spawn, exec} = require('child_process');
const {setupGhost, setupMailgun, enableLabs, setupStripe} = require('../utils/e2e-browser-utils');
const {allowStripe} = require('../../utils/e2e-framework-mock-manager');
const {allowStripe, mockMail} = require('../../utils/e2e-framework-mock-manager');
const MailgunClient = require('@tryghost/mailgun-client');
const sinon = require('sinon');
const ObjectID = require('bson-objectid').default;
@ -21,6 +21,10 @@ const getWebhookSecret = async () => {
};
const generateStripeIntegrationToken = async () => {
if (!('STRIPE_PUBLISHABLE_KEY' in process.env) || !('STRIPE_SECRET_KEY' in process.env)) {
throw new Error('Missing STRIPE_PUBLISHABLE_KEY or STRIPE_SECRET_KEY environment variables');
}
const publishableKey = process.env.STRIPE_PUBLISHABLE_KEY;
const secretKey = process.env.STRIPE_SECRET_KEY;
const accountId = process.env.STRIPE_ACCOUNT_ID ?? JSON.parse((await promisify(exec)('stripe get account')).stdout).id;
@ -33,20 +37,6 @@ const generateStripeIntegrationToken = async () => {
})).toString('base64');
};
const stubMailgun = () => {
// We need to stub the Mailgun client before starting Ghost
sinon.stub(MailgunClient.prototype, 'getInstance').returns({
// @ts-ignore
messages: {
create: async function () {
return {
id: `mailgun-mock-id-${ObjectID().toHexString()}`
};
}
}
});
};
// Global promises for webhook secret / Stripe integration token
const webhookSecretPromise = getWebhookSecret();
const stripeIntegrationTokenPromise = generateStripeIntegrationToken();
@ -105,7 +95,18 @@ module.exports = base.test.extend({
process.env.WEBHOOK_SECRET = await webhookSecretPromise;
stubMailgun();
sandbox.stub(MailgunClient.prototype, 'getInstance').returns({
// @ts-ignore
messages: {
create: async function () {
return {
id: `mailgun-mock-id-${ObjectID().toHexString()}`
};
}
}
});
mockMail();
const {startGhost} = require('../../utils/e2e-framework');
const server = await startGhost({