mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #16835 from overleaf/bg-google-spam-temporarily-disable-emails
Temporarily disable onboarding emails GitOrigin-RevId: a1967bc793fcd7b3b90f812fb8c9b9d83f704093
This commit is contained in:
parent
9702b36c64
commit
f9db088d57
5 changed files with 85 additions and 43 deletions
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -397,6 +397,7 @@ module.exports = {
|
|||
|
||||
enableSubscriptions: false,
|
||||
restrictedCountries: [],
|
||||
enableOnboardingEmails: process.env.ENABLE_ONBOARDING_EMAILS === 'true',
|
||||
|
||||
enabledLinkedFileTypes: (process.env.ENABLED_LINKED_FILE_TYPES || '').split(
|
||||
','
|
||||
|
|
|
@ -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 },
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue