Guest User

Untitled

a guest
Apr 22nd, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1.  
  2. describe('Testing Route to Register New User', function(){
  3. var server;
  4. beforeEach(function(){
  5. server = app.startServer();
  6. });
  7. afterEach(function(done){
  8. server.close();
  9. done();
  10. });
  11. it('Missing required fields test', function(done){
  12. request(app).post('/register',{
  13. }).expect(400).end(done);
  14.  
  15. }) ;
  16. it('Empty field test',function(done){
  17. request(app).post('/register',{
  18. email:"",
  19. password:""
  20. }).expect(400).end(done);
  21. });
  22.  
  23. it('Should accept the correct email and password',function(done){
  24. request(app).post('/register',{
  25. email:"email",
  26. password:"alskdjfs"
  27. }).expect(200).end(done);
  28. });
  29.  
  30. });
  31.  
  32.  
  33.  
  34. //Accounts REST API endpoint logic.
  35. var Accounts = function(){
  36. return{
  37. registerNewUser : function(req,res){
  38. var email = req.body.email;
  39. var password = req.body.password;
  40.  
  41. if(email === undefined || password === undefined){
  42. res.status(400).end('Required Fields Missing');
  43. }
  44. else{
  45. email = email.trim();
  46. password = password.trim();
  47. console.log('lengths = ', email.length, ' password length = ', password.length);
  48. if(email.length <=0 || password.length <= 0){
  49. res.status(400).end('Bad Requester');
  50. }
  51. else{
  52. res.status(200).end('ok');
  53. }
  54. }
  55.  
  56.  
  57. }
  58. }
  59.  
  60. }
Add Comment
Please, Sign In to add comment