From a6be3179fd2d2652a987bb079576e6e5b76fd635 Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Tue, 29 Sep 2020 09:06:02 -0500 Subject: [PATCH] Merge pull request #3215 from overleaf/jel-new-cta-email-registered Convert registered email to new email handling GitOrigin-RevId: a2f99c65bdaee1287a0353e66cfc5a7768fdbcc8 --- .../app/src/Features/Email/EmailBuilder.js | 23 +++++------ .../test/unit/src/Email/EmailBuilderTests.js | 39 +++++++++++++++++++ 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/services/web/app/src/Features/Email/EmailBuilder.js b/services/web/app/src/Features/Email/EmailBuilder.js index 775291c12d..a7ddc1363c 100644 --- a/services/web/app/src/Features/Email/EmailBuilder.js +++ b/services/web/app/src/Features/Email/EmailBuilder.js @@ -184,23 +184,24 @@ function buildEmail(templateName, opts) { const templates = {} -templates.registered = CTAEmailTemplate({ +templates.registered = ctaTemplate({ subject() { return `Activate your ${settings.appName} Account` }, message(opts) { - return `\ -Congratulations, you've just had an account created for you on ${ - settings.appName - } with the email address '${_.escape(opts.to)}'. - -Click here to set your password and log in:\ -` + return [ + `Congratulations, you've just had an account created for you on ${ + settings.appName + } with the email address '${_.escape(opts.to)}'.`, + 'Click here to set your password and log in:' + ] }, secondaryMessage() { - return `If you have any questions or problems, please contact ${ - settings.adminEmail - }` + return [ + `If you have any questions or problems, please contact ${ + settings.adminEmail + }` + ] }, ctaText() { return 'Set password' diff --git a/services/web/test/unit/src/Email/EmailBuilderTests.js b/services/web/test/unit/src/Email/EmailBuilderTests.js index be7b834c02..232bcda83c 100644 --- a/services/web/test/unit/src/Email/EmailBuilderTests.js +++ b/services/web/test/unit/src/Email/EmailBuilderTests.js @@ -429,6 +429,45 @@ describe('EmailBuilder', function() { }) }) }) + + describe('registered', function() { + before(function() { + this.emailAddress = 'example@overleaf.com' + this.opts = { + to: this.emailAddress, + setNewPasswordUrl: `${ + this.settings.siteUrl + }/user/activate?token=aToken123&user_id=aUserId123` + } + this.email = this.EmailBuilder.buildEmail('registered', this.opts) + }) + + it('should build the email', function() { + expect(this.email.html).to.exist + expect(this.email.text).to.exist + }) + + describe('HTML email', function() { + it('should include a CTA button and a fallback CTA link', function() { + const dom = cheerio.load(this.email.html) + const buttonLink = dom('a:contains("Set password")') + expect(buttonLink.length).to.equal(1) + expect(buttonLink.attr('href')).to.equal( + this.opts.setNewPasswordUrl + ) + const fallback = dom('.avoid-auto-linking').last() + expect(fallback.length).to.equal(1) + const fallbackLink = fallback.html().replace(/&/, '&') + expect(fallbackLink).to.contain(this.opts.setNewPasswordUrl) + }) + }) + + describe('plain text email', function() { + it('should contain the CTA link', function() { + expect(this.email.text).to.contain(this.opts.setNewPasswordUrl) + }) + }) + }) }) describe('no CTA', function() { describe('securityAlert', function() {