2014-03-04 13:10:06 -05:00
|
|
|
should = require('chai').should()
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
assert = require('assert')
|
|
|
|
path = require('path')
|
|
|
|
sinon = require('sinon')
|
2014-03-05 06:22:34 -05:00
|
|
|
modulePath = path.join __dirname, "../../../../app/js/Features/Email/EmailBuilder"
|
2014-03-04 13:10:06 -05:00
|
|
|
expect = require("chai").expect
|
|
|
|
_ = require('underscore')
|
|
|
|
_.templateSettings =
|
|
|
|
interpolate: /\{\{(.+?)\}\}/g
|
|
|
|
|
2016-03-09 07:51:19 -05:00
|
|
|
describe "EmailBuilder", ->
|
2014-03-04 13:10:06 -05:00
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
|
2017-12-21 12:18:10 -05:00
|
|
|
@settings =
|
|
|
|
appName: "testApp"
|
|
|
|
brandPrefix: ''
|
2014-03-05 06:22:34 -05:00
|
|
|
@EmailBuilder = SandboxedModule.require modulePath, requires:
|
2014-03-04 13:10:06 -05:00
|
|
|
"settings-sharelatex":@settings
|
|
|
|
"logger-sharelatex": log:->
|
|
|
|
|
2016-10-03 10:25:38 -04:00
|
|
|
describe "projectInvite", ->
|
|
|
|
beforeEach ->
|
|
|
|
@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"
|
|
|
|
|
2019-03-04 07:01:15 -05:00
|
|
|
describe "when sending a normal email", ->
|
|
|
|
beforeEach ->
|
|
|
|
@email = @EmailBuilder.buildEmail("projectInvite", @opts)
|
|
|
|
|
|
|
|
it 'should have html and text properties', ->
|
|
|
|
expect(@email.html?).to.equal true
|
|
|
|
expect(@email.text?).to.equal true
|
|
|
|
|
|
|
|
it "should not have undefined in it", ->
|
|
|
|
@email.html.indexOf("undefined").should.equal -1
|
|
|
|
@email.subject.indexOf("undefined").should.equal -1
|
|
|
|
|
|
|
|
describe "when someone is up to no good", ->
|
|
|
|
beforeEach ->
|
|
|
|
@opts.project.name = "<img src='http://evilsite.com/evil.php'>"
|
|
|
|
@email = @EmailBuilder.buildEmail("projectInvite", @opts)
|
|
|
|
|
|
|
|
it 'should not contain unescaped html in the html part', ->
|
2019-03-06 14:36:50 -05:00
|
|
|
expect(@email.html).to.contain "New Project"
|
2016-10-03 10:25:38 -04:00
|
|
|
|
2019-03-06 14:36:50 -05:00
|
|
|
it "should not have undefined in it", ->
|
|
|
|
@email.html.indexOf("undefined").should.equal -1
|
|
|
|
@email.subject.indexOf("undefined").should.equal -1
|
|
|
|
|
|
|
|
describe "SpamSafe", ->
|
|
|
|
beforeEach ->
|
|
|
|
@opts =
|
|
|
|
to:"bob@joe.com"
|
|
|
|
first_name:"bob"
|
|
|
|
owner:
|
|
|
|
email:"sally@hally.com"
|
|
|
|
inviteUrl: "http://example.com/invite"
|
|
|
|
project:
|
|
|
|
url:"http://www.project.com"
|
|
|
|
name:"come buy my product at http://notascam.com"
|
|
|
|
@email = @EmailBuilder.buildEmail("projectInvite", @opts)
|
|
|
|
|
|
|
|
it "should replace spammy project name", ->
|
2019-03-14 11:48:27 -04:00
|
|
|
@email.html.indexOf("a new project").should.not.equal -1
|
2019-03-06 14:36:50 -05:00
|
|
|
@email.subject.indexOf("New Project").should.not.equal -1
|