2

I want to unit test my login flow in a node.js module. I think that every time it encounter any NPM dependency like here I used stitching. It never goes inside stitching.auth() and I get response undefined. Here is my code..

     module.exports.login = function(req, res) {
    const stitching = require("stitching");
        // User email/password
        const email = req.body.email;
        const password = req.body.password;
        var msg;
        // Login using the given email/password
        stitching.auth
        .login(email, password)
        .then((credentials) => {
           console.log('Login authenticated ...');  
            res.send("authenticated");
        },
        function failureHandler(error) {
        if(error=='Error: Wrong email/password')
        {
            console.log(error);
            res.send("error");
        }

      //handle
     }).catch(console.error);
    }

and my jasmine unit test is..

 describe("POST /",function(){
it("The function should authenticate the user",function() {
       const loginTest  =   require('../login_controller');
        const mocks = require('node-mocks-http');
        var req = {};
        var res = {};
        req = mocks.createRequest();
        res = mocks.createResponse();
        req.body.email = "mongo.sitch@gmail.com";
        req.body.password = "abcd34";
        value   =   loginTest.login(req,res);
        console.log(value);
        expect(value).toBe("authenticated");
});
});

0 Answers0