mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Add failing test
This commit is contained in:
parent
535ca0e3c0
commit
aafa1ab70e
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Api\Users;
|
namespace Tests\Feature\Api\Users;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
use Tests\Support\InteractsWithSettings;
|
use Tests\Support\InteractsWithSettings;
|
||||||
|
@ -83,4 +84,67 @@ class UsersSearchTest extends TestCase
|
||||||
'Expected deleted user does not appear in results'
|
'Expected deleted user does not appear in results'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUsersScopedToCompanyWhenMultipleFullCompanySupportEnabled()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
$companyA = Company::factory()
|
||||||
|
->has(User::factory(['first_name' => 'Company A', 'last_name' => 'User']))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
Company::factory()
|
||||||
|
->has(User::factory(['first_name' => 'Company B', 'last_name' => 'User']))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAsForApi(User::factory()->for($companyA)->viewUsers()->create())
|
||||||
|
->getJson(route('api.users.index'))
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
$results = collect($response->json('rows'));
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$results->pluck('name')->contains(fn($text) => str_contains($text, 'Company A')),
|
||||||
|
'User index does not contain expected user'
|
||||||
|
);
|
||||||
|
$this->assertFalse(
|
||||||
|
$results->pluck('name')->contains(fn($text) => str_contains($text, 'Company B')),
|
||||||
|
'User index contains unexpected user from another company'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUsersScopedToCompanyDuringSearchWhenMultipleFullCompanySupportEnabled()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
$companyA = Company::factory()
|
||||||
|
->has(User::factory(['first_name' => 'Company A', 'last_name' => 'User']))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
Company::factory()
|
||||||
|
->has(User::factory(['first_name' => 'Company B', 'last_name' => 'User']))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$response = $this->actingAsForApi(User::factory()->for($companyA)->viewUsers()->create())
|
||||||
|
->getJson(route('api.users.index', [
|
||||||
|
'deleted' => 'false',
|
||||||
|
'company_id' => null,
|
||||||
|
'search' => 'user',
|
||||||
|
'order' => 'asc',
|
||||||
|
'offset' => '0',
|
||||||
|
'limit' => '20',
|
||||||
|
]))
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
$results = collect($response->json('rows'));
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$results->pluck('name')->contains(fn($text) => str_contains($text, 'Company A')),
|
||||||
|
'User index does not contain expected user'
|
||||||
|
);
|
||||||
|
$this->assertFalse(
|
||||||
|
$results->pluck('name')->contains(fn($text) => str_contains($text, 'Company B')),
|
||||||
|
'User index contains unexpected user from another company'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue