From 386b2839e860e3e5de22154a02b804e3faf145c7 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 7 May 2024 18:59:24 +0100 Subject: [PATCH] Added tests Signed-off-by: snipe --- tests/Feature/Api/Users/UsersDeleteTest.php | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/Feature/Api/Users/UsersDeleteTest.php diff --git a/tests/Feature/Api/Users/UsersDeleteTest.php b/tests/Feature/Api/Users/UsersDeleteTest.php new file mode 100644 index 0000000000..cbdba83278 --- /dev/null +++ b/tests/Feature/Api/Users/UsersDeleteTest.php @@ -0,0 +1,42 @@ +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()); + } + + +}