mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 06:04:08 -08:00
Scaffold test before removing scopeCompanyables call from UsersController
This commit is contained in:
parent
0f6051bbe5
commit
6f5252449e
64
tests/Feature/Api/Users/UsersIndexTest.php
Normal file
64
tests/Feature/Api/Users/UsersIndexTest.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\Users;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Laravel\Passport\Passport;
|
||||
use Tests\Support\InteractsWithResponses;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UsersIndexTest extends TestCase
|
||||
{
|
||||
use InteractsWithResponses;
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testUsersIndexAdheresToCompanyScoping()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$userA = User::factory()->for($companyA)->create();
|
||||
$userB = User::factory()->for($companyB)->create();
|
||||
|
||||
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
||||
$userInCompanyA = $companyA->users()->save(User::factory()->viewUsers()->make());
|
||||
$userInCompanyB = $companyB->users()->save(User::factory()->viewUsers()->make());
|
||||
|
||||
$this->settings->disableMultipleFullCompanySupport();
|
||||
|
||||
Passport::actingAs($superUser);
|
||||
$response = $this->getJson(route('api.users.index'));
|
||||
$this->assertResponseContainsInRows($response, $userA, 'first_name');
|
||||
$this->assertResponseContainsInRows($response, $userB, 'first_name');
|
||||
|
||||
Passport::actingAs($userInCompanyA);
|
||||
$response = $this->getJson(route('api.users.index'));
|
||||
$this->assertResponseContainsInRows($response, $userA, 'first_name');
|
||||
$this->assertResponseContainsInRows($response, $userB, 'first_name');
|
||||
|
||||
Passport::actingAs($userInCompanyB);
|
||||
$response = $this->getJson(route('api.users.index'));
|
||||
$this->assertResponseContainsInRows($response, $userA, 'first_name');
|
||||
$this->assertResponseContainsInRows($response, $userB, 'first_name');
|
||||
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
Passport::actingAs($superUser);
|
||||
$response = $this->getJson(route('api.users.index'));
|
||||
$this->assertResponseContainsInRows($response, $userA, 'first_name');
|
||||
$this->assertResponseContainsInRows($response, $userB, 'first_name');
|
||||
|
||||
Passport::actingAs($userInCompanyA);
|
||||
$response = $this->getJson(route('api.users.index'));
|
||||
$this->assertResponseContainsInRows($response, $userA, 'first_name');
|
||||
$this->assertResponseDoesNotContainInRows($response, $userB, 'first_name');
|
||||
|
||||
Passport::actingAs($userInCompanyB);
|
||||
$response = $this->getJson(route('api.users.index'));
|
||||
$this->assertResponseDoesNotContainInRows($response, $userA, 'first_name');
|
||||
$this->assertResponseContainsInRows($response, $userB, 'first_name');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue