From 3a974f6e4e88b1effb0457b618459aa3859f8fb0 Mon Sep 17 00:00:00 2001 From: Naz Date: Fri, 18 Feb 2022 10:12:25 +0700 Subject: [PATCH] Added default values for Stripe config in tests refs https://github.com/TryGhost/Toolbox/issues/214 - These variables need to be present in the configuration during the Ghost's boot time initialization, which caused a need to remember to mock settings cache before agent initialization. - By moving the values into default settings config it removes the need to do any work during test environment setup. Yey! - We should put default values in to test-specific settings-defaults.json In similar situations. Specifically, when we find a need to mock settings cache to be able to start Ghost instance in a certain state --- test/e2e-api/admin/members.test.js | 1 - test/e2e-api/members/signin.test.js | 6 ------ test/e2e-api/members/webhooks.test.js | 6 ------ test/utils/e2e-framework-mock-manager.js | 20 -------------------- test/utils/fixtures/default-settings.json | 4 ++-- 5 files changed, 2 insertions(+), 35 deletions(-) diff --git a/test/e2e-api/admin/members.test.js b/test/e2e-api/admin/members.test.js index 148489ddaf..0668c4ef3f 100644 --- a/test/e2e-api/admin/members.test.js +++ b/test/e2e-api/admin/members.test.js @@ -77,7 +77,6 @@ describe('Members API without Stripe', function () { describe('Members API', function () { before(async function () { - mockManager.setupStripe(); agent = await agentProvider.getAdminAPIAgent(); await fixtureManager.init('members'); await agent.loginAsOwner(); diff --git a/test/e2e-api/members/signin.test.js b/test/e2e-api/members/signin.test.js index 459b7bb07b..8c1c233dae 100644 --- a/test/e2e-api/members/signin.test.js +++ b/test/e2e-api/members/signin.test.js @@ -5,12 +5,6 @@ let membersAgent; describe('Members Signin', function () { before(async function () { - // Weird - most of the mocks happen after getting the agent - // but to mock stripe we want to fake the stripe keys in the settings. - // And it's initialised at boot - so mocking it before - // Probably wanna replace this with a settinfs fixture mock or smth?? - mockManager.setupStripe(); - const agents = await agentProvider.getAgentsForMembers(); membersAgent = agents.membersAgent; diff --git a/test/e2e-api/members/webhooks.test.js b/test/e2e-api/members/webhooks.test.js index 5207bb6816..8eddcaf86d 100644 --- a/test/e2e-api/members/webhooks.test.js +++ b/test/e2e-api/members/webhooks.test.js @@ -8,12 +8,6 @@ let adminAgent; describe('Members API', function () { before(async function () { - // Weird - most of the mocks happen after getting the agent - // but to mock stripe we want to fake the stripe keys in the settings. - // And it's initialised at boot - so mocking it before - // Probably wanna replace this with a settinfs fixture mock or smth?? - mockManager.setupStripe(); - const agents = await agentProvider.getAgentsForMembers(); membersAgent = agents.membersAgent; adminAgent = agents.adminAgent; diff --git a/test/utils/e2e-framework-mock-manager.js b/test/utils/e2e-framework-mock-manager.js index 5e8f2432bb..e720c4f76b 100644 --- a/test/utils/e2e-framework-mock-manager.js +++ b/test/utils/e2e-framework-mock-manager.js @@ -12,7 +12,6 @@ let emailCount = 0; // Mockable services const mailService = require('../../core/server/services/mail/index'); const labs = require('../../core/shared/labs'); -const settingsCache = require('../../core/shared/settings-cache'); const mockMail = () => { mocks.mail = sinon @@ -26,24 +25,6 @@ const mockStripe = () => { nock.disableNetConnect(); }; -const setupStripe = () => { - mocks.settings = sinon.stub(settingsCache, 'get').callsFake(function (key, ...args) { - if (key === 'stripe_connect_secret_key') { - return 'sk_test_blah'; - } - if (key === 'stripe_connect_publishable_key') { - return 'pk_test_blah'; - } - if (key === 'stripe_connect_account_name') { - return 'Test Account'; - } - if (key === 'theme_session_secret') { - return '1337_h4xx0r_53cR37'; - } - return settingsCache.get.wrappedMethod.call(settingsCache, key, ...args); - }); -}; - const mockLabsEnabled = (flag, alpha = true) => { // We assume we should enable alpha experiments unless explicitly told not to! if (!alpha) { @@ -114,7 +95,6 @@ const restore = () => { module.exports = { mockMail, - setupStripe, mockStripe, mockLabsEnabled, mockLabsDisabled, diff --git a/test/utils/fixtures/default-settings.json b/test/utils/fixtures/default-settings.json index 8091b60fb9..cce7f0520c 100644 --- a/test/utils/fixtures/default-settings.json +++ b/test/utils/fixtures/default-settings.json @@ -290,11 +290,11 @@ "type": "array" }, "stripe_connect_publishable_key": { - "defaultValue": null, + "defaultValue": "pk_test_for_stripe", "type": "string" }, "stripe_connect_secret_key": { - "defaultValue": null, + "defaultValue": "sk_test_for_stripe", "type": "string" }, "stripe_connect_livemode": {