UserRegistrationHandlerTests.coffee 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. should = require('chai').should()
  2. SandboxedModule = require('sandboxed-module')
  3. assert = require('assert')
  4. path = require('path')
  5. modulePath = path.join __dirname, '../../../../app/js/Features/User/UserRegistrationHandler'
  6. describe 'validate Register Request', ->
  7. passingRequest = undefined
  8. controller = undefined
  9. beforeEach ->
  10. controller = SandboxedModule.require modulePath, requires:{}
  11. passingRequest = {body:{email:"something@email.com", password:"123"}}
  12. it 'allow working account through', ->
  13. controller.validateRegisterRequest passingRequest, (err, data)->
  14. should.not.exist(err)
  15. data.first_name.should.equal "something"
  16. data.last_name.should.equal ""
  17. data.email.should.equal passingRequest.body.email
  18. data.password.should.equal passingRequest.body.password
  19. it 'not allow not valid email through ', (done)->
  20. passingRequest.body.email = "notemail"
  21. controller.validateRegisterRequest passingRequest, (err, data)->
  22. should.exist(err)
  23. err.should.equal "not valid email"
  24. done()
  25. it 'not allow no email through ', ->
  26. passingRequest.body.email = ""
  27. controller.validateRegisterRequest passingRequest, (err, data)->
  28. should.exist(err)
  29. err.should.equal "please fill in all the fields"
  30. it 'not allow no password through ', (done)->
  31. passingRequest.body.password= ""
  32. controller.validateRegisterRequest passingRequest, (err, data)->
  33. should.exist(err)
  34. err.should.equal "please fill in all the fields"
  35. done()
  36. it 'trim white space from email', (done)->
  37. passingRequest.body.email = " some@email.com "
  38. controller.validateRegisterRequest passingRequest, (err, data)->
  39. should.not.exist(err)
  40. data.email.should.equal "some@email.com"
  41. done()
  42. it 'lower case email', (done)->
  43. passingRequest.body.email = "soMe@eMail.cOm"
  44. controller.validateRegisterRequest passingRequest, (err, data)->
  45. should.not.exist(err)
  46. data.email.should.equal "some@email.com"
  47. done()
  48. it 'should allow a short registeration request through', (done) ->
  49. controller.validateRegisterRequest body: {
  50. email: "user_name@example.com"
  51. password: passingRequest.body.password
  52. }, (err, data) ->
  53. should.not.exist(err)
  54. data.email.should.equal "user_name@example.com"
  55. data.password.should.equal passingRequest.body.password
  56. data.first_name.should.equal "user_name"
  57. done()