A free open source IT asset/license management system
Continue implementing tests
Marcus Moore89eff23e44eb
diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.phpindex 73a9e049dc..cd88cdaf2f 100644--- a/database/factories/SettingFactory.php+++ b/database/factories/SettingFactory.php@@ -52,4 +52,13 @@ class SettingFactory extends Factory'email_domain' => 'test.com',];}++ public function withMultipleFullCompanySupport()+ {+ return $this->state(function () {+ return [+ 'full_multiple_companies_support' => 1,+ ];+ });+ }}diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.phpindex fb1dde2909..4769831fd4 100644--- a/tests/Feature/Api/Users/UsersForSelectListTest.php+++ b/tests/Feature/Api/Users/UsersForSelectListTest.php@@ -2,6 +2,7 @@namespace Tests\Feature\Api\Users;+use App\Models\Company;use App\Models\Setting;use App\Models\User;use Illuminate\Foundation\Testing\RefreshDatabase;@@ -37,14 +38,43 @@ class UsersForSelectListTest extends TestCasepublic function testUsersScopedToCompanyWhenMultipleFullCompanySupportEnabled(){- $this->markTestIncomplete();+ Setting::factory()->withMultipleFullCompanySupport()->create();+ [$jedi, $sith] = Company::factory()->count(2)->create();++ User::factory()+ ->for($sith)+ ->create(['first_name' => 'Darth', 'last_name' => 'Vader']);++ User::factory()+ ->for($jedi)+ ->count(3)+ ->sequence(+ ['first_name' => 'Luke', 'last_name' => 'Skywalker'],+ ['first_name' => 'Obi-Wan', 'last_name' => 'Kenobi'],+ ['first_name' => 'Anakin', 'last_name' => 'Skywalker'],+ )+ ->create();++ Passport::actingAs($jedi->users->first());+ $response = $this->getJson(route('api.users.selectlist'));+ $response->assertOk();++ $results = collect($response->json('results'));++ $this->assertEquals($jedi->users->count(), $results->count());++ $this->assertTrue(+ $results->pluck('text')->contains(fn($text) => str_contains($text, $jedi->users->first()->first_name))+ );++ $this->assertFalse(+ $results->pluck('text')->contains(fn($text) => str_contains($text, $sith->users->first()->first_name))+ );}public function testUsersScopedToCompanyDuringSearchWhenMultipleFullCompanySupportEnabled(){- $this->markTestIncomplete();--+}}diff --git a/tests/TestCase.php b/tests/TestCase.phpindex 2932d4a69d..5082341307 100644--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -2,9 +2,17 @@namespace Tests;+use App\Models\Setting;use Illuminate\Foundation\Testing\TestCase as BaseTestCase;abstract class TestCase extends BaseTestCase{use CreatesApplication;++ protected function setUp(): void+ {+ parent::setUp();++ $this->beforeApplicationDestroyed(fn() => Setting::$_cache = null);+ }}