|
@@ -12,8 +12,9 @@ describe "UserRegistrationHandler", ->
|
|
|
@user =
|
|
@user =
|
|
|
_id: @user_id = "31j2lk21kjl"
|
|
_id: @user_id = "31j2lk21kjl"
|
|
|
@User =
|
|
@User =
|
|
|
- findOne:sinon.stub()
|
|
|
|
|
update: sinon.stub().callsArgWith(2)
|
|
update: sinon.stub().callsArgWith(2)
|
|
|
|
|
+ @UserGetter =
|
|
|
|
|
+ getUserByMainEmail: sinon.stub()
|
|
|
@UserCreator =
|
|
@UserCreator =
|
|
|
createNewUser:sinon.stub().callsArgWith(1, null, @user)
|
|
createNewUser:sinon.stub().callsArgWith(1, null, @user)
|
|
|
@AuthenticationManager =
|
|
@AuthenticationManager =
|
|
@@ -26,6 +27,7 @@ describe "UserRegistrationHandler", ->
|
|
|
getNewToken: sinon.stub()
|
|
getNewToken: sinon.stub()
|
|
|
@handler = SandboxedModule.require modulePath, requires:
|
|
@handler = SandboxedModule.require modulePath, requires:
|
|
|
"../../models/User": {User:@User}
|
|
"../../models/User": {User:@User}
|
|
|
|
|
+ "./UserGetter": @UserGetter
|
|
|
"./UserCreator": @UserCreator
|
|
"./UserCreator": @UserCreator
|
|
|
"../Authentication/AuthenticationManager":@AuthenticationManager
|
|
"../Authentication/AuthenticationManager":@AuthenticationManager
|
|
|
"../Newsletter/NewsletterManager":@NewsLetterManager
|
|
"../Newsletter/NewsletterManager":@NewsLetterManager
|
|
@@ -70,7 +72,7 @@ describe "UserRegistrationHandler", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@user.holdingAccount = true
|
|
@user.holdingAccount = true
|
|
|
@handler._registrationRequestIsValid = sinon.stub().returns true
|
|
@handler._registrationRequestIsValid = sinon.stub().returns true
|
|
|
- @User.findOne.callsArgWith(1, null, @user)
|
|
|
|
|
|
|
+ @UserGetter.getUserByMainEmail.callsArgWith(1, null, @user)
|
|
|
|
|
|
|
|
it "should not create a new user if there is a holding account there", (done)->
|
|
it "should not create a new user if there is a holding account there", (done)->
|
|
|
@handler.registerNewUser @passingRequest, (err)=>
|
|
@handler.registerNewUser @passingRequest, (err)=>
|
|
@@ -94,7 +96,7 @@ describe "UserRegistrationHandler", ->
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
it "should return email registered in the error if there is a non holdingAccount there", (done)->
|
|
it "should return email registered in the error if there is a non holdingAccount there", (done)->
|
|
|
- @User.findOne.callsArgWith(1, null, @user = {holdingAccount:false})
|
|
|
|
|
|
|
+ @UserGetter.getUserByMainEmail.callsArgWith(1, null, @user = {holdingAccount:false})
|
|
|
@handler.registerNewUser @passingRequest, (err, user)=>
|
|
@handler.registerNewUser @passingRequest, (err, user)=>
|
|
|
err.should.deep.equal new Error("EmailAlreadyRegistered")
|
|
err.should.deep.equal new Error("EmailAlreadyRegistered")
|
|
|
user.should.deep.equal @user
|
|
user.should.deep.equal @user
|
|
@@ -103,7 +105,7 @@ describe "UserRegistrationHandler", ->
|
|
|
describe "validRequest", ->
|
|
describe "validRequest", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@handler._registrationRequestIsValid = sinon.stub().returns true
|
|
@handler._registrationRequestIsValid = sinon.stub().returns true
|
|
|
- @User.findOne.callsArgWith 1
|
|
|
|
|
|
|
+ @UserGetter.getUserByMainEmail.callsArgWith 1
|
|
|
|
|
|
|
|
it "should create a new user", (done)->
|
|
it "should create a new user", (done)->
|
|
|
@handler.registerNewUser @passingRequest, (err)=>
|
|
@handler.registerNewUser @passingRequest, (err)=>
|