Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe('Testing Route to Register New User', function(){
- var server;
- beforeEach(function(){
- server = app.startServer();
- });
- afterEach(function(done){
- server.close();
- done();
- });
- it('Missing required fields test', function(done){
- request(app).post('/register',{
- }).expect(400).end(done);
- }) ;
- it('Empty field test',function(done){
- request(app).post('/register',{
- email:"",
- password:""
- }).expect(400).end(done);
- });
- it('Should accept the correct email and password',function(done){
- request(app).post('/register',{
- email:"email",
- password:"alskdjfs"
- }).expect(200).end(done);
- });
- });
- //Accounts REST API endpoint logic.
- var Accounts = function(){
- return{
- registerNewUser : function(req,res){
- var email = req.body.email;
- var password = req.body.password;
- if(email === undefined || password === undefined){
- res.status(400).end('Required Fields Missing');
- }
- else{
- email = email.trim();
- password = password.trim();
- console.log('lengths = ', email.length, ' password length = ', password.length);
- if(email.length <=0 || password.length <= 0){
- res.status(400).end('Bad Requester');
- }
- else{
- res.status(200).end('ok');
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment