Implement interfaces on existing test classes

This commit is contained in:
Marcus Moore 2024-09-16 14:49:08 -07:00
parent 9a13fcab23
commit a629df07bf
No known key found for this signature in database
2 changed files with 40 additions and 22 deletions

View file

@ -5,10 +5,22 @@ namespace Tests\Feature\Locations\Api;
use App\Models\Asset; use App\Models\Asset;
use App\Models\Location; use App\Models\Location;
use App\Models\User; use App\Models\User;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase; 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() public function testErrorReturnedViaApiIfLocationDoesNotExist()
{ {
$this->actingAsForApi(User::factory()->superuser()->create()) $this->actingAsForApi(User::factory()->superuser()->create())

View file

@ -6,10 +6,23 @@ use App\Models\Company;
use App\Models\LicenseSeat; use App\Models\LicenseSeat;
use App\Models\Location; use App\Models\Location;
use App\Models\User; use App\Models\User;
use Tests\Concerns\TestsMultipleFullCompanySupport;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase; 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() public function testErrorReturnedViaApiIfUserDoesNotExist()
{ {
$this->actingAsForApi(User::factory()->deleteUsers()->create()) $this->actingAsForApi(User::factory()->deleteUsers()->create())
@ -75,25 +88,19 @@ class DeleteUsersTest extends TestCase
->json(); ->json();
} }
public function testDeniedPermissionsForDeletingUserViaApi() public function testUsersCannotDeleteThemselves()
{ {
$this->actingAsForApi(User::factory()->create()) $user = User::factory()->deleteUsers()->create();
->deleteJson(route('api.users.destroy', User::factory()->create())) $this->actingAsForApi($user)
->assertStatus(403) ->deleteJson(route('api.users.destroy', $user))
->json();
}
public function testSuccessPermissionsForDeletingUserViaApi()
{
$this->actingAsForApi(User::factory()->deleteUsers()->create())
->deleteJson(route('api.users.destroy', User::factory()->create()))
->assertOk() ->assertOk()
->assertStatus(200) ->assertStatus(200)
->assertStatusMessageIs('success') ->assertStatusMessageIs('error')
->json(); ->json();
} }
public function testPermissionsForDeletingIfNotInSameCompanyAndNotSuperadmin() public function testAdheresToMultipleFullCompanySupportScoping()
{ {
$this->settings->enableMultipleFullCompanySupport(); $this->settings->enableMultipleFullCompanySupport();
@ -132,18 +139,17 @@ class DeleteUsersTest extends TestCase
$userFromA->refresh(); $userFromA->refresh();
$this->assertNotNull($userFromA->deleted_at); $this->assertNotNull($userFromA->deleted_at);
} }
public function testUsersCannotDeleteThemselves() public function testCanDeleteUser()
{ {
$user = User::factory()->deleteUsers()->create(); $user = User::factory()->create();
$this->actingAsForApi($user)
$this->actingAsForApi(User::factory()->deleteUsers()->create())
->deleteJson(route('api.users.destroy', $user)) ->deleteJson(route('api.users.destroy', $user))
->assertOk() ->assertOk()
->assertStatus(200) ->assertStatusMessageIs('success');
->assertStatusMessageIs('error')
->json();
$this->assertSoftDeleted($user);
} }
} }