mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed Playwright tests for new email flow
no issue Tests stopped working because the Mailgun mocker stopped working since we moved to the new email flow. This also fixes a unit test that needed to get updated.
This commit is contained in:
parent
693216c29e
commit
3ac282598c
3 changed files with 16 additions and 33 deletions
|
@ -6,6 +6,9 @@ const {setupGhost, setupStripe, setupMailgun} = require('./e2e-browser-utils');
|
||||||
const {chromium} = require('@playwright/test');
|
const {chromium} = require('@playwright/test');
|
||||||
const {startGhost} = require('../../utils/e2e-framework');
|
const {startGhost} = require('../../utils/e2e-framework');
|
||||||
const {stopGhost} = require('../../utils/e2e-utils');
|
const {stopGhost} = require('../../utils/e2e-utils');
|
||||||
|
const MailgunClient = require('@tryghost/mailgun-client/lib/mailgun-client');
|
||||||
|
const sinon = require('sinon');
|
||||||
|
const ObjectID = require('bson-objectid').default;
|
||||||
|
|
||||||
const startWebhookServer = () => {
|
const startWebhookServer = () => {
|
||||||
const command = `stripe listen --forward-to ${config.getSiteUrl()}members/webhooks/stripe/ ${process.env.CI ? `--api-key ${process.env.STRIPE_SECRET_KEY}` : ''}`.trim();
|
const command = `stripe listen --forward-to ${config.getSiteUrl()}members/webhooks/stripe/ ${process.env.CI ? `--api-key ${process.env.STRIPE_SECRET_KEY}` : ''}`.trim();
|
||||||
|
@ -49,10 +52,17 @@ const generateStripeIntegrationToken = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const stubMailgun = () => {
|
const stubMailgun = () => {
|
||||||
const rewire = require('rewire');
|
// We need to stub the Mailgun client before starting Ghost
|
||||||
const mockMailgunClient = require('../../utils/mocks/MailgunClientMock');
|
sinon.stub(MailgunClient.prototype, 'getInstance').returns({
|
||||||
const bulkEmail = rewire('../../../core/server/services/bulk-email/bulk-email-processor');
|
// @ts-ignore
|
||||||
bulkEmail.__set__('mailgunClient', mockMailgunClient);
|
messages: {
|
||||||
|
create: async function () {
|
||||||
|
return {
|
||||||
|
id: `mailgun-mock-id-${ObjectID().toHexString()}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
const ObjectID = require('bson-objectid').default;
|
|
||||||
|
|
||||||
class MockMailgunClient {
|
|
||||||
getInstance() {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @returns {Promise<{id: string}>}
|
|
||||||
*/
|
|
||||||
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();
|
|
|
@ -481,7 +481,7 @@ describe('Batch Sending Service', function () {
|
||||||
batches,
|
batches,
|
||||||
post: createModel({}),
|
post: createModel({}),
|
||||||
newsletter: createModel({})
|
newsletter: createModel({})
|
||||||
}), /Email failed to send/);
|
}), /An unexpected error occurred, please retry sending your newsletter/);
|
||||||
sinon.assert.callCount(sendBatch, 101);
|
sinon.assert.callCount(sendBatch, 101);
|
||||||
const sendBatches = sendBatch.getCalls().map(call => call.args[0].batch);
|
const sendBatches = sendBatch.getCalls().map(call => call.args[0].batch);
|
||||||
assert.deepEqual(sendBatches, batches);
|
assert.deepEqual(sendBatches, batches);
|
||||||
|
@ -507,7 +507,7 @@ describe('Batch Sending Service', function () {
|
||||||
batches,
|
batches,
|
||||||
post: createModel({}),
|
post: createModel({}),
|
||||||
newsletter: createModel({})
|
newsletter: createModel({})
|
||||||
}), /The email was only partially send/);
|
}), /was only partially sent/);
|
||||||
sinon.assert.callCount(sendBatch, 101);
|
sinon.assert.callCount(sendBatch, 101);
|
||||||
const sendBatches = sendBatch.getCalls().map(call => call.args[0].batch);
|
const sendBatches = sendBatch.getCalls().map(call => call.args[0].batch);
|
||||||
assert.deepEqual(sendBatches, batches);
|
assert.deepEqual(sendBatches, batches);
|
||||||
|
|
Loading…
Add table
Reference in a new issue