2023-06-07 16:09:45 -07:00
|
|
|
<?php
|
|
|
|
|
2024-06-04 10:48:53 -07:00
|
|
|
namespace Tests\Feature\Licenses\Api;
|
2023-06-07 16:09:45 -07:00
|
|
|
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\License;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-06-03 16:54:59 -07:00
|
|
|
class LicenseIndexTest extends TestCase
|
2023-06-07 16:09:45 -07:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|