From 64d94c8c8cae76c64829c58a8f2a3ea49e91d404 Mon Sep 17 00:00:00 2001 From: Sam Lord Date: Fri, 3 Mar 2023 13:43:08 +0000 Subject: [PATCH] Prevent posts-legacy tests from logging errors refs: https://github.com/TryGhost/Toolbox/issues/389 The newsletter fixtures no longer errors when accessing the test image, and tests which intentionally error now stub the logging call --- ghost/core/test/e2e-api/admin/posts-legacy.test.js | 9 +++++++++ ghost/core/test/utils/e2e-utils.js | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/ghost/core/test/e2e-api/admin/posts-legacy.test.js b/ghost/core/test/e2e-api/admin/posts-legacy.test.js index 00965fadb7..059c3d025f 100644 --- a/ghost/core/test/e2e-api/admin/posts-legacy.test.js +++ b/ghost/core/test/e2e-api/admin/posts-legacy.test.js @@ -11,6 +11,8 @@ const models = require('../../../core/server/models'); const localUtils = require('./utils'); const configUtils = require('../../utils/configUtils'); const mockManager = require('../../utils/e2e-framework-mock-manager'); +const sinon = require('sinon'); +const logging = require('@tryghost/logging'); describe('Posts API', function () { let request; @@ -623,6 +625,8 @@ describe('Posts API', function () { updatedPost.status = 'published'; + const loggingStub = sinon.stub(logging, 'error'); + await request .put(localUtils.API.getApiQuery('posts/' + id + '/?newsletter=' + newsletterSlug)) .set('Origin', config.get('url')) @@ -630,6 +634,8 @@ describe('Posts API', function () { .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(400); + + sinon.assert.calledOnce(loggingStub); }); it('Can publish a post without email', async function () { @@ -1987,6 +1993,8 @@ describe('Posts API', function () { const newsletterId = testUtils.DataGenerator.Content.newsletters[1].id; const newsletterSlug = testUtils.DataGenerator.Content.newsletters[1].slug; + const loggingStub = sinon.stub(logging, 'error'); + const response = await request .put(localUtils.API.getApiQuery(`posts/${draftPost.id}/?newsletter=${newsletterSlug}`)) .set('Origin', config.get('url')) @@ -2000,6 +2008,7 @@ describe('Posts API', function () { response.body.errors[0].type.should.equal('HostLimitError'); response.body.errors[0].context.should.equal('No email shalt be sent'); + sinon.assert.calledOnce(loggingStub); }); }); }); diff --git a/ghost/core/test/utils/e2e-utils.js b/ghost/core/test/utils/e2e-utils.js index dfc48a294f..35113c3d9e 100644 --- a/ghost/core/test/utils/e2e-utils.js +++ b/ghost/core/test/utils/e2e-utils.js @@ -96,6 +96,11 @@ const prepareContentFolder = (options) => { } else if (options.copySettings) { fs.copySync(path.join(__dirname, 'fixtures', 'settings', 'routes.yaml'), path.join(contentFolderForTests, 'settings', 'routes.yaml')); } + + // Used by newsletter fixtures + fs.ensureDirSync(path.join(contentFolderForTests, 'images', '2022', '05')); + const GIF1x1 = Buffer.from('R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==', 'base64'); + fs.writeFileSync(path.join(contentFolderForTests, 'images', '2022', '05', 'test.jpg'), GIF1x1); }; // CASE: Ghost Server is Running