Added tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-06-22 17:45:42 +01:00
parent c6a0212384
commit 65e8765bdd
2 changed files with 46 additions and 0 deletions

View file

@ -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()
{

View file

@ -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()
{