| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108 |
- import { vi, expect } from 'vitest'
- import cheerio from 'cheerio'
- import path from 'node:path'
- import EmailMessageHelper from '../../../../app/src/Features/Email/EmailMessageHelper.mjs'
- import ctaEmailBody from '../../../../app/src/Features/Email/Bodies/cta-email.mjs'
- import NoCTAEmailBody from '../../../../app/src/Features/Email/Bodies/NoCTAEmailBody.mjs'
- import BaseEmailLayout from '../../../../app/src/Features/Email/Layouts/BaseEmailLayout.mjs'
- const MODULE_PATH = path.join(
- import.meta.dirname,
- '../../../../app/src/Features/Email/EmailBuilder'
- )
- describe('EmailBuilder', function () {
- beforeEach(async function (ctx) {
- ctx.settings = {
- appName: 'testApp',
- siteUrl: 'https://www.overleaf.com',
- }
- vi.doMock('../../../../app/src/Features/Email/EmailMessageHelper', () => ({
- default: EmailMessageHelper,
- }))
- vi.doMock('../../../../app/src/Features/Email/Bodies/cta-email', () => ({
- default: ctaEmailBody,
- }))
- vi.doMock(
- '../../../../app/src/Features/Email/Bodies/NoCTAEmailBody',
- () => ({
- default: NoCTAEmailBody,
- })
- )
- vi.doMock(
- '../../../../app/src/Features/Email/Layouts/BaseEmailLayout',
- () => ({
- default: BaseEmailLayout,
- })
- )
- vi.doMock('@overleaf/settings', () => ({
- default: ctx.settings,
- }))
- ctx.EmailBuilder = (await import(MODULE_PATH)).default
- })
- describe('projectInvite', function () {
- beforeEach(function (ctx) {
- ctx.opts = {
- to: 'bob@bob.com',
- first_name: 'bob',
- owner: {
- email: 'sally@hally.com',
- },
- inviteUrl: 'http://example.com/invite',
- project: {
- url: 'http://www.project.com',
- name: 'standard project',
- },
- }
- })
- describe('when sending a normal email', function () {
- beforeEach(function (ctx) {
- ctx.email = ctx.EmailBuilder.buildEmail('projectInvite', ctx.opts)
- })
- it('should have html and text properties', function (ctx) {
- expect(ctx.email.html != null).to.equal(true)
- expect(ctx.email.text != null).to.equal(true)
- })
- it('should not have undefined in it', function (ctx) {
- ctx.email.html.indexOf('undefined').should.equal(-1)
- ctx.email.subject.indexOf('undefined').should.equal(-1)
- })
- })
- describe('when dealing with escaping', function () {
- it("should not show possessive 's as '", function (ctx) {
- ctx.opts.project.name = "Aktöbe's project"
- ctx.email = ctx.EmailBuilder.buildEmail('projectInvite', ctx.opts)
- expect(ctx.email.subject).to.not.contain(''')
- expect(ctx.email.subject).to.contain(ctx.opts.project.name)
- })
- it('should not show an ampersand as &', function (ctx) {
- ctx.opts.project.name = 'Aktöbe & Almaty project'
- ctx.email = ctx.EmailBuilder.buildEmail('projectInvite', ctx.opts)
- expect(ctx.email.subject).to.not.contain('&')
- expect(ctx.email.subject).to.contain(ctx.opts.project.name)
- })
- it('should prevent dangerous characters as project names', function (ctx) {
- const characters = ['""', '<>', '//']
- for (const pair of characters) {
- ctx.opts.project.name = `${pair} project`
- ctx.email = ctx.EmailBuilder.buildEmail('projectInvite', ctx.opts)
- expect(ctx.email.subject).to.not.contain(pair)
- }
- })
- })
- describe('when someone is up to no good', function () {
- it('should not contain the project name at all if unsafe', function (ctx) {
- ctx.opts.project.name = "<img src='http://evilsite.com/evil.php'>"
- ctx.email = ctx.EmailBuilder.buildEmail('projectInvite', ctx.opts)
- expect(ctx.email.html).to.not.contain('evilsite.com')
- expect(ctx.email.subject).to.not.contain('evilsite.com')
- // but email should appear
- expect(ctx.email.html).to.contain(ctx.opts.owner.email)
- expect(ctx.email.subject).to.contain(ctx.opts.owner.email)
- })
- it('should not contain the inviter email at all if unsafe', function (ctx) {
- ctx.opts.owner.email =
- 'verylongemailaddressthatwillfailthecheck@longdomain.domain'
- ctx.email = ctx.EmailBuilder.buildEmail('projectInvite', ctx.opts)
- expect(ctx.email.html).to.not.contain(ctx.opts.owner.email)
- expect(ctx.email.subject).to.not.contain(ctx.opts.owner.email)
- // but title should appear
- expect(ctx.email.html).to.contain(ctx.opts.project.name)
- expect(ctx.email.subject).to.contain(ctx.opts.project.name)
- })
- it('should handle both email and title being unsafe', function (ctx) {
- ctx.opts.project.name = "<img src='http://evilsite.com/evil.php'>"
- ctx.opts.owner.email =
- 'verylongemailaddressthatwillfailthecheck@longdomain.domain'
- ctx.email = ctx.EmailBuilder.buildEmail('projectInvite', ctx.opts)
- expect(ctx.email.html).to.not.contain('evilsite.com')
- expect(ctx.email.subject).to.not.contain('evilsite.com')
- expect(ctx.email.html).to.not.contain(ctx.opts.owner.email)
- expect(ctx.email.subject).to.not.contain(ctx.opts.owner.email)
- expect(ctx.email.html).to.contain(
- 'Please view the project to find out more'
- )
- })
- })
- })
- describe('SpamSafe', function () {
- beforeEach(function (ctx) {
- ctx.opts = {
- to: 'bob@joe.com',
- first_name: 'bob',
- newOwner: {
- email: 'sally@hally.com',
- },
- inviteUrl: 'http://example.com/invite',
- project: {
- url: 'http://www.project.com',
- name: 'come buy my product at http://notascam.com',
- },
- }
- ctx.email = ctx.EmailBuilder.buildEmail(
- 'ownershipTransferConfirmationPreviousOwner',
- ctx.opts
- )
- })
- it('should replace spammy project name', function (ctx) {
- ctx.email.html.indexOf('your project').should.not.equal(-1)
- })
- })
- describe('gitTokenExpiringSoon', function () {
- beforeEach(function (ctx) {
- ctx.opts = {
- to: 'user@example.com',
- }
- ctx.email = ctx.EmailBuilder.buildEmail('gitTokenExpiringSoon', ctx.opts)
- })
- it('should render html, text, and subject without undefined', function (ctx) {
- expect(ctx.email.html).to.not.be.undefined
- expect(ctx.email.text).to.not.be.undefined
- expect(ctx.email.subject).to.not.be.undefined
- ctx.email.html.indexOf('undefined').should.equal(-1)
- ctx.email.text.indexOf('undefined').should.equal(-1)
- ctx.email.subject.indexOf('undefined').should.equal(-1)
- })
- it('should link the CTA to user settings', function (ctx) {
- ctx.email.text.should.contain(`${ctx.settings.siteUrl}/user/settings`)
- })
- })
- describe('gitTokenExpired', function () {
- beforeEach(function (ctx) {
- ctx.opts = {
- to: 'user@example.com',
- }
- ctx.email = ctx.EmailBuilder.buildEmail('gitTokenExpired', ctx.opts)
- })
- it('should render html, text, and subject without undefined', function (ctx) {
- expect(ctx.email.html).to.not.be.undefined
- expect(ctx.email.text).to.not.be.undefined
- expect(ctx.email.subject).to.not.be.undefined
- ctx.email.html.indexOf('undefined').should.equal(-1)
- ctx.email.text.indexOf('undefined').should.equal(-1)
- ctx.email.subject.indexOf('undefined').should.equal(-1)
- })
- it('should link the CTA to user settings', function (ctx) {
- ctx.email.text.should.contain(`${ctx.settings.siteUrl}/user/settings`)
- })
- })
- describe('ctaTemplate', function () {
- describe('missing required content', function () {
- const content = {
- title: () => {},
- greeting: () => {},
- message: () => {},
- secondaryMessage: () => {},
- ctaText: () => {},
- ctaURL: () => {},
- gmailGoToAction: () => {},
- }
- it('should throw an error when missing title', function (ctx) {
- const { title, ...missing } = content
- expect(() => {
- ctx.EmailBuilder.ctaTemplate(missing)
- }).to.throw(Error)
- })
- it('should throw an error when missing message', function (ctx) {
- const { message, ...missing } = content
- expect(() => {
- ctx.EmailBuilder.ctaTemplate(missing)
- }).to.throw(Error)
- })
- it('should throw an error when missing ctaText', function (ctx) {
- const { ctaText, ...missing } = content
- expect(() => {
- ctx.EmailBuilder.ctaTemplate(missing)
- }).to.throw(Error)
- })
- it('should throw an error when missing ctaURL', function (ctx) {
- const { ctaURL, ...missing } = content
- expect(() => {
- ctx.EmailBuilder.ctaTemplate(missing)
- }).to.throw(Error)
- })
- })
- describe('footerMessage', function () {
- it('should default footerMessage to undefined when not provided', function (ctx) {
- const template = ctx.EmailBuilder.ctaTemplate({
- subject: () => 'Subject',
- message: () => ['Message'],
- ctaText: () => 'Click',
- ctaURL: () => 'https://example.com',
- })
- expect(template.footerMessage({})).to.be.undefined
- })
- it('should use the provided footerMessage callback', function (ctx) {
- const template = ctx.EmailBuilder.ctaTemplate({
- subject: () => 'Subject',
- message: () => ['Message'],
- ctaText: () => 'Click',
- ctaURL: () => 'https://example.com',
- footerMessage: () => 'Custom footer text',
- })
- expect(template.footerMessage({})).to.equal('Custom footer text')
- })
- it('should include footerMessage in plain text output when provided', function (ctx) {
- ctx.EmailBuilder.templates.testFooterTemplate =
- ctx.EmailBuilder.ctaTemplate({
- subject: () => 'Test Subject',
- message: () => ['Body message'],
- ctaText: () => 'Go',
- ctaURL: () => 'https://example.com',
- footerMessage: (opts, isPlainText) =>
- isPlainText ? 'Plain footer' : '<b>HTML footer</b>',
- })
- const email = ctx.EmailBuilder.buildEmail('testFooterTemplate', {
- to: 'test@example.com',
- })
- expect(email.text).to.contain('Plain footer')
- delete ctx.EmailBuilder.templates.testFooterTemplate
- })
- })
- })
- describe('templates', function () {
- describe('CTA', function () {
- describe('canceledSubscription', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- }
- ctx.email = ctx.EmailBuilder.buildEmail(
- 'canceledSubscription',
- ctx.opts
- )
- ctx.expectedUrl =
- 'https://docs.google.com/forms/d/e/1FAIpQLSfa7z_s-cucRRXm70N4jEcSbFsZeb0yuKThHGQL8ySEaQzF0Q/viewform?usp=sf_link'
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom('a:contains("Leave feedback")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.expectedUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.expectedUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.expectedUrl)
- })
- })
- })
- describe('canceledSubscriptionOrAddOn', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- }
- ctx.email = ctx.EmailBuilder.buildEmail(
- 'canceledSubscriptionOrAddOn',
- ctx.opts
- )
- ctx.expectedUrl =
- 'https://digitalscience.qualtrics.com/jfe/form/SV_2n2aSlWgvoxXdGK'
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom('a:contains("Leave feedback")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.expectedUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.expectedUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.expectedUrl)
- })
- })
- })
- describe('confirmEmail', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.userId = 'abc123'
- ctx.opts = {
- to: ctx.emailAddress,
- confirmEmailUrl: `${ctx.settings.siteUrl}/user/emails/confirm?token=aToken123`,
- sendingUser_id: ctx.userId,
- }
- ctx.email = ctx.EmailBuilder.buildEmail('confirmEmail', ctx.opts)
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom('a:contains("Confirm email")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.opts.confirmEmailUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.opts.confirmEmailUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.opts.confirmEmailUrl)
- })
- })
- })
- describe('ownershipTransferConfirmationNewOwner', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- previousOwner: {},
- project: {
- _id: 'abc123',
- name: 'example project',
- },
- }
- ctx.email = ctx.EmailBuilder.buildEmail(
- 'ownershipTransferConfirmationNewOwner',
- ctx.opts
- )
- ctx.expectedUrl = `${
- ctx.settings.siteUrl
- }/project/${ctx.opts.project._id.toString()}`
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom('a:contains("View project")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.expectedUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.expectedUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.expectedUrl)
- })
- })
- })
- describe('passwordResetRequested', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- setNewPasswordUrl: `${
- ctx.settings.siteUrl
- }/user/password/set?passwordResetToken=aToken&email=${encodeURIComponent(
- ctx.emailAddress
- )}`,
- }
- ctx.email = ctx.EmailBuilder.buildEmail(
- 'passwordResetRequested',
- ctx.opts
- )
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom('a:contains("Reset password")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.opts.setNewPasswordUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.opts.setNewPasswordUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.opts.setNewPasswordUrl)
- })
- })
- })
- describe('reconfirmEmail', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.userId = 'abc123'
- ctx.opts = {
- to: ctx.emailAddress,
- confirmEmailUrl: `${ctx.settings.siteUrl}/user/emails/confirm?token=aToken123`,
- sendingUser_id: ctx.userId,
- }
- ctx.email = ctx.EmailBuilder.buildEmail('reconfirmEmail', ctx.opts)
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom('a:contains("Reconfirm email")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.opts.confirmEmailUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.opts.confirmEmailUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.opts.confirmEmailUrl)
- })
- })
- })
- describe('verifyEmailToJoinTeam', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- acceptInviteUrl: `${ctx.settings.siteUrl}/subscription/invites/aToken123/`,
- inviter: {
- email: 'deanna@overleaf.com',
- first_name: 'Deanna',
- last_name: 'Troi',
- },
- }
- ctx.email = ctx.EmailBuilder.buildEmail(
- 'verifyEmailToJoinTeam',
- ctx.opts
- )
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom('a:contains("Join now")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.opts.acceptInviteUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.opts.acceptInviteUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.opts.acceptInviteUrl)
- })
- })
- })
- describe('reactivatedSubscription', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- }
- ctx.email = ctx.EmailBuilder.buildEmail(
- 'reactivatedSubscription',
- ctx.opts
- )
- ctx.expectedUrl = `${ctx.settings.siteUrl}/user/subscription`
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom('a:contains("View Subscription Dashboard")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.expectedUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.expectedUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.expectedUrl)
- })
- })
- })
- describe('testEmail', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- }
- ctx.email = ctx.EmailBuilder.buildEmail('testEmail', ctx.opts)
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom(`a:contains("Open ${ctx.settings.appName}")`)
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.settings.siteUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.settings.siteUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(
- `Open ${ctx.settings.appName}: ${ctx.settings.siteUrl}`
- )
- })
- })
- })
- describe('registered', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- setNewPasswordUrl: `${ctx.settings.siteUrl}/user/activate?token=aToken123&user_id=aUserId123`,
- }
- ctx.email = ctx.EmailBuilder.buildEmail('registered', ctx.opts)
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom('a:contains("Set password")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.opts.setNewPasswordUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.opts.setNewPasswordUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.opts.setNewPasswordUrl)
- })
- })
- })
- describe('projectInvite', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.owner = {
- email: 'owner@example.com',
- name: 'Bailey',
- }
- ctx.projectName = 'Top Secret'
- ctx.opts = {
- inviteUrl: `${ctx.settings.siteUrl}/project/projectId123/invite/token/aToken123`,
- owner: {
- email: ctx.owner.email,
- },
- project: {
- name: ctx.projectName,
- },
- to: ctx.emailAddress,
- }
- ctx.email = ctx.EmailBuilder.buildEmail('projectInvite', ctx.opts)
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const buttonLink = dom('a:contains("View project")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.opts.inviteUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.opts.inviteUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.opts.inviteUrl)
- })
- })
- })
- describe('welcome', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- confirmEmailUrl: `${ctx.settings.siteUrl}/user/emails/confirm?token=token123`,
- }
- ctx.email = ctx.EmailBuilder.buildEmail('welcome', ctx.opts)
- ctx.dom = cheerio.load(ctx.email.html)
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const buttonLink = ctx.dom('a:contains("Confirm email")')
- expect(buttonLink.length).to.equal(1)
- expect(buttonLink.attr('href')).to.equal(ctx.opts.confirmEmailUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.opts.confirmEmailUrl)
- })
- it('should include help links', function (ctx) {
- const helpGuidesLink = ctx.dom('a:contains("Help Guides")')
- const templatesLink = ctx.dom('a:contains("Templates")')
- const logInLink = ctx.dom('a:contains("log in")')
- expect(helpGuidesLink.length).to.equal(1)
- expect(templatesLink.length).to.equal(1)
- expect(logInLink.length).to.equal(1)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA URL', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.opts.confirmEmailUrl)
- })
- it('should include help URL', function (ctx) {
- expect(ctx.email.text).to.contain('/learn')
- expect(ctx.email.text).to.contain('/login')
- expect(ctx.email.text).to.contain('/templates')
- })
- it('should contain HTML links', function (ctx) {
- expect(ctx.email.text).to.not.contain('<a')
- })
- })
- })
- describe('groupSSODisabled', function () {
- it('should build the email for non managed and linked users', function (ctx) {
- const setNewPasswordUrl = `${ctx.settings.siteUrl}/user/password/reset`
- const emailAddress = 'example@overleaf.com'
- const opts = {
- to: emailAddress,
- setNewPasswordUrl,
- userIsManaged: false,
- }
- const email = ctx.EmailBuilder.buildEmail('groupSSODisabled', opts)
- expect(email.subject).to.equal(
- 'A change to your Overleaf login options'
- )
- const dom = cheerio.load(email.html)
- expect(email.html).to.exist
- expect(email.html).to.contain(
- 'Your group administrator has disabled single sign-on for your group.'
- )
- expect(email.html).to.contain(
- 'You can still log in to Overleaf using one of our other'
- )
- const loginLink = dom('a:contains("login options")')
- expect(loginLink.attr('href')).to.equal(
- `${ctx.settings.siteUrl}/login`
- )
- const passwordLink = dom('a:contains("Set your new password")')
- expect(passwordLink.attr('href')).to.equal(setNewPasswordUrl)
- expect(email.html).to.contain(
- "If you don't have a password, you can set one now."
- )
- expect(email.text).to.exist
- const expectedPlainText = [
- 'Hi,',
- '',
- 'Your group administrator has disabled single sign-on for your group.',
- '',
- '',
- '',
- 'What does this mean for you?',
- '',
- 'You can still log in to Overleaf using one of our other login options or with your email address and password.',
- '',
- "If you don't have a password, you can set one now.",
- '',
- `Set your new password: ${setNewPasswordUrl}`,
- '',
- '',
- '',
- 'Regards,',
- `The ${ctx.settings.appName} Team - ${ctx.settings.siteUrl}`,
- ]
- expect(email.text.split(/\r?\n/)).to.deep.equal(expectedPlainText)
- })
- it('should build the email for managed and linked users', function (ctx) {
- const emailAddress = 'example@overleaf.com'
- const setNewPasswordUrl = `${ctx.settings.siteUrl}/user/password/reset`
- const opts = {
- to: emailAddress,
- setNewPasswordUrl,
- userIsManaged: true,
- }
- const email = ctx.EmailBuilder.buildEmail('groupSSODisabled', opts)
- expect(email.subject).to.equal(
- 'Action required: Set your Overleaf password'
- )
- const dom = cheerio.load(email.html)
- expect(email.html).to.exist
- expect(email.html).to.contain(
- 'Your group administrator has disabled single sign-on for your group.'
- )
- expect(email.html).to.contain(
- 'You now need an email address and password to sign in to your Overleaf account.'
- )
- const ctaLink = dom('a:contains("Set your new password")')
- expect(ctaLink.attr('href')).to.equal(
- `${ctx.settings.siteUrl}/user/password/reset`
- )
- expect(email.text).to.exist
- const expectedPlainText = [
- 'Hi,',
- '',
- 'Your group administrator has disabled single sign-on for your group.',
- '',
- '',
- '',
- 'What does this mean for you?',
- '',
- 'You now need an email address and password to sign in to your Overleaf account.',
- '',
- `Set your new password: ${setNewPasswordUrl}`,
- '',
- '',
- '',
- 'Regards,',
- `The ${ctx.settings.appName} Team - ${ctx.settings.siteUrl}`,
- ]
- expect(email.text.split(/\r?\n/)).to.deep.equal(expectedPlainText)
- })
- })
- })
- describe('no CTA', function () {
- describe('securityAlert', function () {
- beforeEach(function (ctx) {
- ctx.message = 'more details about the action'
- ctx.messageHTML = `<br /><span style="text-align:center" class="a-class"><b><i>${ctx.message}</i></b></span>`
- ctx.messageNotAllowedHTML = `<div></div>${ctx.messageHTML}`
- ctx.actionDescribed = 'an action described'
- ctx.actionDescribedHTML = `<br /><span style="text-align:center" class="a-class"><b><i>${ctx.actionDescribed}</i></b>`
- ctx.actionDescribedNotAllowedHTML = `<div></div>${ctx.actionDescribedHTML}`
- ctx.opts = {
- to: ctx.email,
- actionDescribed: ctx.actionDescribedNotAllowedHTML,
- action: 'an action',
- message: [ctx.messageNotAllowedHTML],
- }
- ctx.email = ctx.EmailBuilder.buildEmail('securityAlert', ctx.opts)
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html != null).to.equal(true)
- expect(ctx.email.text != null).to.equal(true)
- })
- describe('HTML email', function () {
- it('should clean HTML in opts.actionDescribed', function (ctx) {
- expect(ctx.email.html).to.not.contain(
- ctx.actionDescribedNotAllowedHTML
- )
- expect(ctx.email.html).to.contain(ctx.actionDescribedHTML)
- })
- it('should clean HTML in opts.message', function (ctx) {
- expect(ctx.email.html).to.not.contain(ctx.messageNotAllowedHTML)
- expect(ctx.email.html).to.contain(ctx.messageHTML)
- })
- })
- describe('plain text email', function () {
- it('should remove all HTML in opts.actionDescribed', function (ctx) {
- expect(ctx.email.text).to.not.contain(ctx.actionDescribedHTML)
- expect(ctx.email.text).to.contain(ctx.actionDescribed)
- })
- it('should remove all HTML in opts.message', function (ctx) {
- expect(ctx.email.text).to.not.contain(ctx.messageHTML)
- expect(ctx.email.text).to.contain(ctx.message)
- })
- })
- })
- describe('welcomeWithoutCTA', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- }
- ctx.email = ctx.EmailBuilder.buildEmail('welcomeWithoutCTA', ctx.opts)
- ctx.dom = cheerio.load(ctx.email.html)
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include help links', function (ctx) {
- const helpGuidesLink = ctx.dom('a:contains("Help Guides")')
- const templatesLink = ctx.dom('a:contains("Templates")')
- const logInLink = ctx.dom('a:contains("log in")')
- expect(helpGuidesLink.length).to.equal(1)
- expect(templatesLink.length).to.equal(1)
- expect(logInLink.length).to.equal(1)
- })
- })
- describe('plain text email', function () {
- it('should include help URL', function (ctx) {
- expect(ctx.email.text).to.contain('/learn')
- expect(ctx.email.text).to.contain('/login')
- expect(ctx.email.text).to.contain('/templates')
- })
- it('should contain HTML links', function (ctx) {
- expect(ctx.email.text).to.not.contain('<a')
- })
- })
- })
- describe('removeGroupMember', function () {
- beforeEach(function (ctx) {
- ctx.passwordResetUrl = `${ctx.settings.siteUrl}/user/password/reset`
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- adminName: 'abcdef',
- }
- ctx.email = ctx.EmailBuilder.buildEmail('removeGroupMember', ctx.opts)
- ctx.dom = cheerio.load(ctx.email.html)
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include links', function (ctx) {
- const resetPasswordLink = ctx.dom('a:contains("set a password")')
- expect(resetPasswordLink.length).to.equal(1)
- expect(resetPasswordLink.attr('href')).to.equal(
- ctx.passwordResetUrl
- )
- })
- })
- describe('plain text email', function () {
- it('should include URLs', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.passwordResetUrl)
- })
- })
- })
- describe('taxExemptCertificateRequired', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'customer@example.com'
- ctx.opts = {
- to: ctx.emailAddress,
- ein: '12-3456789',
- stripeCustomerId: 'cus_123456789',
- }
- ctx.email = ctx.EmailBuilder.buildEmail(
- 'taxExemptCertificateRequired',
- ctx.opts
- )
- ctx.dom = cheerio.load(ctx.email.html)
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include the EIN', function (ctx) {
- expect(ctx.email.html).to.contain(ctx.opts.ein)
- })
- it('should include the Stripe customer ID', function (ctx) {
- expect(ctx.email.html).to.contain(ctx.opts.stripeCustomerId)
- })
- it('should include tax exemption verification text', function (ctx) {
- expect(ctx.email.html).to.contain('tax exempt')
- expect(ctx.email.html).to.contain('verification')
- })
- })
- describe('plain text email', function () {
- it('should include the EIN', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.opts.ein)
- })
- it('should include the Stripe customer ID', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.opts.stripeCustomerId)
- })
- it('should include tax exemption verification text', function (ctx) {
- expect(ctx.email.text).to.contain('tax exempt')
- expect(ctx.email.text).to.contain('verification')
- })
- })
- })
- describe('groupMemberLimitWarning', function () {
- beforeEach(function (ctx) {
- ctx.emailAddress = 'example@overleaf.com'
- ctx.opts = {
- to: ctx.emailAddress,
- groupName: 'Example Group',
- firstName: 'Joe',
- currentMembers: 9,
- membersLimit: 10,
- remainingSeats: 1,
- }
- ctx.email = ctx.EmailBuilder.buildEmail(
- 'groupMemberLimitWarning',
- ctx.opts
- )
- ctx.expectedUrl = `${ctx.settings.siteUrl}/user/subscription/group/add-users`
- })
- it('should build the email', function (ctx) {
- expect(ctx.email.html).to.exist
- expect(ctx.email.text).to.exist
- })
- describe('HTML email', function () {
- it('should include a CTA button and a fallback CTA link', function (ctx) {
- const dom = cheerio.load(ctx.email.html)
- const plainText = dom.text()
- expect(ctx.email.subject).to.equal(
- 'Action needed: Your Overleaf group is nearly out of licenses'
- )
- expect(ctx.email.html).to.exist
- expect(ctx.email.html).to.contain(
- `Your Overleaf group <b>${ctx.opts.groupName}</b> is close to its license limit.`
- )
- expect(plainText).to.contain(
- `${ctx.opts.currentMembers} of ${ctx.opts.membersLimit} ` +
- `licenses are in use (${ctx.opts.remainingSeats} remaining).`
- )
- expect(ctx.email.html).to.contain(
- 'Because domain capture is enabled, users from your domain ' +
- 'can join automatically via SSO.'
- )
- expect(ctx.email.html).to.contain(
- 'Once all licenses are used, new users won’t be able to join.'
- )
- expect(ctx.email.html).to.contain('What you can do now:')
- expect(ctx.email.html).to.contain('Add more licenses, or')
- expect(ctx.email.html).to.contain(
- 'Remove inactive users to free up licenses'
- )
- const buttonLink = dom('a:contains("Add licenses")')
- expect(buttonLink).to.exist
- expect(buttonLink.attr('href')).to.equal(ctx.expectedUrl)
- expect(ctx.email.html).to.contain('copy and paste this link')
- expect(ctx.email.html).to.contain(ctx.expectedUrl)
- })
- })
- describe('plain text email', function () {
- it('should contain the CTA link', function (ctx) {
- expect(ctx.email.text).to.contain(ctx.expectedUrl)
- })
- })
- })
- })
- })
- })
|