Added test if user has assets

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-06-05 14:16:28 +01:00
parent c5cbe37007
commit 374c6845d6

View file

@ -2,11 +2,13 @@
namespace Tests\Feature\Users\Ui;
use Tests\TestCase;
use App\Models\LicenseSeat;
use App\Models\Location;
use App\Models\Accessory;
use App\Models\User;
use Tests\TestCase;
use App\Models\Asset;
class DeleteUserTest extends TestCase
{
@ -94,6 +96,22 @@ class DeleteUserTest extends TestCase
$this->actingAs(User::factory()->editUsers()->viewUsers()->create())->assertFalse($manager->isDeletable());
}
public function testDisallowUserDeletionIfTheyStillHaveAssets()
{
$user = User::factory()->create();
Asset::factory()->count(6)->checkedOutToUser($user)->create();
$this->actingAs(User::factory()->deleteUsers()->viewUsers()->create())->assertFalse($user->isDeletable());
$response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create())
->delete(route('users.destroy', $user->id))
->assertStatus(302)
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Error');
}
public function testUsersCannotDeleteThemselves()
{
$manager = User::factory()->deleteUsers()->viewUsers()->create();