Monday, March 5, 2018

creation of unit tests with users - development

creation of unit tests with users

I want to test the next method of my controller

function index(){
        if(Auth::User()->can('view_roles'))
        {
            $roles = Role::all();
            return response()->json(['data' => $roles], 200);
        }

        return response()->json(['Not_authorized'], 401);
    }

it is already configured for authentication (tymondesigns / jwt-auth) and the management of roles (spatie / laravel-permission), testing with postman works, I just want to do it in an automated way.

This is the test code, if I remove the conditional function of the controller the TEST passes, but I would like to do a test using a user but I have no idea how to do it.

public function testIndexRole()
{
    $this->json('GET', '/role')->seeJson([
        'name' => 'admin',
        'name' => 'secratary'
    ]);
}



from Laravel Questions and Answers https://laravelquestions.com/php/creation-of-unit-tests-with-users/
via Lzo Media

No comments:

Post a Comment