Skip to content

Commit ae69290

Browse files
authored
Improve distinct tests (#754)
1 parent 520036c commit ae69290

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tests/Endpoints/SearchTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,11 +888,25 @@ public function testSearchWithDistinctAttribute(): void
888888

889889
$response = $this->index->search(null, [
890890
'distinct' => 'genre',
891-
'filter' => ['genre = fantasy'],
892891
])->toArray();
893892

894-
self::assertArrayHasKey('title', $response['hits'][0]);
895-
self::assertCount(1, $response['hits']);
893+
// Should have one document per unique genre
894+
// From DOCUMENTS: romance, adventure, fantasy, plus one document without genre
895+
self::assertCount(4, $response['hits']);
896+
897+
// Extract genres from the results
898+
$genres = [];
899+
foreach ($response['hits'] as $hit) {
900+
$genre = $hit['genre'] ?? null;
901+
self::assertNotContains($genre, $genres, 'Each genre should appear only once in distinct results');
902+
$genres[] = $genre;
903+
}
904+
905+
// Verify we have the expected unique genres
906+
$expectedGenres = ['romance', 'adventure', 'fantasy', null];
907+
foreach ($expectedGenres as $expectedGenre) {
908+
self::assertContains($expectedGenre, $genres, "Genre '{$expectedGenre}' should be present in distinct results");
909+
}
896910
}
897911

898912
public function testSearchWithLocales(): void

0 commit comments

Comments
 (0)