MOAR TESTS

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-06-01 04:01:09 +01:00
parent cff382605c
commit ea8d390596
2 changed files with 38 additions and 7 deletions

View file

@ -66,7 +66,7 @@ class DeleteUsersTest extends TestCase
->json(); ->json();
} }
public function testDisallowUserDeletionIfNotInSameCompanyIfNotSuperadmin() public function testDisallowUserDeletionIfNotInSameCompanyAndNotSuperadmin()
{ {
$this->settings->enableMultipleFullCompanySupport(); $this->settings->enableMultipleFullCompanySupport();
[$companyA, $companyB] = Company::factory()->count(2)->create(); [$companyA, $companyB] = Company::factory()->count(2)->create();
@ -94,6 +94,20 @@ class DeleteUsersTest extends TestCase
} }
public function testUsersCannotDeleteThemselves()
{
$user = User::factory()->deleteUsers()->create();
$this->actingAsForApi($user)
->deleteJson(route('api.users.destroy', $user))
->assertOk()
->assertStatus(200)
->assertStatusMessageIs('error')
->json();
}

View file

@ -13,27 +13,44 @@ class DeleteUsersTest extends TestCase
public function testDisallowUserDeletionIfStillManagingPeople() public function testDisallowUserDeletionIfStillManagingPeople()
{ {
$manager = User::factory()->create(['first_name' => 'Manager', 'last_name' => 'McManagerson']); $manager = User::factory()->create();
User::factory()->create(['first_name' => 'Lowly', 'last_name' => 'Worker', 'manager_id' => $manager->id]); User::factory()->count(3)->create(['manager_id' => $manager->id]);
$this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable()); $this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable());
$this->actingAs(User::factory()->deleteUsers()->create())
->delete(route('users.destroy', $manager->id))
->assertStatus(302)
->assertRedirect(route('users.index'));
} }
public function testDisallowUserDeletionIfStillManagingLocations() public function testDisallowUserDeletionIfStillManagingLocations()
{ {
$manager = User::factory()->create(['first_name' => 'Manager', 'last_name' => 'McManagerson']); $manager = User::factory()->create();
Location::factory()->create(['manager_id' => $manager->id]); Location::factory()->count(3)->create(['manager_id' => $manager->id]);
$this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable()); $this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable());
$this->actingAs(User::factory()->deleteUsers()->create())
->delete(route('users.destroy', $manager->id))
->assertStatus(302)
->assertRedirect(route('users.index'));
} }
public function testAllowUserDeletionIfNotManagingLocations() public function testAllowUserDeletionIfNotManagingLocations()
{ {
$manager = User::factory()->create(['first_name' => 'Manager', 'last_name' => 'McManagerson']); $manager = User::factory()->create();
$this->actingAs(User::factory()->deleteUsers()->create())->assertTrue($manager->isDeletable()); $this->actingAs(User::factory()->deleteUsers()->create())->assertTrue($manager->isDeletable());
$this->actingAs(User::factory()->deleteUsers()->create())
->delete(route('users.destroy', $manager->id))
->assertStatus(302)
->assertRedirect(route('users.index'));
} }
public function testDisallowUserDeletionIfNoDeletePermissions() public function testDisallowUserDeletionIfNoDeletePermissions()
{ {
$manager = User::factory()->create(['first_name' => 'Manager', 'last_name' => 'McManagerson']); $manager = User::factory()->create();
Location::factory()->create(['manager_id' => $manager->id]); Location::factory()->create(['manager_id' => $manager->id]);
$this->actingAs(User::factory()->editUsers()->create())->assertFalse($manager->isDeletable()); $this->actingAs(User::factory()->editUsers()->create())->assertFalse($manager->isDeletable());
} }