mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
setup basic new email feature which is tested, not linked up to real
events yet
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
should = require('chai').should()
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
path = require('path')
|
||||
sinon = require('sinon')
|
||||
modulePath = path.join __dirname, "../../../../app/js/Features/Email/EmailHandler"
|
||||
expect = require("chai").expect
|
||||
|
||||
describe "EmailHandler", ->
|
||||
|
||||
beforeEach ->
|
||||
|
||||
@settings = {}
|
||||
@EmailTemplator =
|
||||
buildEmail:sinon.stub()
|
||||
@EmailSender =
|
||||
sendEmail:sinon.stub()
|
||||
@EmailHandler = SandboxedModule.require modulePath, requires:
|
||||
"./EmailTemplator":@EmailTemplator
|
||||
"./EmailSender":@EmailSender
|
||||
"settings-sharelatex":@settings
|
||||
"logger-sharelatex": log:->
|
||||
|
||||
@html = "<html>hello</html>"
|
||||
|
||||
describe "send email", ->
|
||||
|
||||
it "should use the correct options", (done)->
|
||||
@EmailTemplator.buildEmail.returns({html:@html})
|
||||
@EmailSender.sendEmail.callsArgWith(1)
|
||||
|
||||
opts =
|
||||
to: "bob@bob.com"
|
||||
@EmailHandler.sendEmail "welcome", opts, =>
|
||||
args = @EmailSender.sendEmail.args[0][0]
|
||||
args.html.should.equal @html
|
||||
done()
|
||||
|
||||
|
||||
|
||||
it "should return the erroor", (done)->
|
||||
@EmailTemplator.buildEmail.returns({html:@html})
|
||||
@EmailSender.sendEmail.callsArgWith(1, "error")
|
||||
|
||||
opts =
|
||||
to: "bob@bob.com"
|
||||
subject:"hello bob"
|
||||
@EmailHandler.sendEmail "welcome", opts, (err)=>
|
||||
err.should.equal "error"
|
||||
done()
|
||||
@@ -0,0 +1,50 @@
|
||||
should = require('chai').should()
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
path = require('path')
|
||||
sinon = require('sinon')
|
||||
modulePath = path.join __dirname, "../../../../app/js/Features/Email/EmailSender.js"
|
||||
expect = require("chai").expect
|
||||
|
||||
describe "Email", ->
|
||||
|
||||
beforeEach ->
|
||||
|
||||
@settings =
|
||||
ses:
|
||||
key: "key"
|
||||
secret: "secret"
|
||||
@sesClient =
|
||||
sendemail: sinon.stub()
|
||||
@ses =
|
||||
createClient: => @sesClient
|
||||
@sender = SandboxedModule.require modulePath, requires:
|
||||
'node-ses': @ses
|
||||
"settings-sharelatex":@settings
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
warn:->
|
||||
err:->
|
||||
|
||||
describe "sendEmail", ->
|
||||
|
||||
it "should set the properties on the email to send", (done)->
|
||||
@sesClient.sendemail.callsArgWith(1)
|
||||
|
||||
opts =
|
||||
to: "bob@bob.com"
|
||||
subject: "new email"
|
||||
html: "<hello></hello>"
|
||||
replyTo: "sarah@bob.com"
|
||||
@sender.sendEmail opts, =>
|
||||
args = @sesClient.sendemail.args[0][0]
|
||||
args.message.should.equal opts.html
|
||||
args.to.should.equal opts.to
|
||||
args.subject.should.equal opts.subject
|
||||
done()
|
||||
|
||||
it "should return the error", (done)->
|
||||
@sesClient.sendemail.callsArgWith(1, "error")
|
||||
@sender.sendEmail {}, (err)=>
|
||||
err.should.equal "error"
|
||||
done()
|
||||
@@ -0,0 +1,53 @@
|
||||
should = require('chai').should()
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
path = require('path')
|
||||
sinon = require('sinon')
|
||||
modulePath = path.join __dirname, "../../../../app/js/Features/Email/EmailTemplator"
|
||||
expect = require("chai").expect
|
||||
_ = require('underscore')
|
||||
_.templateSettings =
|
||||
interpolate: /\{\{(.+?)\}\}/g
|
||||
|
||||
describe "Email Templator ", ->
|
||||
|
||||
beforeEach ->
|
||||
|
||||
@settings = {}
|
||||
@EmailTemplator = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex":@settings
|
||||
"logger-sharelatex": log:->
|
||||
|
||||
describe "welcomeEmail", ->
|
||||
|
||||
beforeEach ->
|
||||
@opts =
|
||||
to:"bob@bob.com"
|
||||
first_name:"bob"
|
||||
@email = @EmailTemplator.buildEmail("welcome", @opts)
|
||||
|
||||
it "should insert the first_name into the template", ->
|
||||
@email.html.indexOf(@opts.first_name).should.not.equal -1
|
||||
|
||||
it "should not have undefined in it", ->
|
||||
@email.html.indexOf("undefined").should.equal -1
|
||||
|
||||
describe "projectSharedWithYou", ->
|
||||
beforeEach ->
|
||||
@opts =
|
||||
to:"bob@bob.com"
|
||||
first_name:"bob"
|
||||
owner:
|
||||
email:"sally@hally.com"
|
||||
project:
|
||||
url:"http://www.project.com"
|
||||
name:"standard project"
|
||||
@email = @EmailTemplator.buildEmail("projectSharedWithYou", @opts)
|
||||
|
||||
it "should insert the owner email into the template", ->
|
||||
@email.html.indexOf(@opts.owner.email).should.not.equal -1
|
||||
@email.subject.indexOf(@opts.owner.email).should.not.equal -1
|
||||
|
||||
it "should not have undefined in it", ->
|
||||
@email.html.indexOf("undefined").should.equal -1
|
||||
@email.subject.indexOf("undefined").should.equal -1
|
||||
Reference in New Issue
Block a user