Merge pull request #16835 from overleaf/bg-google-spam-temporarily-disable-emails

Temporarily disable onboarding emails

GitOrigin-RevId: a1967bc793fcd7b3b90f812fb8c9b9d83f704093
This commit is contained in:
Brian Gough 2024-01-31 10:47:04 +00:00 committed by Copybot
parent 9702b36c64
commit f9db088d57
5 changed files with 85 additions and 43 deletions

View file

@ -2,6 +2,7 @@ const EmailHandler = require('../Email/EmailHandler')
const UserGetter = require('../User/UserGetter')
require('./SubscriptionEmailBuilder')
const PlansLocator = require('./PlansLocator')
const Settings = require('@overleaf/settings')
const SubscriptionEmailHandler = {
async sendTrialOnboardingEmail(userId, planCode) {
@ -13,13 +14,15 @@ const SubscriptionEmailHandler = {
if (!plan) {
throw new Error('unknown paid plan: ' + planCode)
}
const emailOptions = {
to: user.email,
sendingUser_id: userId,
planName: plan.name,
features: plan.features,
if (Settings.enableOnboardingEmails) {
const emailOptions = {
to: user.email,
sendingUser_id: userId,
planName: plan.name,
features: plan.features,
}
await EmailHandler.promises.sendEmail('trialOnboarding', emailOptions)
}
await EmailHandler.promises.sendEmail('trialOnboarding', emailOptions)
},
}

View file

@ -2,6 +2,7 @@ const Queues = require('../../infrastructure/Queues')
const EmailHandler = require('../Email/EmailHandler')
const UserUpdater = require('./UserUpdater')
const UserGetter = require('./UserGetter')
const Settings = require('@overleaf/settings')
const ONE_DAY_MS = 24 * 60 * 60 * 1000
@ -15,7 +16,7 @@ async function scheduleOnboardingEmail(user) {
async function sendOnboardingEmail(userId) {
const user = await UserGetter.promises.getUser({ _id: userId }, { email: 1 })
if (user) {
if (Settings.enableOnboardingEmails && user) {
await EmailHandler.promises.sendEmail('userOnboardingEmail', {
to: user.email,
})

View file

@ -397,6 +397,7 @@ module.exports = {
enableSubscriptions: false,
restrictedCountries: [],
enableOnboardingEmails: process.env.ENABLE_ONBOARDING_EMAILS === 'true',
enabledLinkedFileTypes: (process.env.ENABLED_LINKED_FILE_TYPES || '').split(
','

View file

@ -29,27 +29,45 @@ describe('SubscriptionEmailHandler', function () {
features: { collaborators: 42 },
}),
}),
'@overleaf/settings': (this.Settings = {
enableOnboardingEmails: true,
}),
},
})
})
it('sends trail onboarding email', async function () {
await this.SubscriptionEmailHandler.sendTrialOnboardingEmail(
this.userId,
'foo-plan-code'
)
describe('when onboarding emails are disabled', function () {
beforeEach(function () {
this.Settings.enableOnboardingEmails = false
})
it('does not send a trial onboarding email', async function () {
await this.SubscriptionEmailHandler.sendTrialOnboardingEmail(
this.userId,
'foo-plan-code'
)
expect(this.EmailHandler.promises.sendEmail).to.not.have.been.called
})
})
expect(this.PlansLocator.findLocalPlanInSettings).to.have.been.calledWith(
'foo-plan-code'
)
expect(this.EmailHandler.promises.sendEmail.lastCall.args).to.deep.equal([
'trialOnboarding',
{
to: this.email,
sendingUser_id: this.userId,
planName: 'foo',
features: { collaborators: 42 },
},
])
describe('when onboarding emails are enabled', function () {
it('sends trial onboarding email', async function () {
await this.SubscriptionEmailHandler.sendTrialOnboardingEmail(
this.userId,
'foo-plan-code'
)
expect(this.PlansLocator.findLocalPlanInSettings).to.have.been.calledWith(
'foo-plan-code'
)
expect(this.EmailHandler.promises.sendEmail.lastCall.args).to.deep.equal([
'trialOnboarding',
{
to: this.email,
sendingUser_id: this.userId,
planName: 'foo',
features: { collaborators: 42 },
},
])
})
})
})

View file

@ -49,6 +49,9 @@ describe('UserOnboardingEmailManager', function () {
'../Email/EmailHandler': this.EmailHandler,
'./UserGetter': this.UserGetter,
'./UserUpdater': this.UserUpdater,
'@overleaf/settings': (this.Settings = {
enableOnboardingEmails: true,
}),
},
})
})
@ -68,26 +71,42 @@ describe('UserOnboardingEmailManager', function () {
})
describe('sendOnboardingEmail', function () {
it('should send onboarding email and update user', async function () {
await this.UserOnboardingEmailManager.sendOnboardingEmail(this.fakeUserId)
expect(this.EmailHandler.promises.sendEmail).to.have.been.calledWith(
'userOnboardingEmail',
{
to: this.fakeUserEmail,
}
)
expect(this.UserUpdater.promises.updateUser).to.have.been.calledWith(
this.fakeUserId,
{ $set: { onboardingEmailSentAt: sinon.match.date } }
)
})
it('should stop if user is not found', async function () {
await this.UserOnboardingEmailManager.sendOnboardingEmail({
data: { userId: 'deleted-user' },
describe('when onboarding emails are disabled', function () {
beforeEach(function () {
this.Settings.enableOnboardingEmails = false
})
it('should not send onboarding email', async function () {
await this.UserOnboardingEmailManager.sendOnboardingEmail(
this.fakeUserId
)
expect(this.EmailHandler.promises.sendEmail).not.to.have.been.called
expect(this.UserUpdater.promises.updateUser).not.to.have.been.called
})
})
describe('when onboarding emails are enabled', function () {
it('should send onboarding email and update user', async function () {
await this.UserOnboardingEmailManager.sendOnboardingEmail(
this.fakeUserId
)
expect(this.EmailHandler.promises.sendEmail).to.have.been.calledWith(
'userOnboardingEmail',
{
to: this.fakeUserEmail,
}
)
expect(this.UserUpdater.promises.updateUser).to.have.been.calledWith(
this.fakeUserId,
{ $set: { onboardingEmailSentAt: sinon.match.date } }
)
})
it('should stop if user is not found', async function () {
await this.UserOnboardingEmailManager.sendOnboardingEmail({
data: { userId: 'deleted-user' },
})
expect(this.EmailHandler.promises.sendEmail).not.to.have.been.called
expect(this.UserUpdater.promises.updateUser).not.to.have.been.called
})
expect(this.EmailHandler.promises.sendEmail).not.to.have.been.called
expect(this.UserUpdater.promises.updateUser).not.to.have.been.called
})
})
})