mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 04:45:21 -05:00
Fix tests after refactoring register validation
This commit is contained in:
parent
676557a051
commit
1ef947b1fe
2 changed files with 58 additions and 17 deletions
|
@ -94,6 +94,48 @@ describe "AuthenticationManager", ->
|
|||
it "should not return a user", ->
|
||||
@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", ->
|
||||
beforeEach ->
|
||||
@user_id = ObjectId()
|
||||
|
|
|
@ -19,6 +19,8 @@ describe "UserRegistrationHandler", ->
|
|||
@UserCreator =
|
||||
createNewUser:sinon.stub().callsArgWith(1, null, @user)
|
||||
@AuthenticationManager =
|
||||
validateEmail: sinon.stub().returns(null)
|
||||
validatePassword: sinon.stub().returns(null)
|
||||
setUserPassword: sinon.stub().callsArgWith(2)
|
||||
@NewsLetterManager =
|
||||
subscribe: sinon.stub().callsArgWith(1)
|
||||
|
@ -44,28 +46,25 @@ describe "UserRegistrationHandler", ->
|
|||
|
||||
|
||||
describe 'validate Register Request', ->
|
||||
|
||||
|
||||
it 'allow working account through', ->
|
||||
it 'allows passing validation through', ->
|
||||
result = @handler._registrationRequestIsValid @passingRequest
|
||||
result.should.equal true
|
||||
|
||||
it 'not allow not valid email through ', ()->
|
||||
@passingRequest.email = "notemail"
|
||||
result = @handler._registrationRequestIsValid @passingRequest
|
||||
result.should.equal false
|
||||
|
||||
it 'not allow no email through ', ->
|
||||
@passingRequest.email = ""
|
||||
result = @handler._registrationRequestIsValid @passingRequest
|
||||
result.should.equal false
|
||||
|
||||
it 'not allow no password through ', ()->
|
||||
@passingRequest.password= ""
|
||||
result = @handler._registrationRequestIsValid @passingRequest
|
||||
result.should.equal false
|
||||
describe 'failing email validation', ->
|
||||
beforeEach ->
|
||||
@AuthenticationManager.validateEmail.returns({ message: 'email not set' })
|
||||
|
||||
it 'does not allow through', ->
|
||||
result = @handler._registrationRequestIsValid @passingRequest
|
||||
result.should.equal false
|
||||
|
||||
describe 'failing password validation', ->
|
||||
beforeEach ->
|
||||
@AuthenticationManager.validatePassword.returns({ message: 'password is too short' })
|
||||
|
||||
it 'does not allow through', ->
|
||||
result = @handler._registrationRequestIsValid @passingRequest
|
||||
result.should.equal false
|
||||
|
||||
describe "registerNewUser", ->
|
||||
|
||||
|
|
Loading…
Reference in a new issue