Skip to content

Commit b35c269

Browse files
committed
MC-21480: Add caching for CategoryList resolver
- integration test
1 parent b77d131 commit b35c269

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQlCache\Controller\Catalog;
9+
10+
use Magento\GraphQlCache\Controller\AbstractGraphqlCacheTest;
11+
12+
/**
13+
* Test caching works for categoryList query
14+
*
15+
* @magentoAppArea graphql
16+
* @magentoCache full_page enabled
17+
* @magentoDbIsolation disabled
18+
*/
19+
class CategoryListCacheTest extends AbstractGraphqlCacheTest
20+
{
21+
/**
22+
* Test cache tags are generated
23+
*
24+
* @magentoDataFixture Magento/Catalog/_files/category_product.php
25+
*/
26+
public function testRequestCacheTagsForCategoryList(): void
27+
{
28+
$categoryId ='333';
29+
$query
30+
= <<<QUERY
31+
{
32+
categoryList(filters: {ids: {in: ["$categoryId"]}}) {
33+
id
34+
name
35+
url_key
36+
description
37+
product_count
38+
}
39+
}
40+
QUERY;
41+
$response = $this->dispatchGraphQlGETRequest(['query' => $query]);
42+
$this->assertEquals('MISS', $response->getHeader('X-Magento-Cache-Debug')->getFieldValue());
43+
$actualCacheTags = explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue());
44+
$expectedCacheTags = ['cat_c','cat_c_' . $categoryId, 'FPC'];
45+
$this->assertEquals($expectedCacheTags, $actualCacheTags);
46+
}
47+
48+
/**
49+
* Test request is served from cache
50+
*
51+
* @magentoDataFixture Magento/Catalog/_files/category_product.php
52+
*/
53+
public function testSecondRequestIsServedFromCache()
54+
{
55+
$categoryId ='333';
56+
$query
57+
= <<<QUERY
58+
{
59+
categoryList(filters: {ids: {in: ["$categoryId"]}}) {
60+
id
61+
name
62+
url_key
63+
description
64+
product_count
65+
}
66+
}
67+
QUERY;
68+
$expectedCacheTags = ['cat_c','cat_c_' . $categoryId, 'FPC'];
69+
70+
$response = $this->dispatchGraphQlGETRequest(['query' => $query]);
71+
$this->assertEquals('MISS', $response->getHeader('X-Magento-Cache-Debug')->getFieldValue());
72+
$actualCacheTags = explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue());
73+
$this->assertEquals($expectedCacheTags, $actualCacheTags);
74+
75+
$cacheResponse = $this->dispatchGraphQlGETRequest(['query' => $query]);
76+
$this->assertEquals('HIT', $cacheResponse->getHeader('X-Magento-Cache-Debug')->getFieldValue());
77+
$actualCacheTags = explode(',', $cacheResponse->getHeader('X-Magento-Tags')->getFieldValue());
78+
$this->assertEquals($expectedCacheTags, $actualCacheTags);
79+
}
80+
}

0 commit comments

Comments
 (0)