email sending options are configurable from settings

This commit is contained in:
Henry Oswald 2014-03-05 11:31:40 +00:00
parent 5bacb2d784
commit 3c18cc5553
2 changed files with 38 additions and 15 deletions

View file

@ -20,10 +20,10 @@ module.exports =
metrics.inc "email"
options =
to: options.to
from: "ShareLaTeX <team@sharelatex.com>"
from: Settings.email.fromAddress
subject: options.subject
message: options.html
replyTo: options.replyTo || "team@sharelatex.com"
replyTo: Settings.email.replyToAddress
client.sendemail options, (err, data, res)->
if err?
logger.err err:err, "error sending message"

View file

@ -11,9 +11,13 @@ describe "Email", ->
beforeEach ->
@settings =
email:
ses:
key: "key"
secret: "secret"
fromAddress: "bob@bob.com"
replyToAddress: "sally@gmail.com"
@sesClient =
sendemail: sinon.stub()
@ses =
@ -26,21 +30,22 @@ describe "Email", ->
warn:->
err:->
@opts =
to: "bob@bob.com"
subject: "new email"
html: "<hello></hello>"
replyTo: "sarah@bob.com"
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, =>
@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
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)->
@ -48,3 +53,21 @@ describe "Email", ->
@sender.sendEmail {}, (err)=>
err.should.equal "error"
done()
it "should use the from address from settings", (done)->
@sesClient.sendemail.callsArgWith(1)
@sender.sendEmail @opts, =>
args = @sesClient.sendemail.args[0][0]
args.from.should.equal @settings.email.fromAddress
done()
it "should use the reply to address from settings", (done)->
@sesClient.sendemail.callsArgWith(1)
@sender.sendEmail @opts, =>
args = @sesClient.sendemail.args[0][0]
args.replyTo.should.equal @settings.email.replyToAddress
done()