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\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())

View file

@ -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);
}
}