1

I'm trying to test my application with mocha, chai and chai-http. When I test the login, I can't seem to log in no matter what I try. I've tried in Postman and gotten the same result.

I've seen many answers along the lines of this one but I've had no success with them.

Is Passport doing something that's preventing successful login? I can log in from the browser with no problem.

Community
  • 1
  • 1
fredrover
  • 2,997
  • 2
  • 17
  • 24

1 Answers1

0

I found an answer in this post and from tinkering with the settings in Postman. Adding the content type x-www-form-urlencoded seemed to be the key.

it('should redirect to dashboard on successful login', function(done) {
    chai.request('http://localhost:3000')
      .post('/login')
      .set('Token', 'text/plain')
      .set('content-type', 'application/x-www-form-urlencoded')
      .type('form')
      .send('grant_type=password')
      .send('username=bobby')
      .send('password=abc123')
      .end(function(err, res) {
        res.should.have.status(200);
        expect(res).to.redirectTo('http://localhost:3000/user/dashboard');
        done();
      });
  });
fredrover
  • 2,997
  • 2
  • 17
  • 24