title: creation of unit tests with users
body: <p>I want to test the next method of my controller</p>
  
  <pre><code>function index(){
          if(Auth::User()-&gt;can('view_roles'))
          {
              $roles = Role::all();
              return response()-&gt;json(['data' =&gt; $roles], 200);
          }
  
          return response()-&gt;json(['Not_authorized'], 401);
      }
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <pre><code>public function testIndexRole()
  {
      $this-&gt;json('GET', '/role')-&gt;seeJson([
          'name' =&gt; 'admin',
          'name' =&gt; 'secratary'
      ]);
  }
  </code></pre>