Просмотр исходного кода

Merge pull request #3197 from overleaf/jel-new-cta-email-subscription-alerts

Convert subscription emails to new email handling

GitOrigin-RevId: bd10389aca073a1a21778af8c362e9254ddc70f1
Jessica Lawshe 6 лет назад
Родитель
Сommit
dfb58a69c4

+ 9 - 11
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() {
   subject() {
     return `${settings.appName} thoughts`
     return `${settings.appName} thoughts`
   },
   },
   message() {
   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() {
   secondaryMessage() {
-    return 'Thank you in advance!'
+    return ['Thank you in advance!']
   },
   },
   ctaText() {
   ctaText() {
     return 'Leave Feedback'
     return 'Leave Feedback'
@@ -232,14 +232,12 @@ We are sorry to see you cancelled your ${
   }
   }
 })
 })
 
 
-templates.reactivatedSubscription = CTAEmailTemplate({
+templates.reactivatedSubscription = ctaTemplate({
   subject() {
   subject() {
     return `Subscription Reactivated - ${settings.appName}`
     return `Subscription Reactivated - ${settings.appName}`
   },
   },
   message(opts) {
   message(opts) {
-    return `\
-Your subscription was reactivated successfully.\
-`
+    return ['Your subscription was reactivated successfully.']
   },
   },
   ctaText() {
   ctaText() {
     return 'View Subscription Dashboard'
     return 'View Subscription Dashboard'

+ 77 - 0
services/web/test/unit/src/Email/EmailBuilderTests.js

@@ -142,6 +142,45 @@ describe('EmailBuilder', function() {
 
 
   describe('templates', function() {
   describe('templates', function() {
     describe('CTA', 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() {
       describe('confirmEmail', function() {
         before(function() {
         before(function() {
           this.emailAddress = 'example@overleaf.com'
           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('no CTA', function() {
       describe('securityAlert', function() {
       describe('securityAlert', function() {