Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wilfredlepelaar's avatar

How to test Laravel Nova Api route policies | TDD

How can I test API route policies for Nova resources? When I run the following test I receive a 403 response. (without any policies set)

    $response = $this->json('POST', 'nova-api/users', [
        'name' => 'Fancy Name',
        'password' => 'secretpassword',
        'email' => '[email protected]'
    ]);

    $response
        ->assertStatus(200)
        ->assertJson([
            'created' => true,
        ]);
0 likes
1 reply
thomas_inckx's avatar
Level 5

Hi, I find this repo/nova testing guide very helpful: https://github.com/bradenkeith/testing-nova.

You could setUp() your test with $this->user->assignRole('the_role_you_want_to_test'); and then go on testing your resources and policies.

(I stumbled upon this issue because I myself am stuck with a 404 response testing the nova api routes)

1 like

Please or to participate in this conversation.