Skip to content

Commit

Permalink
Tests WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
eronisko committed Jan 12, 2024
1 parent ddc667c commit 1174547
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/Feature/Api/V1/ItemsAggregationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
]);
}
}
36 changes: 36 additions & 0 deletions tests/Feature/Api/V1/ItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
Expand Down

0 comments on commit 1174547

Please sign in to comment.