mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 21:54:14 -08:00
Remove scopeCompanyables call from ConsumablesController
This commit is contained in:
parent
48850f3597
commit
a18f5e7fc0
|
@ -45,11 +45,7 @@ class ConsumablesController extends Controller
|
|||
'notes',
|
||||
];
|
||||
|
||||
|
||||
$consumables = Company::scopeCompanyables(
|
||||
Consumable::select('consumables.*')
|
||||
->with('company', 'location', 'category', 'users', 'manufacturer')
|
||||
);
|
||||
$consumables = Consumable::with('company', 'location', 'category', 'users', 'manufacturer');
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$consumables = $consumables->TextSearch(e($request->input('search')));
|
||||
|
|
72
tests/Feature/Api/Consumables/ConsumablesIndexTest.php
Normal file
72
tests/Feature/Api/Consumables/ConsumablesIndexTest.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\Consumables;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\User;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Laravel\Passport\Passport;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ConsumablesIndexTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testConsumableIndexAdheresToCompanyScoping()
|
||||
{
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$consumableA = Consumable::factory()->for($companyA)->create();
|
||||
$consumableB = Consumable::factory()->for($companyB)->create();
|
||||
|
||||
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
||||
$userInCompanyA = $companyA->users()->save(User::factory()->viewConsumables()->make());
|
||||
$userInCompanyB = $companyB->users()->save(User::factory()->viewConsumables()->make());
|
||||
|
||||
$this->settings->disableMultipleFullCompanySupport();
|
||||
|
||||
Passport::actingAs($superUser);
|
||||
$response = $this->getJson(route('api.consumables.index'));
|
||||
$this->assertResponseContains($response, $consumableA);
|
||||
$this->assertResponseContains($response, $consumableB);
|
||||
|
||||
Passport::actingAs($userInCompanyA);
|
||||
$response = $this->getJson(route('api.consumables.index'));
|
||||
$this->assertResponseContains($response, $consumableA);
|
||||
$this->assertResponseContains($response, $consumableB);
|
||||
|
||||
Passport::actingAs($userInCompanyB);
|
||||
$response = $this->getJson(route('api.consumables.index'));
|
||||
$this->assertResponseContains($response, $consumableA);
|
||||
$this->assertResponseContains($response, $consumableB);
|
||||
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
Passport::actingAs($superUser);
|
||||
$response = $this->getJson(route('api.consumables.index'));
|
||||
$this->assertResponseContains($response, $consumableA);
|
||||
$this->assertResponseContains($response, $consumableB);
|
||||
|
||||
Passport::actingAs($userInCompanyA);
|
||||
$response = $this->getJson(route('api.consumables.index'));
|
||||
$this->assertResponseContains($response, $consumableA);
|
||||
$this->assertResponseDoesNotContain($response, $consumableB);
|
||||
|
||||
Passport::actingAs($userInCompanyB);
|
||||
$response = $this->getJson(route('api.consumables.index'));
|
||||
$this->assertResponseDoesNotContain($response, $consumableA);
|
||||
$this->assertResponseContains($response, $consumableB);
|
||||
}
|
||||
|
||||
private function assertResponseContains(TestResponse $response, Consumable $consumable)
|
||||
{
|
||||
$this->assertTrue(collect($response['rows'])->pluck('name')->contains($consumable->name));
|
||||
}
|
||||
|
||||
private function assertResponseDoesNotContain(TestResponse $response, Consumable $consumable)
|
||||
{
|
||||
$this->assertFalse(collect($response['rows'])->pluck('name')->contains($consumable->name));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue