Skip to content

Commit 0394f37

Browse files
committed
GraphQL-480: [Test Coverage] 'GetBillingAddress' functionality
1 parent ca25925 commit 0394f37

File tree

3 files changed

+107
-138
lines changed

3 files changed

+107
-138
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetBillingAddressTest.php renamed to dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetSpecifiedBillingAddressTest.php

Lines changed: 64 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,51 @@
77

88
namespace Magento\GraphQl\Quote\Customer;
99

10+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1011
use Magento\Integration\Api\CustomerTokenServiceInterface;
11-
use Magento\Quote\Model\QuoteFactory;
12-
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
13-
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1412
use Magento\TestFramework\Helper\Bootstrap;
1513
use Magento\TestFramework\TestCase\GraphQlAbstract;
1614

1715
/**
18-
* Test for get billing address
16+
* Test for get specified billing address
1917
*/
20-
class GetBillingAddressTest extends GraphQlAbstract
18+
class GetSpecifiedBillingAddressTest extends GraphQlAbstract
2119
{
2220
/**
2321
* @var CustomerTokenServiceInterface
2422
*/
2523
private $customerTokenService;
2624

2725
/**
28-
* @var QuoteResource
26+
* @var GetMaskedQuoteIdByReservedOrderId
2927
*/
30-
private $quoteResource;
31-
32-
/**
33-
* @var QuoteFactory
34-
*/
35-
private $quoteFactory;
36-
37-
/**
38-
* @var QuoteIdToMaskedQuoteIdInterface
39-
*/
40-
private $quoteIdToMaskedId;
28+
private $getMaskedQuoteIdByReservedOrderId;
4129

4230
/**
4331
* @inheritdoc
4432
*/
4533
protected function setUp()
4634
{
4735
$objectManager = Bootstrap::getObjectManager();
48-
$this->quoteResource = $objectManager->get(QuoteResource::class);
49-
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
50-
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
36+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
5137
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
5238
}
5339

5440
/**
5541
* @magentoApiDataFixture Magento/Customer/_files/customer.php
56-
* @magentoApiDataFixture Magento/Catalog/_files/products.php
42+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
5743
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
5844
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
59-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
6045
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
6146
*/
62-
public function testGetCartWithBillingAddress()
47+
public function testGeSpecifiedBillingAddress()
6348
{
64-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_quote');
65-
$query = $this->getGetBillingAddressQuery($maskedQuoteId);
49+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
50+
$query = $this->getQuery($maskedQuoteId);
51+
6652
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
53+
self::assertArrayHasKey('cart', $response);
54+
self::assertArrayHasKey('billing_address', $response['cart']);
6755

6856
$expectedBillingAddressData = [
6957
'firstname' => 'John',
@@ -86,41 +74,23 @@ public function testGetCartWithBillingAddress()
8674
'address_type' => 'BILLING',
8775
'customer_notes' => null,
8876
];
89-
9077
self::assertEquals($expectedBillingAddressData, $response['cart']['billing_address']);
9178
}
9279

93-
/**
94-
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
95-
* @magentoApiDataFixture Magento/Catalog/_files/products.php
96-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
97-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
98-
*/
99-
public function testGetBillingAddressFromAnotherCustomerCart()
100-
{
101-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_quote');
102-
$this->expectExceptionMessage(
103-
"The current user cannot perform operations on cart \"$maskedQuoteId\""
104-
);
105-
$this->graphQlQuery(
106-
$this->getGetBillingAddressQuery($maskedQuoteId),
107-
[],
108-
'',
109-
$this->getHeaderMap('customer2@search.example.com')
110-
);
111-
}
112-
11380
/**
11481
* @magentoApiDataFixture Magento/Customer/_files/customer.php
115-
* @magentoApiDataFixture Magento/Catalog/_files/products.php
82+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
11683
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
11784
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
11885
*/
119-
public function testGetBillingAddressIfBillingAddressIsNotSet()
86+
public function testGeSpecifiedBillingAddressIfBillingAddressIsNotSet()
12087
{
121-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_quote');
122-
$query = $this->getGetBillingAddressQuery($maskedQuoteId);
88+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
89+
$query = $this->getQuery($maskedQuoteId);
90+
12391
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
92+
self::assertArrayHasKey('cart', $response);
93+
self::assertArrayHasKey('billing_address', $response['cart']);
12494

12595
$expectedBillingAddressData = [
12696
'firstname' => null,
@@ -143,7 +113,6 @@ public function testGetBillingAddressIfBillingAddressIsNotSet()
143113
'address_type' => 'BILLING',
144114
'customer_notes' => null,
145115
];
146-
147116
self::assertEquals($expectedBillingAddressData, $response['cart']['billing_address']);
148117
}
149118

@@ -152,21 +121,60 @@ public function testGetBillingAddressIfBillingAddressIsNotSet()
152121
* @expectedException \Exception
153122
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
154123
*/
155-
public function testGetBillingAddressOfNonExistentCart()
124+
public function testGeSpecifiedBillingAddressOfNonExistentCart()
156125
{
157126
$maskedQuoteId = 'non_existent_masked_id';
158-
$query = $this->getGetBillingAddressQuery($maskedQuoteId);
127+
$query = $this->getQuery($maskedQuoteId);
159128

160129
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
161130
}
162131

132+
/**
133+
* _security
134+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
135+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
136+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
137+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
138+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
139+
*/
140+
public function testGeSpecifiedBillingAddressFromAnotherGuestCart()
141+
{
142+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
143+
144+
$this->expectExceptionMessage(
145+
"The current user cannot perform operations on cart \"$maskedQuoteId\""
146+
);
147+
$this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap());
148+
}
149+
150+
/**
151+
* _security
152+
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
153+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
154+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
155+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
156+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
157+
*/
158+
public function testGeSpecifiedBillingAddressFromAnotherCustomerCart()
159+
{
160+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
161+
162+
$this->expectExceptionMessage(
163+
"The current user cannot perform operations on cart \"$maskedQuoteId\""
164+
);
165+
$this->graphQlQuery($this->getQuery($maskedQuoteId),
166+
[],
167+
'',
168+
$this->getHeaderMap('customer2@search.example.com')
169+
);
170+
}
171+
163172
/**
164173
* @param string $maskedQuoteId
165174
* @return string
166175
*/
167-
private function getGetBillingAddressQuery(
168-
string $maskedQuoteId
169-
): string {
176+
private function getQuery(string $maskedQuoteId): string
177+
{
170178
return <<<QUERY
171179
{
172180
cart(cart_id: "$maskedQuoteId") {
@@ -207,16 +215,4 @@ private function getHeaderMap(string $username = 'customer@example.com', string
207215
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
208216
return $headerMap;
209217
}
210-
211-
/**
212-
* @param string $reservedOrderId
213-
* @return string
214-
*/
215-
private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string
216-
{
217-
$quote = $this->quoteFactory->create();
218-
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
219-
220-
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
221-
}
222218
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetBillingAddressTest.php renamed to dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetSpecifiedBillingAddressTest.php

Lines changed: 42 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,43 @@
77

88
namespace Magento\GraphQl\Quote\Guest;
99

10-
use Magento\Integration\Api\CustomerTokenServiceInterface;
11-
use Magento\Quote\Model\QuoteFactory;
12-
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
13-
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
10+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1411
use Magento\TestFramework\Helper\Bootstrap;
1512
use Magento\TestFramework\TestCase\GraphQlAbstract;
1613

1714
/**
18-
* Test for get billing address
15+
* Test for get specified billing address
1916
*/
20-
class GetBillingAddressTest extends GraphQlAbstract
17+
class GetSpecifiedBillingAddressTest extends GraphQlAbstract
2118
{
2219
/**
23-
* @var QuoteResource
20+
* @var GetMaskedQuoteIdByReservedOrderId
2421
*/
25-
private $quoteResource;
26-
27-
/**
28-
* @var QuoteFactory
29-
*/
30-
private $quoteFactory;
31-
32-
/**
33-
* @var QuoteIdToMaskedQuoteIdInterface
34-
*/
35-
private $quoteIdToMaskedId;
22+
private $getMaskedQuoteIdByReservedOrderId;
3623

3724
/**
3825
* @inheritdoc
3926
*/
4027
protected function setUp()
4128
{
4229
$objectManager = Bootstrap::getObjectManager();
43-
$this->quoteResource = $objectManager->get(QuoteResource::class);
44-
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
45-
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
30+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
4631
}
4732

4833
/**
49-
* @magentoApiDataFixture Magento/Catalog/_files/products.php
34+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
5035
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
5136
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
52-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
5337
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
5438
*/
55-
public function testGetCartWithBillingAddress()
39+
public function testGeSpecifiedBillingAddress()
5640
{
57-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_quote');
58-
$response = $this->graphQlQuery($this->getGetBillingAddressQuery($maskedQuoteId));
41+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
42+
$query = $this->getQuery($maskedQuoteId);
43+
44+
$response = $this->graphQlQuery($query);
45+
self::assertArrayHasKey('cart', $response);
46+
self::assertArrayHasKey('billing_address', $response['cart']);
5947

6048
$expectedBillingAddressData = [
6149
'firstname' => 'John',
@@ -77,41 +65,22 @@ public function testGetCartWithBillingAddress()
7765
'telephone' => '3468676',
7866
'address_type' => 'BILLING',
7967
];
80-
8168
self::assertEquals($expectedBillingAddressData, $response['cart']['billing_address']);
8269
}
8370

8471
/**
85-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
86-
* @magentoApiDataFixture Magento/Catalog/_files/products.php
87-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
88-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
89-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
90-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
91-
*/
92-
public function testGetBillingAddressFromAnotherCustomerCart()
93-
{
94-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_quote');
95-
$query = $this->getGetBillingAddressQuery($maskedQuoteId);
96-
97-
$this->expectExceptionMessage(
98-
"The current user cannot perform operations on cart \"$maskedQuoteId\""
99-
);
100-
101-
$this->graphQlQuery($query);
102-
}
103-
104-
/**
105-
* @magentoApiDataFixture Magento/Catalog/_files/products.php
72+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
10673
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
10774
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
108-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
10975
*/
110-
public function testGetBillingAddressIfBillingAddressIsNotSet()
76+
public function testGeSpecifiedBillingAddressIfBillingAddressIsNotSet()
11177
{
112-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_quote');
113-
$query = $this->getGetBillingAddressQuery($maskedQuoteId);
78+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
79+
$query = $this->getQuery($maskedQuoteId);
80+
11481
$response = $this->graphQlQuery($query);
82+
self::assertArrayHasKey('cart', $response);
83+
self::assertArrayHasKey('billing_address', $response['cart']);
11584

11685
$expectedBillingAddressData = [
11786
'firstname' => null,
@@ -133,7 +102,6 @@ public function testGetBillingAddressIfBillingAddressIsNotSet()
133102
'telephone' => null,
134103
'address_type' => 'BILLING',
135104
];
136-
137105
self::assertEquals($expectedBillingAddressData, $response['cart']['billing_address']);
138106
}
139107

@@ -144,17 +112,34 @@ public function testGetBillingAddressIfBillingAddressIsNotSet()
144112
public function testGetBillingAddressOfNonExistentCart()
145113
{
146114
$maskedQuoteId = 'non_existent_masked_id';
147-
$query = $this->getGetBillingAddressQuery($maskedQuoteId);
115+
$query = $this->getQuery($maskedQuoteId);
116+
$this->graphQlQuery($query);
117+
}
118+
119+
/**
120+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
121+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
122+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
123+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
124+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
125+
*/
126+
public function testGetBillingAddressFromAnotherCustomerCart()
127+
{
128+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
129+
$query = $this->getQuery($maskedQuoteId);
130+
131+
$this->expectExceptionMessage(
132+
"The current user cannot perform operations on cart \"$maskedQuoteId\""
133+
);
148134
$this->graphQlQuery($query);
149135
}
150136

151137
/**
152138
* @param string $maskedQuoteId
153139
* @return string
154140
*/
155-
private function getGetBillingAddressQuery(
156-
string $maskedQuoteId
157-
): string {
141+
private function getQuery(string $maskedQuoteId): string
142+
{
158143
return <<<QUERY
159144
{
160145
cart(cart_id: "$maskedQuoteId") {
@@ -182,16 +167,4 @@ private function getGetBillingAddressQuery(
182167
}
183168
QUERY;
184169
}
185-
186-
/**
187-
* @param string $reservedOrderId
188-
* @return string
189-
*/
190-
private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string
191-
{
192-
$quote = $this->quoteFactory->create();
193-
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
194-
195-
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
196-
}
197170
}

0 commit comments

Comments
 (0)