mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Add test for searching for user's first and last name
This commit is contained in:
parent
b2b6f0cf96
commit
6300909fee
28
tests/Feature/Api/Users/UsersSearchTest.php
Normal file
28
tests/Feature/Api/Users/UsersSearchTest.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\Users;
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Passport\Passport;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UsersSearchTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testCanSearchByUserFirstAndLastName()
|
||||
{
|
||||
User::factory()->create(['first_name' => 'Luke', 'last_name' => 'Skywalker']);
|
||||
User::factory()->create(['first_name' => 'Darth', 'last_name' => 'Vader']);
|
||||
|
||||
Passport::actingAs(User::factory()->viewUsers()->create());
|
||||
$response = $this->getJson(route('api.users.index', ['search' => 'luke sky']))->assertOk();
|
||||
|
||||
$results = collect($response->json('rows'));
|
||||
|
||||
$this->assertEquals(1, $results->count());
|
||||
$this->assertTrue($results->pluck('name')->contains(fn($text) => str_contains($text, 'Luke')));
|
||||
$this->assertFalse($results->pluck('name')->contains(fn($text) => str_contains($text, 'Darth')));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue