diff --git a/services/web/app/coffee/Features/User/UserController.coffee b/services/web/app/coffee/Features/User/UserController.coffee index 6aff636f35..0c02568352 100644 --- a/services/web/app/coffee/Features/User/UserController.coffee +++ b/services/web/app/coffee/Features/User/UserController.coffee @@ -9,6 +9,7 @@ metrics = require("../../infrastructure/Metrics") Url = require("url") AuthenticationController = require("../Authentication/AuthenticationController") AuthenticationManager = require("../Authentication/AuthenticationManager") +ReferalAllocator = require("../Referal/ReferalAllocator") module.exports = @@ -61,6 +62,7 @@ module.exports = metrics.inc "user.register.success" req.session.user = user req.session.justRegistered = true + ReferalAllocator.allocate req.session.referal_id, user._id, req.session.referal_source, req.session.referal_medium res.send redir:redir id:user._id.toString() @@ -69,6 +71,7 @@ module.exports = email: user.email created: Date.now() + changePassword : (req, res, next = (error) ->)-> metrics.inc "user.password-change" oldPass = req.body.currentPassword diff --git a/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee b/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee index f25e89450d..e808b4cb1c 100644 --- a/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee @@ -33,6 +33,8 @@ describe "UserController", -> @AuthenticationManager = authenticate: sinon.stub() setUserPassword: sinon.stub() + @ReferalAllocator = + allocate:sinon.stub() @UserController = SandboxedModule.require modulePath, requires: "./UserLocator": @UserLocator "./UserDeleter": @UserDeleter @@ -41,6 +43,7 @@ describe "UserController", -> "./UserRegistrationHandler":@UserRegistrationHandler "../Authentication/AuthenticationController": @AuthenticationController "../Authentication/AuthenticationManager": @AuthenticationManager + "../Referal/ReferalAllocator":@ReferalAllocator "logger-sharelatex": {log:->} @@ -151,6 +154,19 @@ describe "UserController", -> done() @UserController.register @req, @res + it "should allocate the referals", (done)-> + @req.session = + referal_id : "23123" + referal_source : "email" + referal_medium : "bob" + + @UserRegistrationHandler.registerNewUser.callsArgWith(1, null, @user) + @req.body.redir = "/somewhere" + @res.send = (opts)=> + @ReferalAllocator.allocate.calledWith(@req.session.referal_id, @user._id, @req.session.referal_source, @req.session.referal_medium).should.equal true + done() + @UserController.register @req, @res + describe "changePassword", ->