mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-11 08:04:09 -08:00
64 lines
2.5 KiB
PHP
64 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api\Components;
|
|
|
|
use App\Models\Company;
|
|
use App\Models\Component;
|
|
use App\Models\User;
|
|
use Laravel\Passport\Passport;
|
|
use Tests\Support\InteractsWithResponses;
|
|
use Tests\Support\InteractsWithSettings;
|
|
use Tests\TestCase;
|
|
|
|
class ComponentIndexTest extends TestCase
|
|
{
|
|
use InteractsWithResponses;
|
|
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);
|
|
$response = $this->getJson(route('api.components.index'));
|
|
$this->assertResponseContainsInRows($response, $componentA);
|
|
$this->assertResponseContainsInRows($response, $componentB);
|
|
|
|
Passport::actingAs($userInCompanyA);
|
|
$response = $this->getJson(route('api.components.index'));
|
|
$this->assertResponseContainsInRows($response, $componentA);
|
|
$this->assertResponseContainsInRows($response, $componentB);
|
|
|
|
Passport::actingAs($userInCompanyB);
|
|
$response = $this->getJson(route('api.components.index'));
|
|
$this->assertResponseContainsInRows($response, $componentA);
|
|
$this->assertResponseContainsInRows($response, $componentB);
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
Passport::actingAs($superUser);
|
|
$response = $this->getJson(route('api.components.index'));
|
|
$this->assertResponseContainsInRows($response, $componentA);
|
|
$this->assertResponseContainsInRows($response, $componentB);
|
|
|
|
Passport::actingAs($userInCompanyA);
|
|
$response = $this->getJson(route('api.components.index'));
|
|
$this->assertResponseContainsInRows($response, $componentA);
|
|
$this->assertResponseDoesNotContainInRows($response, $componentB);
|
|
|
|
Passport::actingAs($userInCompanyB);
|
|
$response = $this->getJson(route('api.components.index'));
|
|
$this->assertResponseDoesNotContainInRows($response, $componentA);
|
|
$this->assertResponseContainsInRows($response, $componentB);
|
|
}
|
|
}
|