dillingham / nova-assertions

Laravel Nova assertions for your tests
MIT License
79 stars 16 forks source link

AuthenticationException #11

Open andersespedalen opened 4 years ago

andersespedalen commented 4 years ago

In the browser, login works fine using the same user as in the test Regardless of using the seeded data, or creating the user in the test, I'm getting Unauthenticated when testing Index

test

public function admin_user_can_access_nova()
    {
        $this->be(User::create([
            'name' => 'admin',
            'email' => 'admin@mysite.com',
            'password' => bcrypt('Test1234'),
        ]));

        $response = $this->novaIndex('users');
        $response->assertOk();
        $response->assertCanView();
        $response->assertCanCreate();
        $response->assertCanUpdate();
        $response->assertCanDelete();
        $response->assertCanForceDelete();
        $response->assertCanRestore();
    }

In NovaServiceProvider, even I allow all users to debug

    protected function gate()
    {
        Gate::define('viewNova', function ($user) {
            return true;
        });
    }

PHPUnit

There was 1 error:
1) Tests\Feature\NovaTest::admin_user_can_access_nova
Laravel\Nova\Exceptions\AuthenticationException: Unauthenticated.

Environment:

Homestead 10
Laravel 7
Nova 3.14
dillingham commented 4 years ago

@andersespedalen hmmm I'll have to check with this specific version of nova maybe

Current version works for me

brunocfalcao commented 3 years ago

Hi @andersespedalen ,

I think you need to pass the default argument value to null in your define method.

Not ($user) but ($user = null).

As this:

protected function gate()
    {
        Gate::define('viewNova', function ($user = null) {
            return true;
        });
    }
andersespedalen commented 3 years ago

Don't think so. The callback of Gate::define() does not require a default value. At least not according to the Laravel documentation or the rest of my project. And adding it does not fix the problem.