dillingham / nova-assertions

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

nova test policy #29

Closed r0gu30n3 closed 3 years ago

r0gu30n3 commented 3 years ago

Hello, it is my redic problem in that when you do tests with a user who does not have permissions, ak runs my test only passes the one that cannot create but those to update and but it does not happen because this error is due

namespace Tests\Feature;

use App\User; use NovaTesting\NovaAssertions; use Illuminate\Support\Facades\Config; use Tests\TestCase;

class UserNovaTest extends TestCase { use NovaAssertions;

/* function __construct()
{
    parent::setUp();
} */

public function PolicyCannot($index)
{
    $user = User::where('name', 'roberto')->first();
    $this->actingAs($user)->withSession(['business_center_id' => 1]);
    Config::set('testing.viewAny', false);
    Config::set('testing.create', false);
    Config::set('testing.update', false);
    Config::set('testing.delete', false);
    Config::set('testing.restore', false);  
    Config::set('testing.forceDelete', false); 
    $response = $this->novaIndex($index);
    $response->assertStatus(403);
    $response->assertCannotCreate();
    $response->assertCannotUpdate();
    $response->assertCannotDelete();
    $response->assertCannotForceDelete();
    $response->assertCannotRestore();
} 
public function test_user_nova()
{
    $this->PolicyCannot('offices');
    $this->PolicyCannot('patients');
    $this->PolicyCannot('appointments');
    $this->PolicyCannot('promotions');
    $this->PolicyCannot('medical-services-categories');
    $this->PolicyCannot('appointment-statuses');
    $this->PolicyCannot('professionals');
    $this->PolicyCannot('medical-services');
    $this->PolicyCannot('symptom-categories');
    $this->PolicyCannot('records');
    $this->PolicyCannot('medical-records');  
}

}

r0gu30n3 commented 3 years ago

error Time: 00:00.402, Memory: 34.00 MB

There was 1 failure:

1) Tests\Feature\UserNovaTest::test_user_nova Unable to find JSON fragment:

[{"authorizedToUpdate":false}]