mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Add tests for delete component endpoint
This commit is contained in:
parent
910f13c1f7
commit
6df8b0ac0e
64
tests/Feature/Components/Api/DeleteComponentsTest.php
Normal file
64
tests/Feature/Components/Api/DeleteComponentsTest.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Components\Api;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Component;
|
||||
use App\Models\User;
|
||||
use Tests\Concerns\TestsMultipleFullCompanySupport;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteComponentsTest extends TestCase implements TestsMultipleFullCompanySupport, TestsPermissionsRequirement
|
||||
{
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$component = Component::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->deleteJson(route('api.components.destroy', $component))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testCanDeleteComponents()
|
||||
{
|
||||
$component = Component::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->deleteComponents()->create())
|
||||
->deleteJson(route('api.components.destroy', $component))
|
||||
->assertStatusMessageIs('success');
|
||||
|
||||
$this->assertTrue($component->fresh()->trashed());
|
||||
}
|
||||
|
||||
public function testAdheresToMultipleFullCompanySupportScoping()
|
||||
{
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$componentA = Component::factory()->for($companyA)->create();
|
||||
$componentB = Component::factory()->for($companyB)->create();
|
||||
$componentC = Component::factory()->for($companyB)->create();
|
||||
|
||||
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
||||
$userInCompanyA = $companyA->users()->save(User::factory()->deleteComponents()->make());
|
||||
$userInCompanyB = $companyB->users()->save(User::factory()->deleteComponents()->make());
|
||||
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAsForApi($userInCompanyA)
|
||||
->deleteJson(route('api.components.destroy', $componentB))
|
||||
->assertStatusMessageIs('error');
|
||||
|
||||
$this->actingAsForApi($userInCompanyB)
|
||||
->deleteJson(route('api.components.destroy', $componentA))
|
||||
->assertStatusMessageIs('error');
|
||||
|
||||
$this->actingAsForApi($superUser)
|
||||
->deleteJson(route('api.components.destroy', $componentC))
|
||||
->assertStatusMessageIs('success');
|
||||
|
||||
$this->assertNull($componentA->fresh()->deleted_at, 'Component unexpectedly deleted');
|
||||
$this->assertNull($componentB->fresh()->deleted_at, 'Component unexpectedly deleted');
|
||||
$this->assertNotNull($componentC->fresh()->deleted_at, 'Component was not deleted');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue