Skip to content

Commit 9983223

Browse files
committed
MC-15986: Category Filtering
- additional test cases
1 parent 8774f67 commit 9983223

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function fetchCategories(array $categoryIds, ResolveInfo $info)
104104
foreach ($categoryIds as $categoryId) {
105105
$categoryTree = $this->categoryTree->getTree($info, $categoryId);
106106
if (empty($categoryTree)) {
107-
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
107+
continue;
108108
}
109109
$fetchedCategories[] = current($this->extractDataFromCategoryTree->execute($categoryTree));
110110
}

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\GraphQl\Catalog;
99

10+
use Magento\Store\Model\StoreManagerInterface;
11+
use Magento\TestFramework\Helper\Bootstrap;
1012
use Magento\TestFramework\TestCase\GraphQlAbstract;
1113

1214
/**
@@ -239,6 +241,64 @@ public function testNoResultsFound()
239241
$this->assertEquals([], $result['categoryList']);
240242
}
241243

244+
/**
245+
* When no filters are supplied, the root category is returned
246+
*
247+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
248+
*/
249+
public function testEmptyFiltersReturnRootCategory()
250+
{
251+
$query = <<<QUERY
252+
{
253+
categoryList{
254+
id
255+
name
256+
url_key
257+
url_path
258+
children_count
259+
path
260+
position
261+
}
262+
}
263+
QUERY;
264+
265+
$storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
266+
$storeRootCategoryId = $storeManager->getStore()->getRootCategoryId();
267+
268+
$result = $this->graphQlQuery($query);
269+
$this->assertArrayNotHasKey('errors', $result);
270+
$this->assertArrayHasKey('categoryList', $result);
271+
$this->assertEquals('Default Category', $result['categoryList'][0]['name']);
272+
$this->assertEquals($storeRootCategoryId, $result['categoryList'][0]['id']);
273+
}
274+
275+
/**
276+
* Filtering with match value less than minimum query should return empty result
277+
*
278+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
279+
*/
280+
public function testMinimumMatchQueryLength()
281+
{
282+
$query = <<<QUERY
283+
{
284+
categoryList(filters: {name: {match: "mo"}}){
285+
id
286+
name
287+
url_key
288+
url_path
289+
children_count
290+
path
291+
position
292+
}
293+
}
294+
QUERY;
295+
296+
$result = $this->graphQlQuery($query);
297+
$this->assertArrayNotHasKey('errors', $result);
298+
$this->assertArrayHasKey('categoryList', $result);
299+
$this->assertEquals([], $result['categoryList']);
300+
}
301+
242302
/**
243303
* @return array
244304
*/

0 commit comments

Comments
 (0)