From ffe690afa3a953a52bf3c7de331209674f6df2c4 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 5 Mar 2014 14:56:52 +0000 Subject: [PATCH] hooked up lifetime emails --- .../web/app/coffee/Features/Email/EmailHandler.coffee | 2 +- .../Features/Subscription/SubscriptionHandler.coffee | 8 ++++++-- services/web/app/coffee/controllers/UserController.coffee | 4 ++++ .../coffee/Subscription/SubscriptionHandlerTests.coffee | 8 +++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/services/web/app/coffee/Features/Email/EmailHandler.coffee b/services/web/app/coffee/Features/Email/EmailHandler.coffee index 6316c21511..732009c12c 100644 --- a/services/web/app/coffee/Features/Email/EmailHandler.coffee +++ b/services/web/app/coffee/Features/Email/EmailHandler.coffee @@ -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() diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionHandler.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionHandler.coffee index cdcf4da724..cdba20a0cc 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionHandler.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionHandler.coffee @@ -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 = - diff --git a/services/web/app/coffee/controllers/UserController.coffee b/services/web/app/coffee/controllers/UserController.coffee index 13b0a7d2f6..a4b139fec4 100644 --- a/services/web/app/coffee/controllers/UserController.coffee +++ b/services/web/app/coffee/controllers/UserController.coffee @@ -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', diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionHandlerTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionHandlerTests.coffee index 118fd680fe..e2e6bdbb44 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionHandlerTests.coffee @@ -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) ->