Skip to content

Commit c51ec52

Browse files
committed
Issue-230: adding varnish
- fixing test - handling error codes > 400
1 parent bf84115 commit c51ec52

File tree

2 files changed

+117
-30
lines changed

2 files changed

+117
-30
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQl/Client.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ public function get(string $query, array $variables = [], string $operationName
8686
];
8787
array_filter($requestArray);
8888

89-
$responseBody = $this->curlClient->get($url, $requestArray, $headers);
89+
try {
90+
$responseBody = $this->curlClient->get($url, $requestArray, $headers);
91+
} catch (\Exception $e) {
92+
// if response code > 400 then response is the exception message
93+
$responseBody = $e->getMessage();
94+
}
9095
return $this->processResponse($responseBody);
9196
}
9297

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

Lines changed: 111 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,73 @@
1818
class ProductInMultipleStoresCacheTest extends GraphQlAbstract
1919
{
2020
/**
21-
* Test a non existing or non allowed currency
21+
* @inheritdoc
22+
*/
23+
protected function setUp()
24+
{
25+
/** @var \Magento\Store\Model\Store $store */
26+
$store = ObjectManager::getInstance()->get(\Magento\Store\Model\Store::class);
27+
$storeCodeFromFixture = 'fixture_second_store';
28+
29+
/** @var \Magento\Config\Model\ResourceModel\Config $configResource */
30+
$configResource = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class);
31+
/** @var \Magento\Config\App\Config\Type\System $config */
32+
$config = ObjectManager::getInstance()->get(\Magento\Config\App\Config\Type\System::class);
33+
34+
$configResource->saveConfig(
35+
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT,
36+
'EUR',
37+
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES,
38+
$store->load($storeCodeFromFixture)->getWebsiteId()
39+
);
40+
41+
// allow USD & EUR currency
42+
$configResource->saveConfig(
43+
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW,
44+
'EUR,USD',
45+
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES,
46+
$store->load($storeCodeFromFixture)->getWebsiteId()
47+
);
48+
49+
// allow USD & EUR currency
50+
$configResource->saveConfig(
51+
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW,
52+
'EUR,USD'
53+
);
54+
55+
// configuration cache clean is required to reload currency setting
56+
$config->clean();
57+
}
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
protected function tearDown()
63+
{
64+
/** @var \Magento\Config\App\Config\Type\System $config */
65+
$config = ObjectManager::getInstance()->get(\Magento\Config\App\Config\Type\System::class);
66+
/** @var \Magento\Config\Model\ResourceModel\Config $configResource */
67+
$configResource = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class);
68+
69+
// restore allow USD currency
70+
$configResource->saveConfig(
71+
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW,
72+
'USD'
73+
);
74+
75+
// configuration cache clean is required to reload currency setting
76+
$config->clean();
77+
parent::tearDown();
78+
}
79+
80+
/**
81+
* Test a non existing or non existing currency
2282
*
2383
* @magentoApiDataFixture Magento/Store/_files/second_website_with_second_currency.php
2484
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
2585
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2686
*/
27-
public function testProductFromSpecificAndDefaultStoreWithMultiCurrencyNotAllowed()
87+
public function testProductFromSpecificAndDefaultStoreWithMultiCurrencyNonExisting()
2888
{
2989
$productSku = 'simple';
3090

@@ -56,16 +116,58 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrencyNotAllowe
56116
}
57117
QUERY;
58118

59-
$storeCodeFromFixture = 'fixture_second_store';
60-
61119
//test non existing currency
62120
$headerMap = ['Store' => 'default', 'Content-Currency' => 'someNonExistentCurrency'];
63-
$this->expectExceptionMessage('Currency someNonExistentCurrency not allowed for store default');
121+
$this->expectExceptionMessage('GraphQL response contains errors: Currency not allowed for store default');
64122
$this->graphQlQuery($query, [], '', $headerMap);
123+
}
124+
125+
/**
126+
* Test a non existing or non allowed currency
127+
*
128+
* @magentoApiDataFixture Magento/Store/_files/second_website_with_second_currency.php
129+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
130+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
131+
*/
132+
public function testProductFromSpecificAndDefaultStoreWithMultiCurrencyNotAllowed()
133+
{
134+
$productSku = 'simple';
135+
136+
$query = <<<QUERY
137+
{
138+
products(filter: {sku: {eq: "{$productSku}"}})
139+
{
140+
items {
141+
attribute_set_id
142+
created_at
143+
id
144+
name
145+
price {
146+
minimalPrice {
147+
amount {
148+
value
149+
currency
150+
}
151+
}
152+
}
153+
sku
154+
type_id
155+
updated_at
156+
... on PhysicalProductInterface {
157+
weight
158+
}
159+
}
160+
}
161+
}
162+
QUERY;
163+
164+
$storeCodeFromFixture = 'fixture_second_store';
65165

66166
//test not allowed existing currency
67167
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'CAD'];
68-
$this->expectExceptionMessage('Currency not allowed for store ' . $storeCodeFromFixture);
168+
$this->expectExceptionMessage(
169+
"GraphQL response contains errors: Currency not allowed for store {$storeCodeFromFixture}"
170+
);
69171
$this->graphQlQuery($query, [], '', $headerMap);
70172
}
71173

@@ -113,28 +215,6 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
113215
$storeCodeFromFixture = 'fixture_second_store';
114216
$storeId = $store->load($storeCodeFromFixture)->getStoreId();
115217

116-
$configResource = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class);
117-
118-
$configResource->saveConfig(
119-
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT,
120-
'EUR',
121-
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES,
122-
$store->load($storeCodeFromFixture)->getWebsiteId()
123-
);
124-
125-
// allow USD & EUR currency
126-
$configResource->saveConfig(
127-
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW,
128-
'EUR,USD',
129-
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES,
130-
$store->load($storeCodeFromFixture)->getWebsiteId()
131-
);
132-
133-
/** @var \Magento\Config\App\Config\Type\System $config */
134-
$config = ObjectManager::getInstance()->get(\Magento\Config\App\Config\Type\System::class);
135-
// configuration cache clean is required to reload currency setting
136-
$config->clean();
137-
138218
/** @var \Magento\Catalog\Model\Product $product */
139219
$product = ObjectManager::getInstance()->get(\Magento\Catalog\Model\Product::class);
140220
$product->load($product->getIdBySku($productSku));
@@ -234,7 +314,9 @@ public function testProductFromSpecificAndDefaultStoreWithMultiCurrency()
234314

235315
// test cached response store + currency header with non existing currency, and no valid response, no cache
236316
$headerMap = ['Store' => $storeCodeFromFixture, 'Content-Currency' => 'SOMECURRENCY'];
237-
$this->expectExceptionMessage('Currency not allowed for store ' . $storeCodeFromFixture);
317+
$this->expectExceptionMessage(
318+
"GraphQL response contains errors: Currency not allowed for store {$storeCodeFromFixture}"
319+
);
238320
$this->graphQlQuery($query, [], '', $headerMap);
239321
}
240322
}

0 commit comments

Comments
 (0)