60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\V3\Permission;
|
|
|
|
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;
|
|
/**
|
|
* A basic feature test example.
|
|
*/
|
|
public function test_user_should_have_manage_permission(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->getJson(route('v3.permissions.index'));
|
|
|
|
$response->assertForbidden();
|
|
}
|
|
|
|
public function test_all_permissions_returned_successfully(): void
|
|
{
|
|
$user = User::factory()
|
|
->has(Permission::factory([
|
|
'name' => 'manage-permissions'
|
|
]))
|
|
->create();
|
|
|
|
$response = $this->actingAs($user)->getJson(route('v3.permissions.index', [
|
|
'start' => 0,
|
|
'size' => 10,
|
|
'filters' => json_encode([]),
|
|
'sorting' => json_encode([]),
|
|
]));
|
|
|
|
$response->assertOk();
|
|
|
|
$response->assertJsonStructure([
|
|
'data' => [
|
|
'*' => [
|
|
'id',
|
|
'name',
|
|
'name_fa',
|
|
'type',
|
|
'type_fa',
|
|
'description',
|
|
],
|
|
],
|
|
"meta" => [
|
|
"totalRowCount"
|
|
]
|
|
]);
|
|
}
|
|
}
|