-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ allow searching explicitly for username or displayname (#3064)
- Loading branch information
1 parent
2543eef
commit 35f94b6
Showing
4 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\APIv1; | ||
|
||
use App\Models\User; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Laravel\Passport\Passport; | ||
use Tests\ApiTestCase; | ||
|
||
class UserSearchTest extends ApiTestCase | ||
{ | ||
|
||
use RefreshDatabase; | ||
|
||
public function testUserSearch(): void { | ||
$alice = User::factory(['name' => 'Alice', 'username' => 'alice'])->create(); | ||
$bob = User::factory(['name' => 'Bob', 'username' => 'bob'])->create(); | ||
$charlie = User::factory(['name' => 'Charlie', 'username' => 'charlie'])->create(); | ||
|
||
Passport::actingAs($alice, ['*']); | ||
|
||
// 1. Test Search in Path (username AND displayname) - legacy | ||
$response = $this->getJson('/api/v1/user/search/charlie'); | ||
$response->assertOk(); | ||
$response->assertJsonCount(1, 'data'); | ||
$response->assertJsonFragment(['id' => $charlie->id]); | ||
|
||
// 2. Test Search for username in query | ||
$response = $this->getJson('/api/v1/user/search?username=Charlie'); | ||
$response->assertOk(); | ||
$response->assertJsonCount(1, 'data'); | ||
$response->assertJsonFragment(['id' => $charlie->id]); | ||
|
||
// 3. Test Search for displayname in query | ||
$response = $this->getJson('/api/v1/user/search?name=charlie'); | ||
$response->assertOk(); | ||
$response->assertJsonCount(1, 'data'); | ||
$response->assertJsonFragment(['id' => $charlie->id]); | ||
|
||
// 4. Test without any parameters (should fail) | ||
$response = $this->getJson('/api/v1/user/search'); | ||
$response->assertBadRequest(); | ||
} | ||
} |