Skip to content

Commit cfa889e

Browse files
engcom-KiloMaciej Pawłowski
authored and
Maciej Pawłowski
committed
Fixed tests.
1 parent 4a05e78 commit cfa889e

File tree

2 files changed

+54
-20
lines changed

2 files changed

+54
-20
lines changed

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

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

88
namespace Magento\GraphQl\Catalog;
99

10+
use Magento\PageCache\Model\Cache\Type as PageCache;
1011
use Magento\TestFramework\ObjectManager;
11-
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
1212
use Magento\TestFramework\TestCase\GraphQlAbstract;
1313

1414
/**
@@ -77,12 +77,7 @@ public function testProductFromSpecificAndDefaultStore()
7777
'Product name in fixture store is invalid.'
7878
);
7979

80-
// use case for invalid storeCode
81-
$nonExistingStoreCode = "non_existent_store";
82-
$headerMapInvalidStoreCode = ['Store' => $nonExistingStoreCode];
83-
$this->expectException(ResponseContainsErrorsException::class);
84-
$this->expectExceptionMessage('Requested store is not found');
85-
$this->graphQlQuery($query, [], '', $headerMapInvalidStoreCode);
80+
$this->flushPageCache();
8681

8782
//use case for default storeCode
8883
$nameInDefaultStore = 'Simple Product';
@@ -94,6 +89,8 @@ public function testProductFromSpecificAndDefaultStore()
9489
'Product name in default store is invalid.'
9590
);
9691

92+
$this->flushPageCache();
93+
9794
//use case for empty storeCode
9895
$headerMapEmpty = ['Store' => ''];
9996
$response = $this->graphQlQuery($query, [], '', $headerMapEmpty);
@@ -102,5 +99,21 @@ public function testProductFromSpecificAndDefaultStore()
10299
$response['products']['items'][0]['name'],
103100
'Product in the default store should be returned'
104101
);
102+
103+
$this->flushPageCache();
104+
105+
// use case for invalid storeCode
106+
$nonExistingStoreCode = "non_existent_store";
107+
$headerMapInvalidStoreCode = ['Store' => $nonExistingStoreCode];
108+
$this->expectException(\Exception::class);
109+
$this->expectExceptionMessage('Requested store is not found');
110+
$this->graphQlQuery($query, [], '', $headerMapInvalidStoreCode);
111+
}
112+
113+
protected function flushPageCache(): void
114+
{
115+
/** @var PageCache $fullPageCache */
116+
$fullPageCache = ObjectManager::getInstance()->get(PageCache::class);
117+
$fullPageCache->clean();
105118
}
106119
}

dev/tests/api-functional/testsuite/Magento/GraphQl/PageCache/ProductInMultipleStoresCacheTest.php

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\PageCache;
99

10+
use Magento\PageCache\Model\Cache\Type as PageCache;
1011
use Magento\TestFramework\ObjectManager;
1112
use Magento\TestFramework\TestCase\GraphQlAbstract;
1213

@@ -242,6 +243,8 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
242243
'Currency code EUR in fixture ' . $storeCodeFromFixture . ' is unexpected'
243244
);
244245

246+
$this->flushPageCache();
247+
245248
// test cached store + currency header in Euros
246249
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'EUR'];
247250
$response = $this->graphQlQuery($query, [], '', $headerMap);
@@ -256,6 +259,8 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
256259
'Currency code EUR in fixture ' . $storeCodeFromFixture . ' is unexpected'
257260
);
258261

262+
$this->flushPageCache();
263+
259264
// test non cached store + currency header in USD
260265
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'USD'];
261266
$response = $this->graphQlQuery($query, [], '', $headerMap);
@@ -270,42 +275,41 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
270275
'Currency code USD in fixture ' . $storeCodeFromFixture . ' is unexpected'
271276
);
272277

278+
$this->flushPageCache();
279+
273280
// test non cached store + currency header in USD not cached
274-
$headerMap = ['Store' => 'default', 'Content-Currency' => 'EUR'];
281+
$headerMap = ['Store' => 'default', 'Content-Currency' => 'USD'];
275282
$response = $this->graphQlQuery($query, [], '', $headerMap);
276283
$this->assertEquals(
277284
'Simple Product',
278285
$response['products']['items'][0]['name'],
279286
'Product name in fixture store is invalid.'
280287
);
281288
$this->assertEquals(
282-
'EUR',
289+
'USD',
283290
$response['products']['items'][0]['price']['minimalPrice']['amount']['currency'],
284-
'Currency code EUR in fixture store default is unexpected'
291+
'Currency code USD in fixture store default is unexpected'
285292
);
286293

287-
// test cached response store + currency header with non existing currency, and no valid response, no cache
288-
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'SOMECURRENCY'];
289-
$this->expectExceptionMessage(
290-
'GraphQL response contains errors: Please correct the target currency'
291-
);
292-
$this->graphQlQuery($query, [], '', $headerMap);
294+
$this->flushPageCache();
293295

294296
// test non cached store + currency header in USD not cached
295-
$headerMap = ['Store' => 'default', 'Content-Currency' => 'USD'];
297+
$headerMap = ['Store' => 'default', 'Content-Currency' => 'EUR'];
296298
$response = $this->graphQlQuery($query, [], '', $headerMap);
297299
$this->assertEquals(
298300
'Simple Product',
299301
$response['products']['items'][0]['name'],
300302
'Product name in fixture store is invalid.'
301303
);
302304
$this->assertEquals(
303-
'USD',
305+
'EUR',
304306
$response['products']['items'][0]['price']['minimalPrice']['amount']['currency'],
305-
'Currency code USD in fixture store default is unexpected'
307+
'Currency code EUR in fixture store default is unexpected'
306308
);
307309

308-
// test non cached store + currency header in USD cached
310+
$this->flushPageCache();
311+
312+
// test non cached store + currency header in USD cached
309313
$headerMap = ['Store' => 'default'];
310314
$response = $this->graphQlQuery($query, [], '', $headerMap);
311315
$this->assertEquals(
@@ -318,5 +322,22 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
318322
$response['products']['items'][0]['price']['minimalPrice']['amount']['currency'],
319323
'Currency code USD in fixture store default is unexpected'
320324
);
325+
326+
$this->flushPageCache();
327+
328+
// test cached response store + currency header with non existing currency, and no valid response, no cache
329+
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'SOMECURRENCY'];
330+
$this->expectExceptionMessage(
331+
'GraphQL response contains errors: Please correct the target currency'
332+
);
333+
334+
$this->graphQlQuery($query, [], '', $headerMap);
335+
}
336+
337+
protected function flushPageCache(): void
338+
{
339+
/** @var PageCache $fullPageCache */
340+
$fullPageCache = ObjectManager::getInstance()->get(PageCache::class);
341+
$fullPageCache->clean();
321342
}
322343
}

0 commit comments

Comments
 (0)