Fix tests after refactoring register validation

This commit is contained in:
Alasdair Smith 2018-10-04 13:48:57 +01:00
parent 676557a051
commit 1ef947b1fe
2 changed files with 58 additions and 17 deletions

View file

@ -94,6 +94,48 @@ describe "AuthenticationManager", ->
it "should not return a user", -> it "should not return a user", ->
@callback.calledWith(null, null).should.equal true @callback.calledWith(null, null).should.equal true
describe "validateEmail", ->
describe "valid", ->
it "should return null", ->
result = @AuthenticationManager.validateEmail 'foo@example.com'
expect(result).to.equal null
describe "invalid", ->
it "should return validation error object for no email", ->
result = @AuthenticationManager.validateEmail ''
expect(result).to.not.equal null
expect(result.message).to.equal 'email not valid'
it "should return validation error object for invalid", ->
result = @AuthenticationManager.validateEmail 'notanemail'
expect(result).to.not.equal null
expect(result.message).to.equal 'email not valid'
describe "validatePassword", ->
it "should return null if valid", ->
result = @AuthenticationManager.validatePassword 'banana'
expect(result).to.equal null
describe "invalid", ->
beforeEach ->
@settings.passwordStrengthOptions =
length:
max:10
min:6
it "should return validation error object if not set", ->
result = @AuthenticationManager.validatePassword()
expect(result).to.not.equal null
expect(result.message).to.equal 'password not set'
it "should return validation error object if too short", ->
result = @AuthenticationManager.validatePassword 'dsd'
expect(result).to.not.equal null
expect(result.message).to.equal 'password is too short'
it "should return validation error object if too long", ->
result = @AuthenticationManager.validatePassword 'dsdsadsadsadsadsadkjsadjsadjsadljs'
describe "setUserPassword", -> describe "setUserPassword", ->
beforeEach -> beforeEach ->
@user_id = ObjectId() @user_id = ObjectId()

View file

@ -19,6 +19,8 @@ describe "UserRegistrationHandler", ->
@UserCreator = @UserCreator =
createNewUser:sinon.stub().callsArgWith(1, null, @user) createNewUser:sinon.stub().callsArgWith(1, null, @user)
@AuthenticationManager = @AuthenticationManager =
validateEmail: sinon.stub().returns(null)
validatePassword: sinon.stub().returns(null)
setUserPassword: sinon.stub().callsArgWith(2) setUserPassword: sinon.stub().callsArgWith(2)
@NewsLetterManager = @NewsLetterManager =
subscribe: sinon.stub().callsArgWith(1) subscribe: sinon.stub().callsArgWith(1)
@ -44,29 +46,26 @@ describe "UserRegistrationHandler", ->
describe 'validate Register Request', -> describe 'validate Register Request', ->
it 'allows passing validation through', ->
it 'allow working account through', ->
result = @handler._registrationRequestIsValid @passingRequest result = @handler._registrationRequestIsValid @passingRequest
result.should.equal true result.should.equal true
it 'not allow not valid email through ', ()-> describe 'failing email validation', ->
@passingRequest.email = "notemail" beforeEach ->
@AuthenticationManager.validateEmail.returns({ message: 'email not set' })
it 'does not allow through', ->
result = @handler._registrationRequestIsValid @passingRequest result = @handler._registrationRequestIsValid @passingRequest
result.should.equal false result.should.equal false
it 'not allow no email through ', -> describe 'failing password validation', ->
@passingRequest.email = "" beforeEach ->
@AuthenticationManager.validatePassword.returns({ message: 'password is too short' })
it 'does not allow through', ->
result = @handler._registrationRequestIsValid @passingRequest result = @handler._registrationRequestIsValid @passingRequest
result.should.equal false result.should.equal false
it 'not allow no password through ', ()->
@passingRequest.password= ""
result = @handler._registrationRequestIsValid @passingRequest
result.should.equal false
describe "registerNewUser", -> describe "registerNewUser", ->
describe "holdingAccount", (done)-> describe "holdingAccount", (done)->