lundi 19 septembre 2016

Unit test MEAN app with Jasmine newbie questions

I’m starting to learn Jasmine unit testing (i’m using Jasmine 2.5). Therefore I’m having little problem to understand some things and questions . What are good extensions for jasmine which will improve my work. How to test code like this

router.post('/user/login', function (req, res, next) {
  var data = {
    email: String,
    msg: String
  }
  console.log("In user/login:" + req.body.email + " " + req.body.password);

  if (Auth.isAlphaNumeric(req.body.password) && Auth.isEmailAddress(req.body.email)) {
    User.findOne({ email: { $regex: new RegExp("^" + req.body.email, "i") }, password: req.body.password }, function (err, doc) {

      if (doc) {
        data.msg = "AUTHORIZATION_SUCCESS";
        req.session.email = req.body.email;
        req.session.save();
      } else {
        data.msg = "AUTHORIZATION_FAILED";
      }

      res.send(JSON.stringify(data));
    })
  }
  else {
    data.msg = "AUTHORIZATION_FAILED";
    res.send(JSON.stringify(data));
  }
});

I have read that it is good pratice to dont get data from database but how to solve this problem with above example and what to do with session ?, add it somehow to spec or is there a better solution ?

With Jasmine can i test Angular 2 and TypeScript? If yes then is it hard ? do i need some tools to do this?

Aucun commentaire:

Enregistrer un commentaire