From 65e8765bddb2a1b19ec9d39073274c50671cc16d Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 22 Jun 2024 17:45:42 +0100 Subject: [PATCH] Added tests Signed-off-by: snipe --- tests/Feature/Users/Api/DeleteUserTest.php | 22 ++++++++++++++++++++ tests/Feature/Users/Ui/DeleteUserTest.php | 24 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/tests/Feature/Users/Api/DeleteUserTest.php b/tests/Feature/Users/Api/DeleteUserTest.php index f3f8e80f34..b127543c52 100644 --- a/tests/Feature/Users/Api/DeleteUserTest.php +++ b/tests/Feature/Users/Api/DeleteUserTest.php @@ -11,6 +11,28 @@ use Tests\TestCase; class DeleteUserTest extends TestCase { + public function testUserCanDeleteAnotherUserViaApi() + { + + $this->actingAsForApi(User::factory()->deleteUsers()->create()) + ->deleteJson(route('api.users.destroy', User::factory()->create())) + ->assertOk() + ->assertStatus(200) + ->assertStatusMessageIs('success') + ->json(); + } + + + public function testErrorReturnedViaApiIfUserDoesNotExist() + { + $this->actingAsForApi(User::factory()->deleteUsers()->create(['company_id'=> null])) + ->deleteJson(route('api.users.destroy', 'invalid-id')) + ->assertOk() + ->assertStatus(200) + ->assertStatusMessageIs('error') + ->json(); + } + public function testDisallowUserDeletionViaApiIfStillManagingPeople() { diff --git a/tests/Feature/Users/Ui/DeleteUserTest.php b/tests/Feature/Users/Ui/DeleteUserTest.php index 61ee233795..5679bb3ac1 100644 --- a/tests/Feature/Users/Ui/DeleteUserTest.php +++ b/tests/Feature/Users/Ui/DeleteUserTest.php @@ -14,6 +14,30 @@ use App\Models\Asset; class DeleteUserTest extends TestCase { + public function testUserCanDeleteAnotherUser() + { + $user = User::factory()->deleteUsers()->viewUsers()->create(); + $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create())->assertTrue($user->isDeletable()); + + $response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create()) + ->delete(route('users.destroy', ['user' => $user->id])) + ->assertStatus(302) + ->assertRedirect(route('users.index')); + + $this->followRedirects($response)->assertSee(trans('general.notification_success')); + } + + + public function testErrorReturnedIfUserDoesNotExist() + { + $response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create()) + ->delete(route('users.destroy', ['user' => '40596803548609346'])) + ->assertStatus(302) + ->assertRedirect(route('users.index')); + //$this->followRedirects($response)->assertSee(trans('general.error')); + } + + public function testPermissionsToDeleteUser() {