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:
Simon Backx 2023-01-20 18:58:54 +01:00
parent 693216c29e
commit 3ac282598c
3 changed files with 16 additions and 33 deletions

View File

@ -6,6 +6,9 @@ const {setupGhost, setupStripe, setupMailgun} = require('./e2e-browser-utils');
const {chromium} = require('@playwright/test');
const {startGhost} = require('../../utils/e2e-framework');
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 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 rewire = require('rewire');
const mockMailgunClient = require('../../utils/mocks/MailgunClientMock');
const bulkEmail = rewire('../../../core/server/services/bulk-email/bulk-email-processor');
bulkEmail.__set__('mailgunClient', mockMailgunClient);
// 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()}`
};
}
}
});
};
/**

View File

@ -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();

View File

@ -481,7 +481,7 @@ describe('Batch Sending Service', function () {
batches,
post: createModel({}),
newsletter: createModel({})
}), /Email failed to send/);
}), /An unexpected error occurred, please retry sending your newsletter/);
sinon.assert.callCount(sendBatch, 101);
const sendBatches = sendBatch.getCalls().map(call => call.args[0].batch);
assert.deepEqual(sendBatches, batches);
@ -507,7 +507,7 @@ describe('Batch Sending Service', function () {
batches,
post: createModel({}),
newsletter: createModel({})
}), /The email was only partially send/);
}), /was only partially sent/);
sinon.assert.callCount(sendBatch, 101);
const sendBatches = sendBatch.getCalls().map(call => call.args[0].batch);
assert.deepEqual(sendBatches, batches);