Expected status code 200 but received 302.

Published 3 months ago by BishoyWagih

i'm trying to perform a test to check if 1 - the user is authenticated 2 - has permission to view the requested page

every time i run the test i get this error

Expected status code 200 but received 302.

Here is my TestMethod

 /** @test */

public function it_can_see_all_categories()
    $user = $user = factory(User::class)->create();

    $permission = Permission::create(['group' => 'categories' , 'name' => 'view categories' , 'label' => 'view categories']);

    $role = Role::find($user->role_id);


    $response = $this->get('/categories');

    $response->assertStatus(200 , $response->getStatusCode());
3 months ago (200,570 XP)

try to change this

  $user = $user = factory(User::class)->create();

to this

  $user = factory(User::class)->create();

this is typing mistake from me here, not in the code


Does your route for '/categories' use any middleware such as auth? That would be returning a 302 when it redirects you to the auth/login page whenever it gets hit.


yes i have a middleware auth, also i have authorization on request with permission view categories, please see this alse,,


Please sign in or create an account to participate in this conversation.