mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Write tests around getIdForCurrentUser method [sc-24748]
This commit is contained in:
parent
7b4020c5e9
commit
76cc5995d9
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace Tests\Unit;
|
||||
namespace Tests\Unit\Models\Company;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
45
tests/Unit/Models/Company/GetIdForCurrentUserTest.php
Normal file
45
tests/Unit/Models/Company/GetIdForCurrentUserTest.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Models\Company;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GetIdForCurrentUserTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testReturnsProvidedValueWhenFullCompanySupportDisabled()
|
||||
{
|
||||
$this->settings->disableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAs(User::factory()->create());
|
||||
$this->assertEquals(1000, Company::getIdForCurrentUser(1000));
|
||||
}
|
||||
|
||||
public function testReturnsProvidedValueForSuperUsersWhenFullCompanySupportEnabled()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAs(User::factory()->superuser()->create());
|
||||
$this->assertEquals(2000, Company::getIdForCurrentUser(2000));
|
||||
}
|
||||
|
||||
public function testReturnsNonSuperUsersCompanyIdWhenFullCompanySupportEnabled()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAs(User::factory()->forCompany(['id' => 2000])->create());
|
||||
$this->assertEquals(2000, Company::getIdForCurrentUser(1000));
|
||||
}
|
||||
|
||||
public function testReturnsProvidedValueForNonSuperUserWithoutCompanyIdWhenFullCompanySupportEnabled()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAs(User::factory()->create(['company_id' => null]));
|
||||
$this->assertEquals(1000, Company::getIdForCurrentUser(1000));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue