mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-11 08:04:09 -08:00
61 lines
2.1 KiB
PHP
61 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api\Licenses;
|
|
|
|
use App\Models\Company;
|
|
use App\Models\License;
|
|
use App\Models\User;
|
|
use Tests\Support\InteractsWithSettings;
|
|
use Tests\TestCase;
|
|
|
|
class LicensesIndexTest extends TestCase
|
|
{
|
|
use InteractsWithSettings;
|
|
|
|
public function testLicensesIndexAdheresToCompanyScoping()
|
|
{
|
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
|
|
|
$licenseA = License::factory()->for($companyA)->create();
|
|
$licenseB = License::factory()->for($companyB)->create();
|
|
|
|
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
|
$userInCompanyA = $companyA->users()->save(User::factory()->viewLicenses()->make());
|
|
$userInCompanyB = $companyB->users()->save(User::factory()->viewLicenses()->make());
|
|
|
|
$this->settings->disableMultipleFullCompanySupport();
|
|
|
|
$this->actingAsForApi($superUser)
|
|
->getJson(route('api.licenses.index'))
|
|
->assertResponseContainsInRows($licenseA)
|
|
->assertResponseContainsInRows($licenseB);
|
|
|
|
$this->actingAsForApi($userInCompanyA)
|
|
->getJson(route('api.licenses.index'))
|
|
->assertResponseContainsInRows($licenseA)
|
|
->assertResponseContainsInRows($licenseB);
|
|
|
|
$this->actingAsForApi($userInCompanyB)
|
|
->getJson(route('api.licenses.index'))
|
|
->assertResponseContainsInRows($licenseA)
|
|
->assertResponseContainsInRows($licenseB);
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
$this->actingAsForApi($superUser)
|
|
->getJson(route('api.licenses.index'))
|
|
->assertResponseContainsInRows($licenseA)
|
|
->assertResponseContainsInRows($licenseB);
|
|
|
|
$this->actingAsForApi($userInCompanyA)
|
|
->getJson(route('api.licenses.index'))
|
|
->assertResponseContainsInRows($licenseA)
|
|
->assertResponseDoesNotContainInRows($licenseB);
|
|
|
|
$this->actingAsForApi($userInCompanyB)
|
|
->getJson(route('api.licenses.index'))
|
|
->assertResponseDoesNotContainInRows($licenseA)
|
|
->assertResponseContainsInRows($licenseB);
|
|
}
|
|
}
|