mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 11:55:01 +03:00
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
This commit is contained in:
parent
d820b961b0
commit
74a65f3b1c
@ -37,7 +37,7 @@ describe('Slack Notifications Service', function () {
|
||||
emailSentAt: new Date()
|
||||
},
|
||||
meta: {
|
||||
currentARR: 105
|
||||
currentValue: 105
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -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});
|
||||
}
|
||||
|
@ -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 () {
|
||||
|
@ -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<void>}
|
||||
*/
|
||||
@ -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})}`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -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'
|
||||
}
|
||||
});
|
||||
|
@ -81,7 +81,7 @@ describe('SlackNotificationsService', function () {
|
||||
emailSentAt: new Date()
|
||||
},
|
||||
meta: {
|
||||
currentARR: 1398
|
||||
currentValue: 1398
|
||||
}
|
||||
}));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user