2024-09-12 15:52:07 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Components\Api;
|
|
|
|
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\Component;
|
|
|
|
use App\Models\User;
|
2024-09-16 16:55:20 -07:00
|
|
|
use Tests\Concerns\TestsFullMultipleCompaniesSupport;
|
2024-09-12 15:52:07 -07:00
|
|
|
use Tests\Concerns\TestsPermissionsRequirement;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-09-16 16:55:20 -07:00
|
|
|
class DeleteComponentsTest extends TestCase implements TestsFullMultipleCompaniesSupport, TestsPermissionsRequirement
|
2024-09-12 15:52:07 -07:00
|
|
|
{
|
|
|
|
public function testRequiresPermission()
|
|
|
|
{
|
|
|
|
$component = Component::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->deleteJson(route('api.components.destroy', $component))
|
|
|
|
->assertForbidden();
|
2024-09-16 14:32:38 -07:00
|
|
|
|
|
|
|
$this->assertNotSoftDeleted($component);
|
2024-09-12 15:52:07 -07:00
|
|
|
}
|
|
|
|
|
2024-09-16 16:55:20 -07:00
|
|
|
public function testAdheresToFullMultipleCompaniesSupportScoping()
|
2024-09-12 15:52:07 -07:00
|
|
|
{
|
|
|
|
[$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');
|
|
|
|
|
2024-09-16 14:20:24 -07:00
|
|
|
$this->assertNotSoftDeleted($componentA);
|
|
|
|
$this->assertNotSoftDeleted($componentB);
|
|
|
|
$this->assertSoftDeleted($componentC);
|
2024-09-12 15:52:07 -07:00
|
|
|
}
|
2024-09-16 14:25:11 -07:00
|
|
|
|
|
|
|
public function testCanDeleteComponents()
|
|
|
|
{
|
|
|
|
$component = Component::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->deleteComponents()->create())
|
|
|
|
->deleteJson(route('api.components.destroy', $component))
|
|
|
|
->assertStatusMessageIs('success');
|
|
|
|
|
|
|
|
$this->assertSoftDeleted($component);
|
|
|
|
}
|
2024-09-12 15:52:07 -07:00
|
|
|
}
|