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 Laravel\Passport\Passport;
|
2023-06-07 16:16:30 -07:00
|
|
|
use Tests\Support\InteractsWithResponses;
|
2023-06-07 16:09:45 -07:00
|
|
|
use Tests\Support\InteractsWithSettings;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class LicensesIndexTest extends TestCase
|
|
|
|
{
|
2023-06-07 16:16:30 -07:00
|
|
|
use InteractsWithResponses;
|
2023-06-07 16:09:45 -07:00
|
|
|
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();
|
|
|
|
|
|
|
|
Passport::actingAs($superUser);
|
|
|
|
$response = $this->getJson(route('api.licenses.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $licenseA);
|
|
|
|
$this->assertResponseContainsInRows($response, $licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyA);
|
|
|
|
$response = $this->getJson(route('api.licenses.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $licenseA);
|
|
|
|
$this->assertResponseContainsInRows($response, $licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyB);
|
|
|
|
$response = $this->getJson(route('api.licenses.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $licenseA);
|
|
|
|
$this->assertResponseContainsInRows($response, $licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
Passport::actingAs($superUser);
|
|
|
|
$response = $this->getJson(route('api.licenses.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $licenseA);
|
|
|
|
$this->assertResponseContainsInRows($response, $licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyA);
|
|
|
|
$response = $this->getJson(route('api.licenses.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseContainsInRows($response, $licenseA);
|
|
|
|
$this->assertResponseDoesNotContainInRows($response, $licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
|
|
|
|
Passport::actingAs($userInCompanyB);
|
|
|
|
$response = $this->getJson(route('api.licenses.index'));
|
2023-06-07 16:16:30 -07:00
|
|
|
$this->assertResponseDoesNotContainInRows($response, $licenseA);
|
|
|
|
$this->assertResponseContainsInRows($response, $licenseB);
|
2023-06-07 16:09:45 -07:00
|
|
|
}
|
|
|
|
}
|