Wednesday 17 May 2017

Getting response as undefined and getting the error onnect ECONNREFUSED 127.0.0.1:80 in supertest

I've added this to my sample test file. All I want is to get the token

var bodyParser = require('body-parser'); var supertest = require('supertest');

var express = require('express');


var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

 describe('Server Tests', function() {
        it('should verify the server is running', function(done) {

            app.post('https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token', function(req, res) {
                console.log('In the post function');
                res.json(req.body).status(200);
            });

            supertest(app)
                .post('https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token')
                .set({'Host': 'login.microsoftonline.com', 'Content-Type': 'application/x-www-form-urlencoded','Connection': 'keep-alive'})
                .send({
                       grant_type: 'client_credentials',
                       'Content-Type': 'application/x-www-form-urlencoded',
                        client_id: appId,
                        client_secret:  appPassword,
                       'scope': 'https://api.botframework.com/.default'
                })
                .end(function(err, res) {
                    console.log(err);
                    console.log(res);
                    token = res.body.token;
                   // console.log(token);
                    done();
                });
});



via user2825406

No comments:

Post a Comment