mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Scaffold test before removing scopeCompanyables call from AssetsController
This commit is contained in:
parent
65e8e4e163
commit
af77fefc61
|
@ -3,14 +3,17 @@
|
||||||
namespace Tests\Feature\Api\Assets;
|
namespace Tests\Feature\Api\Assets;
|
||||||
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Testing\Fluent\AssertableJson;
|
use Illuminate\Testing\Fluent\AssertableJson;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
|
use Tests\Support\InteractsWithResponses;
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class AssetIndexTest extends TestCase
|
class AssetIndexTest extends TestCase
|
||||||
{
|
{
|
||||||
|
use InteractsWithResponses;
|
||||||
use InteractsWithSettings;
|
use InteractsWithSettings;
|
||||||
|
|
||||||
public function testAssetIndexReturnsExpectedAssets()
|
public function testAssetIndexReturnsExpectedAssets()
|
||||||
|
@ -32,4 +35,50 @@ class AssetIndexTest extends TestCase
|
||||||
])
|
])
|
||||||
->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc());
|
->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAssetIndexAdheresToCompanyScoping()
|
||||||
|
{
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$assetA = Asset::factory()->for($companyA)->create();
|
||||||
|
$assetB = Asset::factory()->for($companyB)->create();
|
||||||
|
|
||||||
|
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
||||||
|
$userInCompanyA = $companyA->users()->save(User::factory()->viewAssets()->make());
|
||||||
|
$userInCompanyB = $companyB->users()->save(User::factory()->viewAssets()->make());
|
||||||
|
|
||||||
|
$this->settings->disableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
Passport::actingAs($superUser);
|
||||||
|
$response = $this->getJson(route('api.assets.index'));
|
||||||
|
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
||||||
|
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
||||||
|
|
||||||
|
Passport::actingAs($userInCompanyA);
|
||||||
|
$response = $this->getJson(route('api.assets.index'));
|
||||||
|
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
||||||
|
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
||||||
|
|
||||||
|
Passport::actingAs($userInCompanyB);
|
||||||
|
$response = $this->getJson(route('api.assets.index'));
|
||||||
|
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
||||||
|
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
||||||
|
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
Passport::actingAs($superUser);
|
||||||
|
$response = $this->getJson(route('api.assets.index'));
|
||||||
|
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
||||||
|
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
||||||
|
|
||||||
|
Passport::actingAs($userInCompanyA);
|
||||||
|
$response = $this->getJson(route('api.assets.index'));
|
||||||
|
$this->assertResponseContainsInRows($response, $assetA, 'asset_tag');
|
||||||
|
$this->assertResponseDoesNotContainInRows($response, $assetB, 'asset_tag');
|
||||||
|
|
||||||
|
Passport::actingAs($userInCompanyB);
|
||||||
|
$response = $this->getJson(route('api.assets.index'));
|
||||||
|
$this->assertResponseDoesNotContainInRows($response, $assetA, 'asset_tag');
|
||||||
|
$this->assertResponseContainsInRows($response, $assetB, 'asset_tag');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue