From a400353881c5e20233c35ac35b3d92b8e9107f4b Mon Sep 17 00:00:00 2001 From: Aileen Nowak Date: Wed, 15 Feb 2023 09:23:31 +0200 Subject: [PATCH] Renamed milestone-emails to milestones no issue - The way we're going to implement milestones diverged from the original idea of handling email sending within the milestone-emails package, as we'll be sending events instead and will utilise the StaffService to listen to them and send the emails - This renames the package as well as the service in core itself and all relevant tests --- ghost/core/core/boot.js | 4 +-- .../MilestoneQueries.js | 0 .../{milestone-emails => milestones}/index.js | 0 .../service.js | 8 +++--- ghost/core/package.json | 2 +- ...tone-emails.test.js => milestones.test.js} | 24 ++++++++--------- .../services/milestone-emails/index.test.js | 13 ---------- .../MilestoneQueries.test.js | 16 +++++------- .../server/services/milestones/index.test.js | 11 ++++++++ ghost/milestone-emails/index.js | 1 - .../.eslintrc.js | 0 .../README.md | 4 +-- ghost/milestones/index.js | 1 + .../lib/InMemoryMilestoneRepository.js | 2 +- .../lib/Milestone.js | 0 .../lib/MilestonesService.js} | 2 +- .../lib/milestones.js} | 2 +- .../package.json | 4 +-- .../test/.eslintrc.js | 0 .../test/InMemoryMilestoneRepository.test.js | 0 .../test/Milestone.test.js | 0 .../test/MilestonesEmailService.test.js | 26 +++++++++---------- 22 files changed, 58 insertions(+), 62 deletions(-) rename ghost/core/core/server/services/{milestone-emails => milestones}/MilestoneQueries.js (100%) rename ghost/core/core/server/services/{milestone-emails => milestones}/index.js (100%) rename ghost/core/core/server/services/{milestone-emails => milestones}/service.js (89%) rename ghost/core/test/e2e-server/services/{milestone-emails.test.js => milestones.test.js} (90%) delete mode 100644 ghost/core/test/unit/server/services/milestone-emails/index.test.js rename ghost/core/test/unit/server/services/{milestone-emails => milestones}/MilestoneQueries.test.js (52%) create mode 100644 ghost/core/test/unit/server/services/milestones/index.test.js delete mode 100644 ghost/milestone-emails/index.js rename ghost/{milestone-emails => milestones}/.eslintrc.js (100%) rename ghost/{milestone-emails => milestones}/README.md (75%) create mode 100644 ghost/milestones/index.js rename ghost/{milestone-emails => milestones}/lib/InMemoryMilestoneRepository.js (96%) rename ghost/{milestone-emails => milestones}/lib/Milestone.js (100%) rename ghost/{milestone-emails/lib/MilestonesEmailService.js => milestones/lib/MilestonesService.js} (99%) rename ghost/{milestone-emails/lib/milestone-emails.js => milestones/lib/milestones.js} (53%) rename ghost/{milestone-emails => milestones}/package.json (92%) rename ghost/{milestone-emails => milestones}/test/.eslintrc.js (100%) rename ghost/{milestone-emails => milestones}/test/InMemoryMilestoneRepository.test.js (100%) rename ghost/{milestone-emails => milestones}/test/Milestone.test.js (100%) rename ghost/{milestone-emails => milestones}/test/MilestonesEmailService.test.js (94%) diff --git a/ghost/core/core/boot.js b/ghost/core/core/boot.js index 1c9ee4e600..6d12e9d667 100644 --- a/ghost/core/core/boot.js +++ b/ghost/core/core/boot.js @@ -370,8 +370,8 @@ async function initBackgroundServices({config}) { const updateCheck = require('./server/update-check'); updateCheck.scheduleRecurringJobs(); - const milestoneEmails = require('./server/services/milestone-emails'); - milestoneEmails.initAndRun(); + const milestonesService = require('./server/services/milestones'); + milestonesService.initAndRun(); debug('End: initBackgroundServices'); } diff --git a/ghost/core/core/server/services/milestone-emails/MilestoneQueries.js b/ghost/core/core/server/services/milestones/MilestoneQueries.js similarity index 100% rename from ghost/core/core/server/services/milestone-emails/MilestoneQueries.js rename to ghost/core/core/server/services/milestones/MilestoneQueries.js diff --git a/ghost/core/core/server/services/milestone-emails/index.js b/ghost/core/core/server/services/milestones/index.js similarity index 100% rename from ghost/core/core/server/services/milestone-emails/index.js rename to ghost/core/core/server/services/milestones/index.js diff --git a/ghost/core/core/server/services/milestone-emails/service.js b/ghost/core/core/server/services/milestones/service.js similarity index 89% rename from ghost/core/core/server/services/milestone-emails/service.js rename to ghost/core/core/server/services/milestones/service.js index 070691f3a2..ed71da3d74 100644 --- a/ghost/core/core/server/services/milestone-emails/service.js +++ b/ghost/core/core/server/services/milestones/service.js @@ -15,7 +15,7 @@ const getStripeLiveEnabled = () => { }; module.exports = { - /** @type {import('@tryghost/milestone-emails/lib/MilestonesEmailService')} */ + /** @type {import('@tryghost/milestones/lib/MilestonesService')} */ api: null, /** @@ -27,9 +27,9 @@ module.exports = { const MilestoneQueries = require('./MilestoneQueries'); const { - MilestonesEmailService, + MilestonesService, InMemoryMilestoneRepository - } = require('@tryghost/milestone-emails'); + } = require('@tryghost/milestones'); const config = require('../../../shared/config'); const milestonesConfig = config.get('milestones'); const {GhostMailer} = require('../mail'); @@ -38,7 +38,7 @@ module.exports = { const repository = new InMemoryMilestoneRepository(); const queries = new MilestoneQueries({db}); - this.api = new MilestonesEmailService({ + this.api = new MilestonesService({ mailer, repository, milestonesConfig, // avoid using getters and pass as JSON diff --git a/ghost/core/package.json b/ghost/core/package.json index c8f6fd75bd..8f568d8a55 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -112,7 +112,7 @@ "@tryghost/members-ssr": "0.0.0", "@tryghost/members-stripe-service": "0.0.0", "@tryghost/metrics": "1.0.20", - "@tryghost/milestone-emails": "0.0.0", + "@tryghost/milestones": "0.0.0", "@tryghost/minifier": "0.0.0", "@tryghost/mw-api-version-mismatch": "0.0.0", "@tryghost/mw-cache-control": "0.0.0", diff --git a/ghost/core/test/e2e-server/services/milestone-emails.test.js b/ghost/core/test/e2e-server/services/milestones.test.js similarity index 90% rename from ghost/core/test/e2e-server/services/milestone-emails.test.js rename to ghost/core/test/e2e-server/services/milestones.test.js index 18f4ee29c0..7d96eb741d 100644 --- a/ghost/core/test/e2e-server/services/milestone-emails.test.js +++ b/ghost/core/test/e2e-server/services/milestones.test.js @@ -5,7 +5,7 @@ const sinon = require('sinon'); const models = require('../../../core/server/models'); const moment = require('moment'); -const milestoneEmailsService = require('../../../core/server/services/milestone-emails'); +const milestonesService = require('../../../core/server/services/milestones'); let agent; let counter = 0; @@ -137,7 +137,7 @@ async function createFreeMembers(amount, amountImported = 0) { await Promise.all(members); } -describe('Milestone Emails Service', function () { +describe('Milestones Service', function () { const milestonesConfig = { arr: [{currency: 'usd', values: [100, 150]}], members: [10, 20, 30] @@ -153,7 +153,7 @@ describe('Milestone Emails Service', function () { sinon.createSandbox(); // TODO: stub out stripe mode // stripeModeStub = sinon.stub().returns(true); - // milestoneEmailsService.__set__('getStripeLiveEnabled', stripeModeStub); + // milestonesService.__set__('getStripeLiveEnabled', stripeModeStub); configUtils.set('milestones', milestonesConfig); mockManager.mockLabsEnabled('milestoneEmails'); }); @@ -165,29 +165,29 @@ describe('Milestone Emails Service', function () { }); it('Inits milestone service', async function () { - await milestoneEmailsService.init(); + await milestonesService.init(); - assert.ok(milestoneEmailsService.api); + assert.ok(milestonesService.api); }); it('Runs ARR and Members milestone jobs', async function () { mockManager.mockSetting('stripe_connect_publishable_key', 'pk_live_89843uihsidfh98832uo8ri'); // No ARR and no members - const firstRun = await milestoneEmailsService.initAndRun(); + const firstRun = await milestonesService.initAndRun(); assert(firstRun.members === undefined); assert(firstRun.arr === undefined); await createFreeMembers(7); await createMemberWithSubscription('year', 5000, 'usd', '2000-01-10'); await createMemberWithSubscription('month', 100, 'usd', '2000-01-10'); - const secondRun = await milestoneEmailsService.initAndRun(); + const secondRun = await milestonesService.initAndRun(); assert(secondRun.members === undefined); assert(secondRun.arr === undefined); // Reached the first milestone for members await createFreeMembers(1); - const thirdRun = await milestoneEmailsService.initAndRun(); + const thirdRun = await milestonesService.initAndRun(); assert(thirdRun.members.value === 10); assert(thirdRun.members.emailSentAt !== undefined); assert(thirdRun.arr === undefined); @@ -197,7 +197,7 @@ describe('Milestone Emails Service', function () { // will be created await createMemberWithSubscription('month', 500, 'usd', '2000-01-10'); await createMemberWithSubscription('month', 500, 'eur', '2000-01-10'); - const fourthRun = await milestoneEmailsService.initAndRun(); + const fourthRun = await milestonesService.initAndRun(); assert(fourthRun.members === undefined); assert(fourthRun.arr.value === 100); assert(fourthRun.arr.emailSentAt !== undefined); @@ -209,7 +209,7 @@ describe('Milestone Emails Service', function () { await createFreeMembers(10, 1); await createMemberWithSubscription('month', 1000, 'usd', '2023-01-10'); - const result = await milestoneEmailsService.initAndRun(); + const result = await milestonesService.initAndRun(); assert(result.members.value === 20); assert(result.members.emailSentAt === null); @@ -220,7 +220,7 @@ describe('Milestone Emails Service', function () { it('Does not run when milestoneEmails labs flag is not set', async function () { mockManager.mockLabsDisabled('milestoneEmails'); - const result = await milestoneEmailsService.initAndRun(); + const result = await milestonesService.initAndRun(); assert(result === undefined); }); @@ -229,7 +229,7 @@ describe('Milestone Emails Service', function () { mockManager.mockSetting('stripe_connect_publishable_key', 'pk_test_89843uihsidfh98832uo8ri'); await createFreeMembers(10); - const result = await milestoneEmailsService.initAndRun(); + const result = await milestonesService.initAndRun(); assert(result.members.value === 30); assert(result.members.emailSentAt !== undefined); assert(result.arr === undefined); diff --git a/ghost/core/test/unit/server/services/milestone-emails/index.test.js b/ghost/core/test/unit/server/services/milestone-emails/index.test.js deleted file mode 100644 index 5cad890afc..0000000000 --- a/ghost/core/test/unit/server/services/milestone-emails/index.test.js +++ /dev/null @@ -1,13 +0,0 @@ -const assert = require('assert'); - -describe('Milestone Emails Service', function () { - let milestoneEmails; - - describe('Milestone Emails Service', function () { - it('Provides expected public API', async function () { - milestoneEmails = require('../../../../../core/server/services/milestone-emails'); - - assert.ok(milestoneEmails.initAndRun); - }); - }); -}); diff --git a/ghost/core/test/unit/server/services/milestone-emails/MilestoneQueries.test.js b/ghost/core/test/unit/server/services/milestones/MilestoneQueries.test.js similarity index 52% rename from ghost/core/test/unit/server/services/milestone-emails/MilestoneQueries.test.js rename to ghost/core/test/unit/server/services/milestones/MilestoneQueries.test.js index 492174f165..d154d23e1d 100644 --- a/ghost/core/test/unit/server/services/milestone-emails/MilestoneQueries.test.js +++ b/ghost/core/test/unit/server/services/milestones/MilestoneQueries.test.js @@ -23,15 +23,13 @@ describe('MilestoneQueries', function () { }); }); - describe('Milestone Emails Service', function () { - it('Provides expected public API', async function () { - const MilestoneQueries = require('../../../../../core/server/services/milestone-emails/MilestoneQueries'); - milestoneQueries = new MilestoneQueries({db: knexMock}); + it('Provides expected public API', async function () { + const MilestoneQueries = require('../../../../../core/server/services/milestones/MilestoneQueries'); + milestoneQueries = new MilestoneQueries({db: knexMock}); - assert.ok(milestoneQueries.getMembersCount); - assert.ok(milestoneQueries.getARR); - assert.ok(milestoneQueries.hasImportedMembersInPeriod); - assert.ok(milestoneQueries.getDefaultCurrency); - }); + assert.ok(milestoneQueries.getMembersCount); + assert.ok(milestoneQueries.getARR); + assert.ok(milestoneQueries.hasImportedMembersInPeriod); + assert.ok(milestoneQueries.getDefaultCurrency); }); }); diff --git a/ghost/core/test/unit/server/services/milestones/index.test.js b/ghost/core/test/unit/server/services/milestones/index.test.js new file mode 100644 index 0000000000..66e614a5dd --- /dev/null +++ b/ghost/core/test/unit/server/services/milestones/index.test.js @@ -0,0 +1,11 @@ +const assert = require('assert'); + +describe('Milestones Service', function () { + let milestonesService; + + it('Provides expected public API', async function () { + milestonesService = require('../../../../../core/server/services/milestones'); + + assert.ok(milestonesService.initAndRun); + }); +}); diff --git a/ghost/milestone-emails/index.js b/ghost/milestone-emails/index.js deleted file mode 100644 index d9806ad66d..0000000000 --- a/ghost/milestone-emails/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./lib/milestone-emails'); diff --git a/ghost/milestone-emails/.eslintrc.js b/ghost/milestones/.eslintrc.js similarity index 100% rename from ghost/milestone-emails/.eslintrc.js rename to ghost/milestones/.eslintrc.js diff --git a/ghost/milestone-emails/README.md b/ghost/milestones/README.md similarity index 75% rename from ghost/milestone-emails/README.md rename to ghost/milestones/README.md index d390692e45..0864a3b3e3 100644 --- a/ghost/milestone-emails/README.md +++ b/ghost/milestones/README.md @@ -1,6 +1,6 @@ -# Milestone Emails +# Milestones -Checking milestone goals and sending emails +Checking milestone defined milestone goals and sending events when achieved ## Usage diff --git a/ghost/milestones/index.js b/ghost/milestones/index.js new file mode 100644 index 0000000000..712e6a45ff --- /dev/null +++ b/ghost/milestones/index.js @@ -0,0 +1 @@ +module.exports = require('./lib/milestones'); diff --git a/ghost/milestone-emails/lib/InMemoryMilestoneRepository.js b/ghost/milestones/lib/InMemoryMilestoneRepository.js similarity index 96% rename from ghost/milestone-emails/lib/InMemoryMilestoneRepository.js rename to ghost/milestones/lib/InMemoryMilestoneRepository.js index e35c7d4b02..92c862c3ba 100644 --- a/ghost/milestone-emails/lib/InMemoryMilestoneRepository.js +++ b/ghost/milestones/lib/InMemoryMilestoneRepository.js @@ -1,6 +1,6 @@ /** * @typedef {import('./Milestone')} Milestone - * @typedef {import('./MilestonesEmailService').IMilestoneRepository} IMilestoneRepository + * @typedef {import('./MilestonesService').IMilestoneRepository} IMilestoneRepository */ /** diff --git a/ghost/milestone-emails/lib/Milestone.js b/ghost/milestones/lib/Milestone.js similarity index 100% rename from ghost/milestone-emails/lib/Milestone.js rename to ghost/milestones/lib/Milestone.js diff --git a/ghost/milestone-emails/lib/MilestonesEmailService.js b/ghost/milestones/lib/MilestonesService.js similarity index 99% rename from ghost/milestone-emails/lib/MilestonesEmailService.js rename to ghost/milestones/lib/MilestonesService.js index 216b075ff1..0952a61932 100644 --- a/ghost/milestone-emails/lib/MilestonesEmailService.js +++ b/ghost/milestones/lib/MilestonesService.js @@ -30,7 +30,7 @@ const Milestone = require('./Milestone'); * @prop {number[]} milestonesConfig.members */ -module.exports = class MilestonesEmailService { +module.exports = class MilestonesService { /** @type {IMilestoneRepository} */ #repository; diff --git a/ghost/milestone-emails/lib/milestone-emails.js b/ghost/milestones/lib/milestones.js similarity index 53% rename from ghost/milestone-emails/lib/milestone-emails.js rename to ghost/milestones/lib/milestones.js index eb85b9bc48..a1c99a8634 100644 --- a/ghost/milestone-emails/lib/milestone-emails.js +++ b/ghost/milestones/lib/milestones.js @@ -1,2 +1,2 @@ module.exports.InMemoryMilestoneRepository = require('./InMemoryMilestoneRepository'); -module.exports.MilestonesEmailService = require('./MilestonesEmailService'); +module.exports.MilestonesService = require('./MilestonesService'); diff --git a/ghost/milestone-emails/package.json b/ghost/milestones/package.json similarity index 92% rename from ghost/milestone-emails/package.json rename to ghost/milestones/package.json index 284455549b..ff97105924 100644 --- a/ghost/milestone-emails/package.json +++ b/ghost/milestones/package.json @@ -1,7 +1,7 @@ { - "name": "@tryghost/milestone-emails", + "name": "@tryghost/milestones", "version": "0.0.0", - "repository": "https://github.com/TryGhost/Ghost/tree/main/packages/milestone-emails", + "repository": "https://github.com/TryGhost/Ghost/tree/main/packages/milestones", "author": "Ghost Foundation", "private": true, "main": "index.js", diff --git a/ghost/milestone-emails/test/.eslintrc.js b/ghost/milestones/test/.eslintrc.js similarity index 100% rename from ghost/milestone-emails/test/.eslintrc.js rename to ghost/milestones/test/.eslintrc.js diff --git a/ghost/milestone-emails/test/InMemoryMilestoneRepository.test.js b/ghost/milestones/test/InMemoryMilestoneRepository.test.js similarity index 100% rename from ghost/milestone-emails/test/InMemoryMilestoneRepository.test.js rename to ghost/milestones/test/InMemoryMilestoneRepository.test.js diff --git a/ghost/milestone-emails/test/Milestone.test.js b/ghost/milestones/test/Milestone.test.js similarity index 100% rename from ghost/milestone-emails/test/Milestone.test.js rename to ghost/milestones/test/Milestone.test.js diff --git a/ghost/milestone-emails/test/MilestonesEmailService.test.js b/ghost/milestones/test/MilestonesEmailService.test.js similarity index 94% rename from ghost/milestone-emails/test/MilestonesEmailService.test.js rename to ghost/milestones/test/MilestonesEmailService.test.js index ce78c9d69e..a4a320bbe8 100644 --- a/ghost/milestone-emails/test/MilestonesEmailService.test.js +++ b/ghost/milestones/test/MilestonesEmailService.test.js @@ -1,11 +1,11 @@ const assert = require('assert'); const { - MilestonesEmailService, + MilestonesService, InMemoryMilestoneRepository } = require('../index'); const Milestone = require('../lib/Milestone'); -describe('MilestonesEmailService', function () { +describe('MilestonesService', function () { let repository; const milestonesConfig = { @@ -35,7 +35,7 @@ describe('MilestonesEmailService', function () { it('Adds first ARR milestone and sends email', async function () { repository = new InMemoryMilestoneRepository(); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, mailer: { // TODO: make this a stub @@ -92,7 +92,7 @@ describe('MilestonesEmailService', function () { await repository.save(milestoneTwo); await repository.save(milestoneThree); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, mailer: { // TODO: make this a stub @@ -124,7 +124,7 @@ describe('MilestonesEmailService', function () { it('Does not add ARR milestone for out of scope currency', async function () { repository = new InMemoryMilestoneRepository(); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, // TODO: make this a stub mailer: { @@ -159,7 +159,7 @@ describe('MilestonesEmailService', function () { await repository.save(milestone); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, mailer: { // TODO: make this a stub @@ -186,7 +186,7 @@ describe('MilestonesEmailService', function () { it('Adds ARR milestone but does not send email if imported members are detected', async function () { repository = new InMemoryMilestoneRepository(); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, mailer: { // TODO: make this a stub @@ -228,7 +228,7 @@ describe('MilestonesEmailService', function () { await repository.save(milestone); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, mailer: { // TODO: make this a stub @@ -260,7 +260,7 @@ describe('MilestonesEmailService', function () { it('Adds first Members milestone and sends email', async function () { repository = new InMemoryMilestoneRepository(); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, mailer: { // TODO: make this a stub @@ -314,7 +314,7 @@ describe('MilestonesEmailService', function () { await repository.save(milestoneTwo); await repository.save(milestoneThree); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, mailer: { // TODO: make this a stub @@ -352,7 +352,7 @@ describe('MilestonesEmailService', function () { await repository.save(milestone); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, mailer: { // TODO: make this a stub @@ -386,7 +386,7 @@ describe('MilestonesEmailService', function () { await repository.save(milestone); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, mailer: { // TODO: make this a stub @@ -426,7 +426,7 @@ describe('MilestonesEmailService', function () { await repository.save(milestone); - const milestoneEmailService = new MilestonesEmailService({ + const milestoneEmailService = new MilestonesService({ repository, mailer: { // TODO: make this a stub