write test for another items and change some part of the code
This commit is contained in:
59
tests/Feature/User/IndexTest.php
Normal file
59
tests/Feature/User/IndexTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\User;
|
||||
|
||||
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('users.index'));
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
public function test_user_without_permission_cannot_see_index(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$response = $this->actingAs($user)->getJson(route('users.index'));
|
||||
$response->assertForbidden();
|
||||
}
|
||||
public function test_all_users_returned_successfully_for_index_user(): void
|
||||
{
|
||||
$user = User::factory()
|
||||
->has(permission::factory([
|
||||
'name'=> 'manage_users',
|
||||
"name_fa" => 'مدیریت کاربران',
|
||||
]))
|
||||
->create();
|
||||
User::factory()->count(2)->create();
|
||||
$response = $this->actingAs($user)->getJson(route('users.index',[
|
||||
'filters'=> json_encode([]),
|
||||
'sortings'=> json_encode([]),
|
||||
'relations'=> ['roles:id,name_fa']
|
||||
]));
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([
|
||||
'data' => [
|
||||
'*' => ['id',
|
||||
'full_name',
|
||||
'username',
|
||||
'province_id',
|
||||
'phone_number',
|
||||
'national_id',
|
||||
'telephone_id',
|
||||
],
|
||||
],
|
||||
'meta' => [
|
||||
'totalRowCount'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user