mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 14:27:33 -08:00
Remove scopeCompanyables call from ComponentsController
This commit is contained in:
parent
4fb86ad2fb
commit
48850f3597
|
@ -44,9 +44,7 @@ class ComponentsController extends Controller
|
|||
'notes',
|
||||
];
|
||||
|
||||
|
||||
$components = Company::scopeCompanyables(Component::select('components.*')
|
||||
->with('company', 'location', 'category', 'assets', 'supplier'));
|
||||
$components = Component::with('company', 'location', 'category', 'assets', 'supplier');
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$components = $components->TextSearch($request->input('search'));
|
||||
|
|
77
tests/Feature/Api/Components/ComponentIndexTest.php
Normal file
77
tests/Feature/Api/Components/ComponentIndexTest.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\Components;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Component;
|
||||
use App\Models\User;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Laravel\Passport\Passport;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ComponentIndexTest extends TestCase
|
||||
{
|
||||
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->sendRequest();
|
||||
$this->assertResponseContains($response, $componentA);
|
||||
$this->assertResponseContains($response, $componentB);
|
||||
|
||||
Passport::actingAs($userInCompanyA);
|
||||
$response = $this->sendRequest();
|
||||
$this->assertResponseContains($response, $componentA);
|
||||
$this->assertResponseContains($response, $componentB);
|
||||
|
||||
Passport::actingAs($userInCompanyB);
|
||||
$response = $this->sendRequest();
|
||||
$this->assertResponseContains($response, $componentA);
|
||||
$this->assertResponseContains($response, $componentB);
|
||||
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
Passport::actingAs($superUser);
|
||||
$response = $this->sendRequest();
|
||||
$this->assertResponseContains($response, $componentA);
|
||||
$this->assertResponseContains($response, $componentB);
|
||||
|
||||
Passport::actingAs($userInCompanyA);
|
||||
$response = $this->sendRequest();
|
||||
$this->assertResponseContains($response, $componentA);
|
||||
$this->assertResponseDoesNotContain($response, $componentB);
|
||||
|
||||
Passport::actingAs($userInCompanyB);
|
||||
$response = $this->sendRequest();
|
||||
$this->assertResponseDoesNotContain($response, $componentA);
|
||||
$this->assertResponseContains($response, $componentB);
|
||||
}
|
||||
|
||||
private function sendRequest(): TestResponse
|
||||
{
|
||||
return $this->getJson(route('api.components.index'));
|
||||
}
|
||||
|
||||
private function assertResponseContains(TestResponse $response, Component $component)
|
||||
{
|
||||
$this->assertTrue(collect($response['rows'])->pluck('name')->contains($component->name));
|
||||
}
|
||||
|
||||
private function assertResponseDoesNotContain(TestResponse $response, Component $component)
|
||||
{
|
||||
$this->assertFalse(collect($response['rows'])->pluck('name')->contains($component->name));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue