Skip to content

A free open source IT asset/license management system

MOAR TESTS

snipeea8d39059697
diff --git a/tests/Feature/Api/Users/DeleteUsersTest.php b/tests/Feature/Api/Users/DeleteUsersTest.php
index 3b68cbb4dc..e926311dca 100644
--- a/tests/Feature/Api/Users/DeleteUsersTest.php
+++ b/tests/Feature/Api/Users/DeleteUsersTest.php
@@ -66,7 +66,7 @@ class DeleteUsersTest extends TestCase
->json();
}
- public function testDisallowUserDeletionIfNotInSameCompanyIfNotSuperadmin()
+ public function testDisallowUserDeletionIfNotInSameCompanyAndNotSuperadmin()
{
$this->settings->enableMultipleFullCompanySupport();
[$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();
+
+ }
+
+
+
diff --git a/tests/Feature/Users/DeleteUsersTest.php b/tests/Feature/Users/DeleteUsersTest.php
index 9903081e20..3d2da4bf4e 100644
--- a/tests/Feature/Users/DeleteUsersTest.php
+++ b/tests/Feature/Users/DeleteUsersTest.php
@@ -13,27 +13,44 @@ class DeleteUsersTest extends TestCase
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]);
+ $manager = User::factory()->create();
+ User::factory()->count(3)->create(['manager_id' => $manager->id]);
+
$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()
{
- $manager = User::factory()->create(['first_name' => 'Manager', 'last_name' => 'McManagerson']);
- Location::factory()->create(['manager_id' => $manager->id]);
+ $manager = User::factory()->create();
+ Location::factory()->count(3)->create(['manager_id' => $manager->id]);
+
$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()
{
- $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())
+ ->delete(route('users.destroy', $manager->id))
+ ->assertStatus(302)
+ ->assertRedirect(route('users.index'));
}
public function testDisallowUserDeletionIfNoDeletePermissions()
{
- $manager = User::factory()->create(['first_name' => 'Manager', 'last_name' => 'McManagerson']);
+ $manager = User::factory()->create();
Location::factory()->create(['manager_id' => $manager->id]);
$this->actingAs(User::factory()->editUsers()->create())->assertFalse($manager->isDeletable());
}