Explorar el Código

added referal allocator to user controller

Henry Oswald hace 12 años
padre
commit
aca2e5639e

+ 3 - 0
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

+ 16 - 0
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", ->