diff --git a/tests/Feature/APIv1/UserSearchTest.php b/tests/Feature/APIv1/UserSearchTest.php new file mode 100644 index 000000000..dbd358414 --- /dev/null +++ b/tests/Feature/APIv1/UserSearchTest.php @@ -0,0 +1,44 @@ + '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(); + } +}