1

I received a test suite written in js using mocha. This is the test method i am attempting to get to work. They are sending the data as form encoded. My controller accepts data in the form body(method below) My model contains the same properties. How do i rewrite the js method to match my controller?

  function loginUser (auth) {
      return function (done) {
        request('https://mysites/api/').post('login')
          .set('Content-Type', 'application/x-www-form-urlencoded')
          .set('emulateJSON', true)
          .timeout({response: 30000, deadline: 30000})
          .send({grant_type: 'password', Username: 'TheUserName', Password: 'Password'})
          .end(function (err, response) {
            assert.equal(response.status, 200)
            console.log('Response: ', response.body)
            auth.token = response.body.access_token
            done()
          })
      };
    }



[AllowAnonymous]
[HttpPost]
public IActionResult Post([FromBody]LoginDto loginViewModel)
{
    if (ModelState.IsValid)
    {
        //This method returns user id from username and password.
        var attemptedUser = GetUserInfoFromLoginViewModel(loginViewModel);
        if (attemptedUser.Username == null)
        {
            return BadRequest("invalid_grant, The user name or password is incorrect.");
        }
Leonardo Wildt
  • 2,529
  • 5
  • 27
  • 56

1 Answers1

0

In case anyone is wondering the answer is to add

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

to the top of your tests.specs.js file. It is a self signed certificate issue. I found the answer posted in another question

Leonardo Wildt
  • 2,529
  • 5
  • 27
  • 56