diff --git a/tests/Feature/Api/V1/ItemsAggregationsTest.php b/tests/Feature/Api/V1/ItemsAggregationsTest.php index 3375ded58..d94bac7e0 100644 --- a/tests/Feature/Api/V1/ItemsAggregationsTest.php +++ b/tests/Feature/Api/V1/ItemsAggregationsTest.php @@ -129,4 +129,18 @@ public function test_size_limits_number_of_buckets() ])['topic'] ); } + + public function test_search_for_authors_with_same_name() + { + $authorSameName = Item::factory()->create([ + 'author' => 'Galanda, Mikuláš', + ]); + + $this->getAggregations([ + 'filter' => ['author_id' => [1]], + 'terms' => ['author' => 'author'], + ])->assertExactJson([ + 'author' => [['value' => 'Galanda, Mikuláš', 'count' => 1]], + ]); + } } diff --git a/tests/Feature/Api/V1/ItemsTest.php b/tests/Feature/Api/V1/ItemsTest.php index daadcace7..689fd5ea2 100644 --- a/tests/Feature/Api/V1/ItemsTest.php +++ b/tests/Feature/Api/V1/ItemsTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Api\V1; +use App\Authority; use App\Elasticsearch\Repositories\ItemRepository; use App\Item; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -95,6 +96,41 @@ public function test_filtering_by_color() ]); } + public function test_distinguishes_authors_with_same_name() + { + $author1 = Authority::factory()->create(['name' => 'Věšín, Jaroslav']); + $author2 = Authority::factory()->create(['name' => 'Věšín, Jaroslav']); + + Item::factory() + ->create() + ->authorities() + ->save($author1); + Item::factory() + ->create() + ->authorities() + ->save($author2); + + app(ItemRepository::class)->refreshIndex(); + + $searchByName = route('api.v1.items.index', [ + 'size' => 10, + 'filter[author]' => 'Věšín, Jaroslav', + ]); + + $this->getJson($searchByName)->assertJson([ + 'total' => 2, + ]); + + $searchById = route('api.v1.items.index', [ + 'size' => 10, + 'filter[author_id]' => $author1->id, + ]); + + $this->getJson($searchById)->assertJson([ + 'total' => 1, + ]); + } + public function test_sorting() { Item::factory()->create(['title' => 'zebra']);