From dfb58a69c40a37dc078ff8306e653a351099a77b Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Mon, 21 Sep 2020 09:06:24 -0500 Subject: [PATCH] Merge pull request #3197 from overleaf/jel-new-cta-email-subscription-alerts Convert subscription emails to new email handling GitOrigin-RevId: bd10389aca073a1a21778af8c362e9254ddc70f1 --- .../app/src/Features/Email/EmailBuilder.js | 20 +++-- .../test/unit/src/Email/EmailBuilderTests.js | 77 +++++++++++++++++++ 2 files changed, 86 insertions(+), 11 deletions(-) diff --git a/services/web/app/src/Features/Email/EmailBuilder.js b/services/web/app/src/Features/Email/EmailBuilder.js index 66c3dd36ef..56efaa07f3 100644 --- a/services/web/app/src/Features/Email/EmailBuilder.js +++ b/services/web/app/src/Features/Email/EmailBuilder.js @@ -210,19 +210,19 @@ Click here to set your password and log in:\ } }) -templates.canceledSubscription = CTAEmailTemplate({ +templates.canceledSubscription = ctaTemplate({ subject() { return `${settings.appName} thoughts` }, message() { - return `\ -We are sorry to see you cancelled your ${ - settings.appName - } premium subscription. Would you mind giving us some feedback on what the site is lacking at the moment via this quick survey?\ -` + return [ + `We are sorry to see you cancelled your ${ + settings.appName + } premium subscription. Would you mind giving us some feedback on what the site is lacking at the moment via this quick survey?` + ] }, secondaryMessage() { - return 'Thank you in advance!' + return ['Thank you in advance!'] }, ctaText() { return 'Leave Feedback' @@ -232,14 +232,12 @@ We are sorry to see you cancelled your ${ } }) -templates.reactivatedSubscription = CTAEmailTemplate({ +templates.reactivatedSubscription = ctaTemplate({ subject() { return `Subscription Reactivated - ${settings.appName}` }, message(opts) { - return `\ -Your subscription was reactivated successfully.\ -` + return ['Your subscription was reactivated successfully.'] }, ctaText() { return 'View Subscription Dashboard' diff --git a/services/web/test/unit/src/Email/EmailBuilderTests.js b/services/web/test/unit/src/Email/EmailBuilderTests.js index 6c8601014a..9b03dcca9f 100644 --- a/services/web/test/unit/src/Email/EmailBuilderTests.js +++ b/services/web/test/unit/src/Email/EmailBuilderTests.js @@ -142,6 +142,45 @@ describe('EmailBuilder', function() { describe('templates', function() { describe('CTA', function() { + describe('canceledSubscription', function() { + beforeEach(function() { + this.emailAddress = 'example@overleaf.com' + this.opts = { + to: this.emailAddress + } + this.email = this.EmailBuilder.buildEmail( + 'canceledSubscription', + this.opts + ) + this.expectedUrl = + 'https://docs.google.com/forms/d/e/1FAIpQLSfa7z_s-cucRRXm70N4jEcSbFsZeb0yuKThHGQL8ySEaQzF0Q/viewform?usp=sf_link' + }) + + 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("Leave Feedback")') + expect(buttonLink.length).to.equal(1) + expect(buttonLink.attr('href')).to.equal(this.expectedUrl) + const fallback = dom('.avoid-auto-linking').last() + expect(fallback.length).to.equal(1) + const fallbackLink = fallback.html() + expect(fallbackLink).to.contain(this.expectedUrl) + }) + }) + + describe('plain text email', function() { + it('should contain the CTA link', function() { + expect(this.email.text).to.contain(this.expectedUrl) + }) + }) + }) + describe('confirmEmail', function() { before(function() { this.emailAddress = 'example@overleaf.com' @@ -314,6 +353,44 @@ describe('EmailBuilder', function() { }) }) }) + + describe('reactivatedSubscription', function() { + before(function() { + this.emailAddress = 'example@overleaf.com' + this.opts = { + to: this.emailAddress + } + this.email = this.EmailBuilder.buildEmail( + 'reactivatedSubscription', + this.opts + ) + this.expectedUrl = `${this.settings.siteUrl}/user/subscription` + }) + + 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("View Subscription Dashboard")') + expect(buttonLink.length).to.equal(1) + expect(buttonLink.attr('href')).to.equal(this.expectedUrl) + const fallback = dom('.avoid-auto-linking').last() + expect(fallback.length).to.equal(1) + const fallbackLink = fallback.html() + expect(fallbackLink).to.contain(this.expectedUrl) + }) + }) + + describe('plain text email', function() { + it('should contain the CTA link', function() { + expect(this.email.text).to.contain(this.expectedUrl) + }) + }) + }) }) describe('no CTA', function() { describe('securityAlert', function() {