| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047 |
- 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 BaseWithHeaderEmailLayout from '../../../../app/src/Features/Email/Layouts/BaseWithHeaderEmailLayout.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/BaseWithHeaderEmailLayout',
- () => ({
- default: BaseWithHeaderEmailLayout,
- })
- )
- 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('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('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)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback.length).to.equal(1)
- const fallbackLink = fallback.html()
- expect(fallbackLink).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)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback.length).to.equal(1)
- const fallbackLink = fallback.html()
- expect(fallbackLink).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)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback.length).to.equal(1)
- const fallbackLink = fallback.html()
- expect(fallbackLink).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('td a')
- expect(buttonLink).to.exist
- expect(buttonLink.attr('href')).to.equal(ctx.expectedUrl)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback).to.exist
- const fallbackLink = fallback.html().replace(/&/g, '&')
- expect(fallbackLink).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('td a')
- expect(buttonLink).to.exist
- expect(buttonLink.attr('href')).to.equal(ctx.opts.setNewPasswordUrl)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback).to.exist
- const fallbackLink = fallback.html().replace(/&/g, '&')
- expect(fallbackLink).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)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback.length).to.equal(1)
- const fallbackLink = fallback.html()
- expect(fallbackLink).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)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback.length).to.equal(1)
- const fallbackLink = fallback.html()
- expect(fallbackLink).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)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback.length).to.equal(1)
- const fallbackLink = fallback.html()
- expect(fallbackLink).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)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback.length).to.equal(1)
- const fallbackLink = fallback.html()
- expect(fallbackLink).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)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback.length).to.equal(1)
- const fallbackLink = fallback.html().replace(/&/, '&')
- expect(fallbackLink).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)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback.length).to.equal(1)
- const fallbackLink = fallback.html().replace(/&/g, '&')
- expect(fallbackLink).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)
- const fallback = ctx.dom('.force-overleaf-style').last()
- expect(fallback.length).to.equal(1)
- expect(fallback.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 links = dom('a')
- expect(links[0].attribs.href).to.equal(
- `${ctx.settings.siteUrl}/login`
- )
- expect(links[1].attribs.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 links = dom('a')
- expect(links[0].attribs.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(
- `${ctx.opts.groupName} is approaching its member limit`
- )
- expect(ctx.email.html).to.exist
- expect(ctx.email.html).to.contain(
- `Your group "${ctx.opts.groupName}" is approaching its member limit.`
- )
- expect(plainText).to.contain(
- `Current usage: ${ctx.opts.currentMembers} of ` +
- `${ctx.opts.membersLimit} licenses used ` +
- `(${ctx.opts.remainingSeats} remaining)`
- )
- expect(ctx.email.html).to.contain(
- 'With domain capture enabled, users with verified email ' +
- 'addresses from your domain can automatically join the group ' +
- 'via SSO. Once the member limit is reached, new users will ' +
- 'be blocked from joining.'
- )
- expect(ctx.email.html).to.contain(
- 'To ensure uninterrupted access for your users, consider ' +
- 'adding more licenses or removing inactive members.'
- )
- const buttonLink = dom('td a')
- expect(buttonLink).to.exist
- expect(buttonLink.attr('href')).to.equal(ctx.expectedUrl)
- const fallback = dom('.force-overleaf-style').last()
- expect(fallback).to.exist
- const fallbackLink = fallback.html().replace(/&/g, '&')
- expect(fallbackLink).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)
- })
- })
- })
- })
- })
- })
|