Files
backend/tests/Feature/Role/IndexTest.php

48 lines
1.1 KiB
PHP

<?php
namespace Tests\Feature\Role;
use App\Models\Permission;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class IndexTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function test_unauthenticated_user_cannot_access(): void
{
$response = $this->getJson(route('roles.index'));
$response->assertUnauthorized();
}
public function test_authenticated_user_can_see_roles_index(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->getJson(route('roles.index',[
'filters' => json_encode([]),
'sorting' => json_encode([]),
]));
$response->assertOk();
$response->assertJsonStructure([
'data' => [
'*' => [
'id',
'name',
'name_fa',
],
],
'meta' => [
'totalRowCount'
]
]);
}
}