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,6 +14,7 @@ const SubscriptionEmailHandler = {
if (!plan) {
throw new Error('unknown paid plan: ' + planCode)
}
if (Settings.enableOnboardingEmails) {
const emailOptions = {
to: user.email,
sendingUser_id: userId,
@ -20,6 +22,7 @@ const SubscriptionEmailHandler = {
features: plan.features,
}
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,11 +29,28 @@ describe('SubscriptionEmailHandler', function () {
features: { collaborators: 42 },
}),
}),
'@overleaf/settings': (this.Settings = {
enableOnboardingEmails: true,
}),
},
})
})
it('sends trail onboarding email', async function () {
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
})
})
describe('when onboarding emails are enabled', function () {
it('sends trial onboarding email', async function () {
await this.SubscriptionEmailHandler.sendTrialOnboardingEmail(
this.userId,
'foo-plan-code'
@ -53,3 +70,4 @@ describe('SubscriptionEmailHandler', function () {
])
})
})
})

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,8 +71,23 @@ describe('UserOnboardingEmailManager', function () {
})
describe('sendOnboardingEmail', function () {
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)
await this.UserOnboardingEmailManager.sendOnboardingEmail(
this.fakeUserId
)
expect(this.EmailHandler.promises.sendEmail).to.have.been.calledWith(
'userOnboardingEmail',
{
@ -91,3 +109,4 @@ describe('UserOnboardingEmailManager', function () {
})
})
})
})