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-02-01 09:03:30 +00:00
committed by Copybot
parent 9702b36c64
commit f9db088d57
5 changed files with 83 additions and 41 deletions
@@ -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 } }
)
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' },
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
})
})
})