mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Implement interfaces on existing test classes
This commit is contained in:
parent
9a13fcab23
commit
a629df07bf
|
@ -5,10 +5,22 @@ namespace Tests\Feature\Locations\Api;
|
|||
use App\Models\Asset;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteLocationsTest extends TestCase
|
||||
class DeleteLocationsTest extends TestCase implements TestsPermissionsRequirement
|
||||
{
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$location = Location::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->deleteJson(route('api.locations.destroy', $location))
|
||||
->assertForbidden();
|
||||
|
||||
$this->assertNotSoftDeleted($location);
|
||||
}
|
||||
|
||||
public function testErrorReturnedViaApiIfLocationDoesNotExist()
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
|
|
|
@ -6,10 +6,23 @@ use App\Models\Company;
|
|||
use App\Models\LicenseSeat;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Tests\Concerns\TestsMultipleFullCompanySupport;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteUsersTest extends TestCase
|
||||
class DeleteUsersTest extends TestCase implements TestsMultipleFullCompanySupport, TestsPermissionsRequirement
|
||||
{
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->deleteJson(route('api.users.destroy', $user))
|
||||
->assertForbidden();
|
||||
|
||||
$this->assertNotSoftDeleted($user);
|
||||
}
|
||||
|
||||
public function testErrorReturnedViaApiIfUserDoesNotExist()
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->deleteUsers()->create())
|
||||
|
@ -75,25 +88,19 @@ class DeleteUsersTest extends TestCase
|
|||
->json();
|
||||
}
|
||||
|
||||
public function testDeniedPermissionsForDeletingUserViaApi()
|
||||
public function testUsersCannotDeleteThemselves()
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->deleteJson(route('api.users.destroy', User::factory()->create()))
|
||||
->assertStatus(403)
|
||||
->json();
|
||||
}
|
||||
|
||||
public function testSuccessPermissionsForDeletingUserViaApi()
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->deleteUsers()->create())
|
||||
->deleteJson(route('api.users.destroy', User::factory()->create()))
|
||||
$user = User::factory()->deleteUsers()->create();
|
||||
$this->actingAsForApi($user)
|
||||
->deleteJson(route('api.users.destroy', $user))
|
||||
->assertOk()
|
||||
->assertStatus(200)
|
||||
->assertStatusMessageIs('success')
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
|
||||
}
|
||||
|
||||
public function testPermissionsForDeletingIfNotInSameCompanyAndNotSuperadmin()
|
||||
public function testAdheresToMultipleFullCompanySupportScoping()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
|
@ -132,18 +139,17 @@ class DeleteUsersTest extends TestCase
|
|||
|
||||
$userFromA->refresh();
|
||||
$this->assertNotNull($userFromA->deleted_at);
|
||||
|
||||
}
|
||||
|
||||
public function testUsersCannotDeleteThemselves()
|
||||
public function testCanDeleteUser()
|
||||
{
|
||||
$user = User::factory()->deleteUsers()->create();
|
||||
$this->actingAsForApi($user)
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->deleteUsers()->create())
|
||||
->deleteJson(route('api.users.destroy', $user))
|
||||
->assertOk()
|
||||
->assertStatus(200)
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
->assertStatusMessageIs('success');
|
||||
|
||||
$this->assertSoftDeleted($user);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue