Continue implementing tests

This commit is contained in:
Marcus Moore 2023-02-02 17:41:32 -08:00
parent a2e47d19fc
commit 89eff23e44
No known key found for this signature in database
3 changed files with 51 additions and 4 deletions

View file

@ -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,
];
});
}
}

View file

@ -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 TestCase
public 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();
}
}

View file

@ -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);
}
}