2024-05-07 10:59:24 -07:00
|
|
|
<?php
|
|
|
|
|
2024-06-04 10:48:53 -07:00
|
|
|
namespace Tests\Feature\Users\Ui;
|
2024-05-07 10:59:24 -07:00
|
|
|
|
|
|
|
use App\Models\Location;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-06-03 16:54:59 -07:00
|
|
|
class DeleteUserTest extends TestCase
|
2024-05-07 10:59:24 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public function testDisallowUserDeletionIfStillManagingPeople()
|
|
|
|
{
|
2024-05-31 20:01:09 -07:00
|
|
|
$manager = User::factory()->create();
|
|
|
|
User::factory()->count(3)->create(['manager_id' => $manager->id]);
|
|
|
|
|
2024-05-07 10:59:24 -07:00
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable());
|
2024-05-31 20:01:09 -07:00
|
|
|
|
2024-05-31 20:24:47 -07:00
|
|
|
$response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create())
|
2024-05-31 20:01:09 -07:00
|
|
|
->delete(route('users.destroy', $manager->id))
|
|
|
|
->assertStatus(302)
|
|
|
|
->assertRedirect(route('users.index'));
|
2024-05-31 20:24:47 -07:00
|
|
|
|
|
|
|
$this->followRedirects($response)->assertSee('Error');
|
2024-05-07 10:59:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisallowUserDeletionIfStillManagingLocations()
|
|
|
|
{
|
2024-05-31 20:01:09 -07:00
|
|
|
$manager = User::factory()->create();
|
|
|
|
Location::factory()->count(3)->create(['manager_id' => $manager->id]);
|
|
|
|
|
2024-05-07 10:59:24 -07:00
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable());
|
2024-05-31 20:01:09 -07:00
|
|
|
|
2024-05-31 20:24:47 -07:00
|
|
|
$response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create())
|
2024-05-31 20:01:09 -07:00
|
|
|
->delete(route('users.destroy', $manager->id))
|
|
|
|
->assertStatus(302)
|
|
|
|
->assertRedirect(route('users.index'));
|
2024-05-31 20:24:47 -07:00
|
|
|
|
|
|
|
$this->followRedirects($response)->assertSee('Error');
|
2024-05-07 10:59:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAllowUserDeletionIfNotManagingLocations()
|
|
|
|
{
|
2024-05-31 20:01:09 -07:00
|
|
|
$manager = User::factory()->create();
|
2024-05-07 10:59:24 -07:00
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())->assertTrue($manager->isDeletable());
|
2024-05-31 20:01:09 -07:00
|
|
|
|
2024-05-31 20:24:47 -07:00
|
|
|
$response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create())
|
2024-05-31 20:01:09 -07:00
|
|
|
->delete(route('users.destroy', $manager->id))
|
|
|
|
->assertStatus(302)
|
|
|
|
->assertRedirect(route('users.index'));
|
2024-05-31 20:24:47 -07:00
|
|
|
|
|
|
|
$this->followRedirects($response)->assertSee('Success');
|
|
|
|
|
2024-05-07 10:59:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisallowUserDeletionIfNoDeletePermissions()
|
|
|
|
{
|
2024-05-31 20:01:09 -07:00
|
|
|
$manager = User::factory()->create();
|
2024-05-07 10:59:24 -07:00
|
|
|
Location::factory()->create(['manager_id' => $manager->id]);
|
|
|
|
$this->actingAs(User::factory()->editUsers()->create())->assertFalse($manager->isDeletable());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|