From 74a65f3b1c9cb5eac19e50beed975db59fe5abeb Mon Sep 17 00:00:00 2001 From: Aileen Nowak Date: Thu, 23 Feb 2023 16:18:39 +0200 Subject: [PATCH] Simplyfied milestone event meta data no issue - Reduced the amount of diffeerent properties by not populating a `currentARR` and `currentMembers` fields, but use a `currentValue` instead. - The type of milestone can still be determined by its `type` property, so we actually don't need two different props here --- .../server/services/slack-notifications/index.test.js | 2 +- .../test/unit/server/services/staff/index.test.js | 3 +-- ghost/milestones/lib/MilestonesService.js | 6 +++--- ghost/milestones/test/MilestonesService.test.js | 4 ++-- ghost/slack-notifications/lib/SlackNotifications.js | 11 +++++------ .../lib/SlackNotificationsService.js | 3 +-- .../test/SlackNotifications.test.js | 4 ++-- .../test/SlackNotificationsService.test.js | 2 +- 8 files changed, 16 insertions(+), 19 deletions(-) diff --git a/ghost/core/test/unit/server/services/slack-notifications/index.test.js b/ghost/core/test/unit/server/services/slack-notifications/index.test.js index dff6c1d3c1..7fc745dc40 100644 --- a/ghost/core/test/unit/server/services/slack-notifications/index.test.js +++ b/ghost/core/test/unit/server/services/slack-notifications/index.test.js @@ -37,7 +37,7 @@ describe('Slack Notifications Service', function () { emailSentAt: new Date() }, meta: { - currentARR: 105 + currentValue: 105 } })); diff --git a/ghost/core/test/unit/server/services/staff/index.test.js b/ghost/core/test/unit/server/services/staff/index.test.js index 45161df33c..ae23bafad6 100644 --- a/ghost/core/test/unit/server/services/staff/index.test.js +++ b/ghost/core/test/unit/server/services/staff/index.test.js @@ -246,13 +246,12 @@ describe('Staff Service:', function () { milestone: { type: 'arr', currency: 'usd', - name: 'arr-100-usd', value: 100, createdAt: new Date(), emailSentAt: new Date() }, meta: { - currentARR: 105 + currentValue: 105 } })); diff --git a/ghost/milestones/lib/MilestonesService.js b/ghost/milestones/lib/MilestonesService.js index 62870828aa..e9adff32e6 100644 --- a/ghost/milestones/lib/MilestonesService.js +++ b/ghost/milestones/lib/MilestonesService.js @@ -178,7 +178,7 @@ module.exports = class MilestonesService { if (milestone?.meta) { // Check how much the value currently differs from the milestone - const difference = (milestone?.meta?.currentMembers || milestone?.meta?.currentARR) - milestone.value; + const difference = milestone?.meta?.currentValue - milestone.value; const differenceInPercentage = difference / milestone.value; emailTooClose = differenceInPercentage >= this.#milestonesConfig.maxPercentageFromMilestone; @@ -227,7 +227,7 @@ module.exports = class MilestonesService { if (!milestoneExists && (!latestMilestone || milestone > latestMilestone.value)) { const meta = { - currentARR: currentARRForCurrency.arr + currentValue: currentARRForCurrency.arr }; return await this.#saveMileStoneAndSendEmail({value: milestone, type: 'arr', currency: defaultCurrency, meta}); } @@ -258,7 +258,7 @@ module.exports = class MilestonesService { if (!milestoneExists && (!latestMembersMilestone || milestone > latestMembersMilestone.value)) { const meta = { - currentMembers: membersCount + currentValue: membersCount }; return await this.#saveMileStoneAndSendEmail({value: milestone, type: 'members', meta}); } diff --git a/ghost/milestones/test/MilestonesService.test.js b/ghost/milestones/test/MilestonesService.test.js index 6bb884bad6..4a84c07d3d 100644 --- a/ghost/milestones/test/MilestonesService.test.js +++ b/ghost/milestones/test/MilestonesService.test.js @@ -74,7 +74,7 @@ describe('MilestonesService', function () { const domainEventSpyResult = domainEventSpy.getCall(0).args[0]; assert(domainEventSpy.calledOnce === true); assert(domainEventSpyResult.data.milestone); - assert(domainEventSpyResult.data.meta.currentARR === 1298); + assert(domainEventSpyResult.data.meta.currentValue === 1298); }); it('Adds next ARR milestone and sends email', async function () { @@ -134,7 +134,7 @@ describe('MilestonesService', function () { assert(domainEventSpy.callCount === 4); // we have just created a new milestone const domainEventSpyResult = domainEventSpy.getCall(3).args[0]; assert(domainEventSpyResult.data.milestone); - assert(domainEventSpyResult.data.meta.currentARR === 10001); + assert(domainEventSpyResult.data.meta.currentValue === 10001); }); it('Does not add ARR milestone for out of scope currency', async function () { diff --git a/ghost/slack-notifications/lib/SlackNotifications.js b/ghost/slack-notifications/lib/SlackNotifications.js index 7aedd832cc..4c6278d73b 100644 --- a/ghost/slack-notifications/lib/SlackNotifications.js +++ b/ghost/slack-notifications/lib/SlackNotifications.js @@ -50,8 +50,7 @@ class SlackNotifications { * @param {import('@tryghost/milestones/lib/InMemoryMilestoneRepository').Milestone} eventData.milestone * @param {object} [eventData.meta] * @param {'import'|'email'|'tooFar'} [eventData.meta.reason] - * @param {number} [eventData.meta.currentARR] - * @param {number} [eventData.meta.currentMembers] + * @param {number} [eventData.meta.currentValue] * * @returns {Promise} */ @@ -79,10 +78,10 @@ class SlackNotifications { ] }; - if (meta?.currentARR) { + if (meta?.currentValue) { valueSection.fields.push({ type: 'mrkdwn', - text: `*Current ARR:*\n${this.#getFormattedAmount({amount: meta.currentARR, currency: milestone?.currency})}` + text: `*Current ARR:*\n${this.#getFormattedAmount({amount: meta.currentValue, currency: milestone?.currency})}` }); } } else { @@ -95,10 +94,10 @@ class SlackNotifications { } ] }; - if (meta?.currentMembers) { + if (meta?.currentValue) { valueSection.fields.push({ type: 'mrkdwn', - text: `*Current Members:*\n${this.#getFormattedAmount({amount: meta.currentMembers})}` + text: `*Current Members:*\n${this.#getFormattedAmount({amount: meta.currentValue})}` }); } } diff --git a/ghost/slack-notifications/lib/SlackNotificationsService.js b/ghost/slack-notifications/lib/SlackNotificationsService.js index 3d1a82dc32..0ab7bb4c80 100644 --- a/ghost/slack-notifications/lib/SlackNotificationsService.js +++ b/ghost/slack-notifications/lib/SlackNotificationsService.js @@ -7,8 +7,7 @@ const {MilestoneCreatedEvent} = require('@tryghost/milestones'); /** * @typedef {object} meta * @prop {'import'|'email'} [reason] - * @prop {number} [currentARR] - * @prop {number} [currentMembers] + * @prop {number} [currentValue] */ /** diff --git a/ghost/slack-notifications/test/SlackNotifications.test.js b/ghost/slack-notifications/test/SlackNotifications.test.js index 41a7375b74..2677410ec4 100644 --- a/ghost/slack-notifications/test/SlackNotifications.test.js +++ b/ghost/slack-notifications/test/SlackNotifications.test.js @@ -115,7 +115,7 @@ describe('SlackNotifications', function () { value: 50000 }, meta: { - currentMembers: 59857, + currentValue: 59857, reason: 'import' } }); @@ -184,7 +184,7 @@ describe('SlackNotifications', function () { value: 1000 }, meta: { - currentARR: 1005, + currentValue: 1005, reason: 'email' } }); diff --git a/ghost/slack-notifications/test/SlackNotificationsService.test.js b/ghost/slack-notifications/test/SlackNotificationsService.test.js index e4f942ae9a..592b593763 100644 --- a/ghost/slack-notifications/test/SlackNotificationsService.test.js +++ b/ghost/slack-notifications/test/SlackNotificationsService.test.js @@ -81,7 +81,7 @@ describe('SlackNotificationsService', function () { emailSentAt: new Date() }, meta: { - currentARR: 1398 + currentValue: 1398 } }));