2023-06-06 18:02:18 -07:00
|
|
|
<?php
|
|
|
|
|
2024-06-04 10:48:53 -07:00
|
|
|
namespace Tests\Feature\Components\Api;
|
2023-06-06 18:02:18 -07:00
|
|
|
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\Component;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class ComponentIndexTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testComponentIndexAdheresToCompanyScoping()
|
|
|
|
{
|
|
|
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
|
|
|
|
|
|
|
$componentA = Component::factory()->for($companyA)->create();
|
|
|
|
$componentB = Component::factory()->for($companyB)->create();
|
|
|
|
|
|
|
|
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
|
|
|
$userInCompanyA = $companyA->users()->save(User::factory()->viewComponents()->make());
|
|
|
|
$userInCompanyB = $companyB->users()->save(User::factory()->viewComponents()->make());
|
|
|
|
|
|
|
|
$this->settings->disableMultipleFullCompanySupport();
|
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($superUser)
|
|
|
|
->getJson(route('api.components.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($componentA)
|
|
|
|
->assertResponseContainsInRows($componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyA)
|
|
|
|
->getJson(route('api.components.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($componentA)
|
|
|
|
->assertResponseContainsInRows($componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyB)
|
|
|
|
->getJson(route('api.components.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($componentA)
|
|
|
|
->assertResponseContainsInRows($componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($superUser)
|
|
|
|
->getJson(route('api.components.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($componentA)
|
|
|
|
->assertResponseContainsInRows($componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyA)
|
|
|
|
->getJson(route('api.components.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($componentA)
|
|
|
|
->assertResponseDoesNotContainInRows($componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyB)
|
|
|
|
->getJson(route('api.components.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseDoesNotContainInRows($componentA)
|
|
|
|
->assertResponseContainsInRows($componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
}
|
|
|
|
}
|