Skip to content

Commit

Permalink
Implement interfaces on existing test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusmoore committed Sep 16, 2024
1 parent 9a13fca commit a629df0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
14 changes: 13 additions & 1 deletion tests/Feature/Locations/Api/DeleteLocationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@
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())
Expand Down
48 changes: 27 additions & 21 deletions tests/Feature/Users/Api/DeleteUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@
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())
Expand Down Expand Up @@ -75,25 +88,19 @@ public function testDisallowUserDeletionViaApiIfStillHasLicenses()
->json();
}

public function testDeniedPermissionsForDeletingUserViaApi()
{
$this->actingAsForApi(User::factory()->create())
->deleteJson(route('api.users.destroy', User::factory()->create()))
->assertStatus(403)
->json();
}

public function testSuccessPermissionsForDeletingUserViaApi()
public function testUsersCannotDeleteThemselves()
{
$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();

Expand Down Expand Up @@ -132,18 +139,17 @@ public function testPermissionsForDeletingIfNotInSameCompanyAndNotSuperadmin()

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

0 comments on commit a629df0

Please sign in to comment.