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
This commit is contained in:
parent
41e4132a17
commit
a400353881
@ -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');
|
||||
}
|
||||
|
@ -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
|
@ -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",
|
||||
|
@ -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);
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
@ -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);
|
||||
});
|
||||
});
|
@ -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);
|
||||
});
|
||||
});
|
@ -1 +0,0 @@
|
||||
module.exports = require('./lib/milestone-emails');
|
@ -1,6 +1,6 @@
|
||||
# Milestone Emails
|
||||
# Milestones
|
||||
|
||||
Checking milestone goals and sending emails
|
||||
Checking milestone defined milestone goals and sending events when achieved
|
||||
|
||||
|
||||
## Usage
|
1
ghost/milestones/index.js
Normal file
1
ghost/milestones/index.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./lib/milestones');
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @typedef {import('./Milestone')} Milestone
|
||||
* @typedef {import('./MilestonesEmailService').IMilestoneRepository} IMilestoneRepository
|
||||
* @typedef {import('./MilestonesService').IMilestoneRepository} IMilestoneRepository
|
||||
*/
|
||||
|
||||
/**
|
@ -30,7 +30,7 @@ const Milestone = require('./Milestone');
|
||||
* @prop {number[]} milestonesConfig.members
|
||||
*/
|
||||
|
||||
module.exports = class MilestonesEmailService {
|
||||
module.exports = class MilestonesService {
|
||||
/** @type {IMilestoneRepository} */
|
||||
#repository;
|
||||
|
@ -1,2 +1,2 @@
|
||||
module.exports.InMemoryMilestoneRepository = require('./InMemoryMilestoneRepository');
|
||||
module.exports.MilestonesEmailService = require('./MilestonesEmailService');
|
||||
module.exports.MilestonesService = require('./MilestonesService');
|
@ -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",
|
@ -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
|
Loading…
Reference in New Issue
Block a user