added referal allocator to user controller

This commit is contained in:
Henry Oswald 2014-04-15 13:59:00 +01:00
parent c2cb6e2c1f
commit aca2e5639e
2 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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", ->