write test for another items and change some part of the code

This commit is contained in:
2025-05-14 15:38:33 +03:30
parent db8cda55df
commit 16fe0be555
20 changed files with 1258 additions and 45 deletions

View File

@@ -0,0 +1,61 @@
<?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 DeleteTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function test_unauthenticated_user_cannot_access(): void
{
$user = User::factory()->create();
$response = $this->getJson(route('users.destroy',[$user->id]));
$response->assertUnauthorized();
}
public function test_user_without_permission_cannot_destroy_users(): void
{
$user = User::factory()
->create();
$response = $this->actingAs($user)->getJson(route('users.destroy',[$user->id]));
$response->assertForbidden();
}
public function test_superAdmin_cant_updated()
{
$user = User::factory()->create([
'username' => "witel",
]);
$response = $this->actingAs($user)->getJson(route('users.destroy',[$user->id]));
$response->assertForbidden();
}
public function test_can_delete_a_user()
{
$user = User::factory()
->has(permission::factory([
'name'=> 'manage_users',
"name_fa" => 'مدیریت کاربران',
]))
->create();
$response = $this->actingAs($user)->deleteJson(route('users.destroy', [$user->id]));
$response->assertStatus(200)
->assertExactJson([
'message' => __('messages.successful')
]);
$this->assertDatabaseMissing('users', [
'username' => $user->username
]);
}
}