create(['name' => 'Acme Industries', 'slug' => 'acme-industries']); $globex = Company::factory()->create(['name' => 'Globex Corporation', 'slug' => 'globex-corp']); $results = Company::query()->searchByTerm('Acme')->pluck('id'); expect($results)->toContain($acme->id) ->not->toContain($globex->id); }); test('searchByTerm returns the query unchanged for a blank term', function () { Company::factory()->count(3)->create(); expect(Company::query()->searchByTerm('')->count())->toBe(Company::query()->count()); }); test('searchByTerm strips a trailing portal abbreviation from the term', function () { $company = Company::factory()->create(['name' => 'Musterfirma']); expect(Company::query()->searchByTerm('Musterfirma (PE)')->pluck('id'))->toContain($company->id); }); test('accessibleBy includes owned and member companies but excludes others', function () { $user = User::factory()->create(); $owned = Company::factory()->create(['owner_user_id' => $user->id]); $member = Company::factory()->create(); $member->users()->attach($user->id, ['role' => 'member']); $foreign = Company::factory()->create(); $ids = Company::query()->withoutGlobalScopes()->accessibleBy($user)->pluck('id'); expect($ids)->toContain($owned->id) ->toContain($member->id) ->not->toContain($foreign->id); });