-1

I try to use phpunit with Laravel and Spatie but i have a issue.

I have this test :

 public function testBasicTest()
    {

        $user = User::where('id', 2)->first();

        $response = $this->actingAs($user, 'api')->json('POST', '/providersList', [
            'database' => 'test'
        ]);

        $response->assertStatus(200);   
    }

But i have a 401 error

  Expected status code 200 but received 401. Failed asserting that 200 is identical to 401.

I have this in web.php

Route::group(['middleware' => ['auth:api','role:Admin']], function() {

    Route::post('/providersList', 'ProviderController@index');

});
apokryfos
  • 38,771
  • 9
  • 70
  • 114
Zekura
  • 317
  • 4
  • 13

2 Answers2

0

This is a common issue when doing testing, I can assure you that the cause of this error is because of your authentication because of 401 HTTP error code, check if the acting user has role admin

Vortechron
  • 51
  • 1
  • 3
0

To get a better error output, add this to the top of your test function

 $this->withoutExceptionHandling();

It should give a better idea of what the issue is.

damask
  • 529
  • 4
  • 17