mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Add tests for delete accessory endpoint
This commit is contained in:
parent
8774da3921
commit
c7ae9d9dfa
8
tests/Concerns/TestsMultipleFullCompanySupport.php
Normal file
8
tests/Concerns/TestsMultipleFullCompanySupport.php
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Concerns;
|
||||||
|
|
||||||
|
interface TestsMultipleFullCompanySupport
|
||||||
|
{
|
||||||
|
public function testAdheresToMultipleFullCompanySupportScoping();
|
||||||
|
}
|
|
@ -3,10 +3,12 @@
|
||||||
namespace Tests\Feature\Accessories\Api;
|
namespace Tests\Feature\Accessories\Api;
|
||||||
|
|
||||||
use App\Models\Accessory;
|
use App\Models\Accessory;
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Tests\Concerns\TestsMultipleFullCompanySupport;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class DeleteAccessoryTest extends TestCase
|
class DeleteAccessoryTest extends TestCase implements TestsMultipleFullCompanySupport
|
||||||
{
|
{
|
||||||
public function testPermissionRequiredToDeleteAccessory()
|
public function testPermissionRequiredToDeleteAccessory()
|
||||||
{
|
{
|
||||||
|
@ -16,4 +18,57 @@ class DeleteAccessoryTest extends TestCase
|
||||||
->deleteJson(route('api.accessories.destroy', $accessory))
|
->deleteJson(route('api.accessories.destroy', $accessory))
|
||||||
->assertForbidden();
|
->assertForbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanDeleteAccessory()
|
||||||
|
{
|
||||||
|
$accessory = Accessory::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->deleteAccessories()->create())
|
||||||
|
->deleteJson(route('api.accessories.destroy', $accessory))
|
||||||
|
->assertStatusMessageIs('success');
|
||||||
|
|
||||||
|
$this->assertTrue($accessory->fresh()->trashed());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCannotDeleteAccessoryThatHasCheckouts()
|
||||||
|
{
|
||||||
|
$accessory = Accessory::factory()->checkedOutToUser()->create();
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->deleteAccessories()->create())
|
||||||
|
->deleteJson(route('api.accessories.destroy', $accessory))
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
|
||||||
|
$this->assertFalse($accessory->fresh()->trashed());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAdheresToMultipleFullCompanySupportScoping()
|
||||||
|
{
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$accessoryA = Accessory::factory()->for($companyA)->create();
|
||||||
|
$accessoryB = Accessory::factory()->for($companyB)->create();
|
||||||
|
$accessoryC = Accessory::factory()->for($companyB)->create();
|
||||||
|
|
||||||
|
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
||||||
|
$userInCompanyA = $companyA->users()->save(User::factory()->deleteAccessories()->make());
|
||||||
|
$userInCompanyB = $companyB->users()->save(User::factory()->deleteAccessories()->make());
|
||||||
|
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
$this->actingAsForApi($userInCompanyA)
|
||||||
|
->deleteJson(route('api.accessories.destroy', $accessoryB))
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
|
||||||
|
$this->actingAsForApi($userInCompanyB)
|
||||||
|
->deleteJson(route('api.accessories.destroy', $accessoryA))
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
|
||||||
|
$this->actingAsForApi($superUser)
|
||||||
|
->deleteJson(route('api.accessories.destroy', $accessoryC))
|
||||||
|
->assertStatusMessageIs('success');
|
||||||
|
|
||||||
|
$this->assertNull($accessoryA->fresh()->deleted_at, 'Accessory unexpectedly deleted');
|
||||||
|
$this->assertNull($accessoryB->fresh()->deleted_at, 'Accessory unexpectedly deleted');
|
||||||
|
$this->assertNotNull($accessoryC->fresh()->deleted_at, 'Accessory was not deleted');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue