Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. var Accounts = function(){
  2. return{
  3. registerNewUser : function(req,res){
  4. console.log(req.body);
  5. var email = req.body.email;
  6. var password = req.body.password;
  7.  
  8. if(email === undefined || password === undefined){
  9. res.status(400).end('Required Fields Missing');
  10. }
  11. else{
  12. email = email.trim();
  13. password = password.trim();
  14. console.log('lengths = ', email.length, ' password length = ', password.length);
  15. if(email.length <= 0 || password.length <= 0){
  16. res.status(400).end('Bad Request');
  17. }
  18. else{
  19. res.status(200).end('ok');
  20. }
  21. }
  22.  
  23.  
  24. }
  25. }
  26.  
  27. }
  28.  
  29. module.exports = new Accounts();
  30.  
  31. describe('Testing Route to Register New User', function(){
  32. var server;
  33. beforeEach(function(){
  34. server = app.startServer();
  35. });
  36. afterEach(function(done){
  37. server.close();
  38. done();
  39. });
  40. it('Missing required fields test', function(done){
  41. request(app).post('/register',{
  42. }).expect(400).end(done);
  43.  
  44. }) ;
  45. it('Empty field test',function(done){
  46. request(app).post('/register',{
  47. email:"",
  48. password:" "
  49. }).expect(400).end(done);
  50. });
  51.  
  52. it('Should accept the correct email and password',function(done){
  53. request(app).post('/register',{
  54. email:"email",
  55. password:"alskdjfs"
  56. }).expect(200).end(done);
  57. });
  58.  
  59. });
  60.  
  61. Testing Route to Register New User
  62. API Server listening on port 3000
  63. {}
  64. ✓ Missing required fields test
  65. API Server listening on port 3000
  66. {}
  67. ✓ Empty field test
  68. API Server listening on port 3000
  69. {}
  70. 1) Should accept the correct email and password
  71.  
  72.  
  73. 2 passing (65ms)
  74. 1 failing
  75.  
  76. 1) Testing Route to Register New User Should accept the correct email and password:
  77. Error: expected 200 "OK", got 400 "Bad Request"
  78. at Test._assertStatus (node_modules/supertest/lib/test.js:232:12)
  79. at Test._assertFunction (node_modules/supertest/lib/test.js:247:11)
  80. at Test.assert (node_modules/supertest/lib/test.js:148:18)
  81. at Server.assert (node_modules/supertest/lib/test.js:127:12)
  82. at emitCloseNT (net.js:1521:8)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement