2023-06-07 16:09:45 -07:00
|
|
|
<?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();
|
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($superUser)
|
|
|
|
->getJson(route('api.licenses.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($licenseA)
|
|
|
|
->assertResponseContainsInRows($licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyA)
|
|
|
|
->getJson(route('api.licenses.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($licenseA)
|
|
|
|
->assertResponseContainsInRows($licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyB)
|
|
|
|
->getJson(route('api.licenses.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($licenseA)
|
|
|
|
->assertResponseContainsInRows($licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($superUser)
|
|
|
|
->getJson(route('api.licenses.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($licenseA)
|
|
|
|
->assertResponseContainsInRows($licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyA)
|
|
|
|
->getJson(route('api.licenses.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseContainsInRows($licenseA)
|
|
|
|
->assertResponseDoesNotContainInRows($licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
|
2023-06-22 17:37:30 -07:00
|
|
|
$this->actingAsForApi($userInCompanyB)
|
|
|
|
->getJson(route('api.licenses.index'))
|
2023-06-22 14:41:56 -07:00
|
|
|
->assertResponseDoesNotContainInRows($licenseA)
|
|
|
|
->assertResponseContainsInRows($licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
}
|
|
|
|
}
|