hooked up lifetime emails

This commit is contained in:
Henry Oswald 2014-03-05 14:56:52 +00:00
parent a9327cb7c5
commit ffe690afa3
4 changed files with 18 additions and 4 deletions

View file

@ -4,7 +4,7 @@ EmailSender = require "./EmailSender"
module.exports =
sendEmail : (emailType, opts, callback)->
sendEmail : (emailType, opts, callback = (err)->)->
email = EmailBuilder.buildEmail emailType, opts
if email.type == "lifecycle" and !settings.email.lifecycle
return callback()

View file

@ -2,9 +2,10 @@ RecurlyWrapper = require("./RecurlyWrapper")
Settings = require "settings-sharelatex"
User = require('../../models/User').User
logger = require('logger-sharelatex')
AnalyticsManager = require '../../Features/Analytics/AnalyticsManager'
AnalyticsManager = require '../Analytics/AnalyticsManager'
SubscriptionUpdater = require("./SubscriptionUpdater")
LimitationsManager = require('./LimitationsManager')
EmailHandler = require("../Email/EmailHandler")
module.exports =
@ -33,6 +34,10 @@ module.exports =
RecurlyWrapper.cancelSubscription subscription.recurlySubscription_id, (error) ->
return callback(error) if error?
AnalyticsManager.trackSubscriptionCancelled user
emailOpts =
to: user.email
first_name: user.first_name
EmailHandler.sendEmail "canceledSubscription", emailOpts
callback()
else
callback()
@ -55,4 +60,3 @@ module.exports =

View file

@ -86,6 +86,10 @@ module.exports =
#things that can be fired and forgot.
newsLetterManager.subscribe user
ReferalAllocator.allocate req.session.referal_id, user._id, req.session.referal_source, req.session.referal_medium
emailOpts =
first_name:user.first_name
to: user.email
EmailHandler.sendEmail "welcome", emailOpts
requestPasswordReset : (req, res)->
res.render 'user/passwordReset',

View file

@ -57,14 +57,17 @@ describe "Subscription Handler sanboxed", ->
userHasSubscription: sinon.stub()
userHasSubscriptionOrFreeTrial: sinon.stub()
@EmailHandler =
sendEmail:sinon.stub()
@SubscriptionHandler = SandboxedModule.require modulePath, requires:
"./RecurlyWrapper": @RecurlyWrapper
"settings-sharelatex": @Settings
'../../models/User': User:@User
'./SubscriptionUpdater': @SubscriptionUpdater
'../../Features/Analytics/AnalyticsManager': @AnalyticsManager
'../Analytics/AnalyticsManager': @AnalyticsManager
"logger-sharelatex":{log:->}
'./LimitationsManager':@LimitationsManager
"../Email/EmailHandler":@EmailHandler
@SubscriptionHandler.syncSubscriptionToUser = sinon.stub().callsArgWith(2)
@ -150,6 +153,9 @@ describe "Subscription Handler sanboxed", ->
.calledWith(@user)
.should.equal true
it "should send a cancellation email", ->
@EmailHandler.sendEmail.calledWith("canceledSubscription", {to:@user.email, first_name:@user.first_name}).should.equal true
describe "reactiveRecurlySubscription", ->
describe "with a user without a subscription", ->
beforeEach (done) ->