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.");
}