Skip to content

Commit e33486d

Browse files
committed
B2B-2256: "countries" and "country" GraphQl query has no cache identity
1 parent 5060779 commit e33486d

File tree

2 files changed

+126
-69
lines changed

2 files changed

+126
-69
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CountriesTest.php

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,57 @@
1414
*/
1515
class CountriesTest extends GraphQlAbstract
1616
{
17+
/**
18+
* Test stores set up:
19+
* STORE - WEBSITE - STORE GROUP
20+
* default - base - main_website_store
21+
* test - base - main_website_store
22+
*
23+
* @magentoApiDataFixture Magento/Store/_files/store.php
24+
* @magentoConfigFixture default/general/locale/code en_US
25+
* @magentoConfigFixture default/general/country/allow US
26+
* @magentoConfigFixture test_store general/locale/code en_US
27+
* @magentoConfigFixture test_store general/country/allow US,DE
28+
*/
1729
public function testGetCountries()
1830
{
19-
$query = <<<QUERY
20-
query {
21-
countries {
22-
id
23-
two_letter_abbreviation
24-
three_letter_abbreviation
25-
full_name_locale
26-
full_name_english
27-
available_regions {
28-
id
29-
code
30-
name
31-
}
32-
}
33-
}
34-
QUERY;
35-
36-
$result = $this->graphQlQuery($query);
31+
$result = $this->graphQlQuery($this->getQuery());
3732
$this->assertArrayHasKey('countries', $result);
33+
$this->assertCount(1, $result['countries']);
3834
$this->assertArrayHasKey('id', $result['countries'][0]);
3935
$this->assertArrayHasKey('two_letter_abbreviation', $result['countries'][0]);
4036
$this->assertArrayHasKey('three_letter_abbreviation', $result['countries'][0]);
4137
$this->assertArrayHasKey('full_name_locale', $result['countries'][0]);
4238
$this->assertArrayHasKey('full_name_english', $result['countries'][0]);
4339
$this->assertArrayHasKey('available_regions', $result['countries'][0]);
40+
41+
$testStoreResult = $this->graphQlQuery(
42+
$this->getQuery(),
43+
[],
44+
'',
45+
['Store' => 'test']
46+
);
47+
$this->assertArrayHasKey('countries', $testStoreResult);
48+
$this->assertCount(2, $testStoreResult['countries']);
4449
}
4550

4651
public function testCheckCountriesForNullLocale()
4752
{
48-
$query = <<<QUERY
53+
$result = $this->graphQlQuery($this->getQuery());
54+
$count = count($result['countries']);
55+
for ($i=0; $i < $count; $i++) {
56+
$this->assertNotNull($result['countries'][$i]['full_name_locale']);
57+
}
58+
}
59+
60+
/**
61+
* Get query
62+
*
63+
* @return string
64+
*/
65+
private function getQuery(): string
66+
{
67+
return <<<QUERY
4968
query {
5069
countries {
5170
id
@@ -61,11 +80,5 @@ public function testCheckCountriesForNullLocale()
6180
}
6281
}
6382
QUERY;
64-
65-
$result = $this->graphQlQuery($query);
66-
$count = count($result['countries']);
67-
for ($i=0; $i < $count; $i++) {
68-
$this->assertNotNull($result['countries'][$i]['full_name_locale']);
69-
}
7083
}
7184
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CountryTest.php

Lines changed: 88 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,85 @@
1414
*/
1515
class CountryTest extends GraphQlAbstract
1616
{
17-
public function testGetCountry()
17+
/**
18+
* Test stores set up:
19+
* STORE - WEBSITE - STORE GROUP
20+
* default - base - main_website_store
21+
* test - base - main_website_store
22+
*
23+
* @magentoApiDataFixture Magento/Store/_files/store.php
24+
* @magentoConfigFixture default/general/locale/code en_US
25+
* @magentoConfigFixture default/general/country/allow US
26+
* @magentoConfigFixture test_store general/locale/code en_US
27+
* @magentoConfigFixture test_store general/country/allow US,DE
28+
*/
29+
public function testGetDefaultStoreUSCountry()
1830
{
19-
$query = <<<QUERY
20-
query {
21-
country(id: "US") {
22-
id
23-
two_letter_abbreviation
24-
three_letter_abbreviation
25-
full_name_locale
26-
full_name_english
27-
available_regions {
28-
id
29-
code
30-
name
31-
}
31+
$result = $this->graphQlQuery($this->getQuery('US'));
32+
$this->assertArrayHasKey('country', $result);
33+
$this->assertEquals('US', $result['country']['id']);
34+
$this->assertEquals('US', $result['country']['two_letter_abbreviation']);
35+
$this->assertEquals('USA', $result['country']['three_letter_abbreviation']);
36+
$this->assertEquals('United States', $result['country']['full_name_locale']);
37+
$this->assertEquals('United States', $result['country']['full_name_english']);
38+
$this->assertCount(65, $result['country']['available_regions']);
39+
$this->assertArrayHasKey('id', $result['country']['available_regions'][0]);
40+
$this->assertArrayHasKey('code', $result['country']['available_regions'][0]);
41+
$this->assertArrayHasKey('name', $result['country']['available_regions'][0]);
3242
}
33-
}
34-
QUERY;
3543

36-
$result = $this->graphQlQuery($query);
44+
/**
45+
* Test stores set up:
46+
* STORE - WEBSITE - STORE GROUP
47+
* default - base - main_website_store
48+
* test - base - main_website_store
49+
*
50+
* @magentoApiDataFixture Magento/Store/_files/store.php
51+
* @magentoConfigFixture default/general/locale/code en_US
52+
* @magentoConfigFixture default/general/country/allow US
53+
* @magentoConfigFixture test_store general/locale/code en_US
54+
* @magentoConfigFixture test_store general/country/allow US,DE
55+
*/
56+
public function testGetTestStoreDECountry()
57+
{
58+
$result = $this->graphQlQuery(
59+
$this->getQuery('DE'),
60+
[],
61+
'',
62+
['Store' => 'test']
63+
);
3764
$this->assertArrayHasKey('country', $result);
38-
$this->assertArrayHasKey('id', $result['country']);
39-
$this->assertArrayHasKey('two_letter_abbreviation', $result['country']);
40-
$this->assertArrayHasKey('three_letter_abbreviation', $result['country']);
41-
$this->assertArrayHasKey('full_name_locale', $result['country']);
42-
$this->assertArrayHasKey('full_name_english', $result['country']);
43-
$this->assertArrayHasKey('available_regions', $result['country']);
65+
$this->assertEquals('DE', $result['country']['id']);
66+
$this->assertEquals('DE', $result['country']['two_letter_abbreviation']);
67+
$this->assertEquals('DEU', $result['country']['three_letter_abbreviation']);
68+
$this->assertEquals('Germany', $result['country']['full_name_locale']);
69+
$this->assertEquals('Germany', $result['country']['full_name_english']);
70+
$this->assertCount(16, $result['country']['available_regions']);
4471
$this->assertArrayHasKey('id', $result['country']['available_regions'][0]);
4572
$this->assertArrayHasKey('code', $result['country']['available_regions'][0]);
4673
$this->assertArrayHasKey('name', $result['country']['available_regions'][0]);
4774
}
4875

4976
/**
77+
* Test stores set up:
78+
* STORE - WEBSITE - STORE GROUP
79+
* default - base - main_website_store
80+
* test - base - main_website_store
81+
*
82+
* @magentoApiDataFixture Magento/Store/_files/store.php
83+
* @magentoConfigFixture default/general/locale/code en_US
84+
* @magentoConfigFixture default/general/country/allow US
85+
* @magentoConfigFixture test_store general/locale/code en_US
86+
* @magentoConfigFixture test_store general/country/allow US,DE
5087
*/
51-
public function testGetCountryNotFoundException()
88+
public function testGetDefaultStoreDECountryNotFoundException()
5289
{
5390
$this->expectException(\Exception::class);
5491
$this->expectExceptionMessage('GraphQL response contains errors: The country isn\'t available.');
5592

56-
$query = <<<QUERY
57-
query {
58-
country(id: "BLAH") {
59-
id
60-
two_letter_abbreviation
61-
three_letter_abbreviation
62-
full_name_locale
63-
full_name_english
64-
available_regions {
65-
id
66-
code
67-
name
68-
}
93+
$this->graphQlQuery($this->getQuery('DE'));
6994
}
70-
}
71-
QUERY;
7295

73-
$this->graphQlQuery($query);
74-
}
75-
76-
/**
77-
*/
7896
public function testMissedInputParameterException()
7997
{
8098
$this->expectException(\Exception::class);
@@ -94,4 +112,30 @@ public function testMissedInputParameterException()
94112

95113
$this->graphQlQuery($query);
96114
}
115+
116+
/**
117+
* Get query
118+
*
119+
* @param string $countryId
120+
* @return string
121+
*/
122+
private function getQuery(string $countryId): string
123+
{
124+
return <<<QUERY
125+
query {
126+
country(id: {$countryId}) {
127+
id
128+
two_letter_abbreviation
129+
three_letter_abbreviation
130+
full_name_locale
131+
full_name_english
132+
available_regions {
133+
id
134+
code
135+
name
136+
}
137+
}
138+
}
139+
QUERY;
140+
}
97141
}

0 commit comments

Comments
 (0)