2023-06-06 18:02:18 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Api\Components;
|
|
|
|
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\Component;
|
|
|
|
use App\Models\User;
|
|
|
|
use Laravel\Passport\Passport;
|
2023-06-07 16:16:30 -07:00
|
|
|
use Tests\Support\InteractsWithResponses;
|
2023-06-06 18:02:18 -07:00
|
|
|
use Tests\Support\InteractsWithSettings;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class ComponentIndexTest extends TestCase
|
|
|
|
{
|
2023-06-07 16:16:30 -07:00
|
|
|
use InteractsWithResponses;
|
2023-06-06 18:02:18 -07:00
|
|
|
use InteractsWithSettings;
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
Passport::actingAs($superUser);
|
2023-06-07 16:18:02 -07:00
|
|
|
$response = $this->getJson(route('api.components.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $componentA);
|
|
|
|
$this->assertResponseContainsInRows($response, $componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyA);
|
2023-06-07 16:18:02 -07:00
|
|
|
$response = $this->getJson(route('api.components.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $componentA);
|
|
|
|
$this->assertResponseContainsInRows($response, $componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyB);
|
2023-06-07 16:18:02 -07:00
|
|
|
$response = $this->getJson(route('api.components.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $componentA);
|
|
|
|
$this->assertResponseContainsInRows($response, $componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
Passport::actingAs($superUser);
|
2023-06-07 16:18:02 -07:00
|
|
|
$response = $this->getJson(route('api.components.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $componentA);
|
|
|
|
$this->assertResponseContainsInRows($response, $componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyA);
|
2023-06-07 16:18:02 -07:00
|
|
|
$response = $this->getJson(route('api.components.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $componentA);
|
|
|
|
$this->assertResponseDoesNotContainInRows($response, $componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyB);
|
2023-06-07 16:18:02 -07:00
|
|
|
$response = $this->getJson(route('api.components.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseDoesNotContainInRows($response, $componentA);
|
|
|
|
$this->assertResponseContainsInRows($response, $componentB);
|
2023-06-06 18:02:18 -07:00
|
|
|
}
|
|
|
|
}
|