2024-05-07 10:59:24 -07:00
|
|
|
<?php
|
|
|
|
|
2024-05-31 18:59:04 -07:00
|
|
|
namespace Tests\Feature\Users;
|
2024-05-07 10:59:24 -07:00
|
|
|
|
|
|
|
use App\Models\Location;
|
|
|
|
use App\Models\User;
|
|
|
|
use Laravel\Passport\Passport;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-05-31 18:59:04 -07:00
|
|
|
class DeleteUsersTest extends TestCase
|
2024-05-07 10:59:24 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public function testDisallowUserDeletionIfStillManagingPeople()
|
|
|
|
{
|
|
|
|
$manager = User::factory()->create(['first_name' => 'Manager', 'last_name' => 'McManagerson']);
|
|
|
|
User::factory()->create(['first_name' => 'Lowly', 'last_name' => 'Worker', 'manager_id' => $manager->id]);
|
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisallowUserDeletionIfStillManagingLocations()
|
|
|
|
{
|
|
|
|
$manager = User::factory()->create(['first_name' => 'Manager', 'last_name' => 'McManagerson']);
|
|
|
|
Location::factory()->create(['manager_id' => $manager->id]);
|
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAllowUserDeletionIfNotManagingLocations()
|
|
|
|
{
|
|
|
|
$manager = User::factory()->create(['first_name' => 'Manager', 'last_name' => 'McManagerson']);
|
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())->assertTrue($manager->isDeletable());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisallowUserDeletionIfNoDeletePermissions()
|
|
|
|
{
|
|
|
|
$manager = User::factory()->create(['first_name' => 'Manager', 'last_name' => 'McManagerson']);
|
|
|
|
Location::factory()->create(['manager_id' => $manager->id]);
|
|
|
|
$this->actingAs(User::factory()->editUsers()->create())->assertFalse($manager->isDeletable());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|