Skip to content

Commit a5c9011

Browse files
committed
B2B-2005: Magento.GraphQl.Catalog.ProductSearchTest.testSearchAndSortByRelevance is failed with AWS ES
1 parent 202bd44 commit a5c9011

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,11 +1616,16 @@ public function testFilterProductsBySingleCategoryId(string $fieldName, string $
16161616
/**
16171617
* Sorting the search results by relevance (DESC => most relevant)
16181618
*
1619+
* Sorting by relevance may return different results depending on the ES.
1620+
* To check that sorting works, we compare results with ASC and DESC relevance sorting
1621+
*
16191622
* Search for products for a fuzzy match and checks if all matching results returned including
16201623
* results based on matching keywords from description
16211624
*
16221625
* @magentoApiDataFixture Magento/Catalog/_files/products_for_relevance_sorting.php
16231626
* @return void
1627+
*
1628+
* @throws \Exception
16241629
*/
16251630
public function testSearchAndSortByRelevance()
16261631
{
@@ -1630,7 +1635,7 @@ public function testSearchAndSortByRelevance()
16301635
{
16311636
products(
16321637
search:"{$search_term}"
1633-
sort:{relevance:DESC}
1638+
sort:{relevance:%s}
16341639
pageSize: 5
16351640
currentPage: 1
16361641
)
@@ -1671,16 +1676,16 @@ public function testSearchAndSortByRelevance()
16711676
16721677
}
16731678
QUERY;
1674-
$response = $this->graphQlQuery($query);
1675-
$this->assertEquals(3, $response['products']['total_count']);
1676-
$this->assertNotEmpty($response['products']['filters'], 'Filters should have the Category layer');
1677-
$this->assertEquals('Colorful Category', $response['products']['filters'][0]['filter_items'][0]['label']);
1678-
$this->assertCount(2, $response['products']['aggregations']);
1679-
$productsInResponse = ['Blue briefs', 'Navy Blue Striped Shoes', 'Grey shorts'];
1680-
$count = count($response['products']['items']);
1681-
for ($i = 0; $i < $count; $i++) {
1682-
$this->assertEquals($productsInResponse[$i], $response['products']['items'][$i]['name']);
1683-
}
1679+
$responseDesc = $this->graphQlQuery(sprintf($query, 'DESC'));
1680+
$responseAsc = $this->graphQlQuery(sprintf($query, 'ASC'));
1681+
$this->assertEquals(3, $responseDesc['products']['total_count']);
1682+
$this->assertNotEmpty($responseDesc['products']['filters'], 'Filters should have the Category layer');
1683+
$this->assertEquals('Colorful Category', $responseDesc['products']['filters'][0]['filter_items'][0]['label']);
1684+
$this->assertCount(2, $responseDesc['products']['aggregations']);
1685+
$expectedProductsInResponse = ['Blue briefs', 'Navy Blue Striped Shoes', 'Grey shorts'];
1686+
$namesDesc = array_column($responseDesc['products']['items'], 'name');
1687+
$this->assertEqualsCanonicalizing($expectedProductsInResponse, $namesDesc);
1688+
$this->assertEquals($namesDesc, array_reverse(array_column($responseAsc['products']['items'], 'name')));
16841689
}
16851690

16861691
/**

0 commit comments

Comments
 (0)