Tightened up tests with better checks

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

View file

@ -370,10 +370,10 @@ class UsersController extends Controller
->with('error', trans_choice('admin/users/message.error.delete_has_locations_var', $user->managedLocations()->count(), ['count'=> $user->managedLocations()->count()]));
}
// if (($user->managesUsers()) && ($user->managesUsers()->count() > 0)) {
// return redirect()->route('users.index')
// ->with('error', trans_choice('admin/users/message.error.delete_has_users_var', $user->managesUsers()->count(), ['count'=> $user->managesUsers()->count()]));
// }
if (($user->managesUsers()) && ($user->managesUsers()->count() > 0)) {
return redirect()->route('users.index')
->with('error', trans_choice('admin/users/message.error.delete_has_users_var', $user->managesUsers()->count(), ['count'=> $user->managesUsers()->count()]));
}
// Delete the user
$user->delete();

View file

@ -18,10 +18,12 @@ class DeleteUsersTest extends TestCase
$this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable());
$this->actingAs(User::factory()->deleteUsers()->create())
$response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create())
->delete(route('users.destroy', $manager->id))
->assertStatus(302)
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Error');
}
public function testDisallowUserDeletionIfStillManagingLocations()
@ -31,10 +33,12 @@ class DeleteUsersTest extends TestCase
$this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable());
$this->actingAs(User::factory()->deleteUsers()->create())
$response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create())
->delete(route('users.destroy', $manager->id))
->assertStatus(302)
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Error');
}
public function testAllowUserDeletionIfNotManagingLocations()
@ -42,10 +46,13 @@ class DeleteUsersTest extends TestCase
$manager = User::factory()->create();
$this->actingAs(User::factory()->deleteUsers()->create())->assertTrue($manager->isDeletable());
$this->actingAs(User::factory()->deleteUsers()->create())
$response = $this->actingAs(User::factory()->deleteUsers()->viewUsers()->create())
->delete(route('users.destroy', $manager->id))
->assertStatus(302)
->assertRedirect(route('users.index'));
$this->followRedirects($response)->assertSee('Success');
}
public function testDisallowUserDeletionIfNoDeletePermissions()