Skip to content

Commit 78fba3d

Browse files
committed
ACP2E-3897: [Mainline] Wrong results in products graphQL query
1 parent d79efbd commit 78fba3d

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,75 @@ public function sortByPriceAndNameDataProvider(): array
204204
];
205205
}
206206

207+
/**
208+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
209+
* @dataProvider filterByNameWithMatchTypeSpecifiedDataProvider
210+
*/
211+
#[
212+
DataFixture(ProductFixture::class, ['price' => 10, 'name' => 'Cronus Yoga Pant'], 'prod1'),
213+
DataFixture(ProductFixture::class, ['price' => 10, 'name' => 'Lucia Cross-Fit Bra'], 'prod2'),
214+
DataFixture(ProductFixture::class, ['price' => 20, 'name' => 'Crown Summit Backpack'], 'prod3'),
215+
]
216+
public function testFilterByNameWithMatchTypeSpecified($matchType, $expectedOrder, $expectedTotalCount): void
217+
{
218+
$expectedNames = [];
219+
foreach ($expectedOrder as $productName) {
220+
$expectedNames[] = $this->fixture->get($productName)->getName();
221+
}
222+
$query = <<<'QUERY'
223+
query GetProductsQuery(
224+
$search: String,
225+
$searchWord: String,
226+
$matchType: FilterMatchTypeEnum
227+
$pageSize: Int,
228+
$currentPage: Int
229+
) {
230+
products(
231+
search: $search,
232+
filter: {name: {match: $searchWord, match_type: $matchType} },
233+
pageSize: $pageSize,
234+
currentPage: $currentPage,
235+
sort: {name: ASC}
236+
) {
237+
total_count
238+
page_info{total_pages}
239+
items{
240+
__typename
241+
url_key
242+
sku
243+
name
244+
}
245+
}
246+
}
247+
QUERY;
248+
$variables = [
249+
'search' => null,
250+
'searchWord' => 'Cros',
251+
'matchType' => $matchType,
252+
'pageSize' => 24,
253+
'currentPage' => 1
254+
];
255+
256+
$response = $this->graphQlQuery($query, $variables);
257+
$this->assertArrayNotHasKey('errors', $response);
258+
$this->assertEquals($expectedTotalCount, $response['products']['total_count']);
259+
$this->assertEquals($expectedNames, array_column($response['products']['items'], 'name'));
260+
}
261+
262+
/**
263+
* @return array
264+
*/
265+
public function filterByNameWithMatchTypeSpecifiedDataProvider(): array
266+
{
267+
return [
268+
[
269+
'PARTIAL',
270+
['prod2'],
271+
1
272+
],
273+
];
274+
}
275+
207276
/**
208277
* Verify that filters for non-existing category are empty
209278
*

0 commit comments

Comments
 (0)