UserRegistrationHandlerTests.coffee 2.3 KB

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