Skip to content

Commit 7257401

Browse files
committed
GraphQL-432: Test coverage: 'reversed quote id to masked cart id'
1 parent 8c6e649 commit 7257401

13 files changed

+154
-197
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
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

@@ -25,29 +23,17 @@ class GetAvailablePaymentMethodsTest extends GraphQlAbstract
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

@@ -56,7 +42,7 @@ protected function setUp()
5642
*/
5743
public function testGetCartWithPaymentMethods()
5844
{
59-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items');
45+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items');
6046
$query = $this->getQuery($maskedQuoteId);
6147
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
6248

@@ -76,7 +62,7 @@ public function testGetCartWithPaymentMethods()
7662
*/
7763
public function testGetPaymentMethodsFromGuestCart()
7864
{
79-
$guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId(
65+
$guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId->execute(
8066
'test_order_with_virtual_product_without_address'
8167
);
8268
$query = $this->getQuery($guestQuoteMaskedId);
@@ -93,7 +79,7 @@ public function testGetPaymentMethodsFromGuestCart()
9379
*/
9480
public function testGetPaymentMethodsFromAnotherCustomerCart()
9581
{
96-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items');
82+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items');
9783
$query = $this->getQuery($maskedQuoteId);
9884

9985
$this->expectExceptionMessage(
@@ -108,7 +94,7 @@ public function testGetPaymentMethodsFromAnotherCustomerCart()
10894
*/
10995
public function testGetPaymentMethodsIfPaymentsAreNotSet()
11096
{
111-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items');
97+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items');
11298
$query = $this->getQuery($maskedQuoteId);
11399
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
114100

@@ -158,16 +144,4 @@ private function getHeaderMap(string $username = 'customer@example.com', string
158144
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
159145
return $headerMap;
160146
}
161-
162-
/**
163-
* @param string $reservedOrderId
164-
* @return string
165-
*/
166-
private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string
167-
{
168-
$quote = $this->quoteFactory->create();
169-
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
170-
171-
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
172-
}
173147
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php

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

88
namespace Magento\GraphQl\Quote\Customer;
99

10+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1011
use Magento\Integration\Api\CustomerTokenServiceInterface;
1112
use Magento\Quote\Model\QuoteFactory;
1213
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
@@ -19,6 +20,11 @@
1920
*/
2021
class GetCartTest extends GraphQlAbstract
2122
{
23+
/**
24+
* @var GetMaskedQuoteIdByReservedOrderId
25+
*/
26+
private $getMaskedQuoteIdByReservedOrderId;
27+
2228
/**
2329
* @var QuoteResource
2430
*/
@@ -42,6 +48,7 @@ class GetCartTest extends GraphQlAbstract
4248
protected function setUp()
4349
{
4450
$objectManager = Bootstrap::getObjectManager();
51+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
4552
$this->quoteResource = $objectManager->get(QuoteResource::class);
4653
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
4754
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
@@ -53,7 +60,7 @@ protected function setUp()
5360
*/
5461
public function testGetCart()
5562
{
56-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items');
63+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items');
5764
$query = $this->getCartQuery($maskedQuoteId);
5865

5966
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
@@ -77,7 +84,9 @@ public function testGetCart()
7784
*/
7885
public function testGetGuestCart()
7986
{
80-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address');
87+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute(
88+
'test_order_with_simple_product_without_address'
89+
);
8190
$query = $this->getCartQuery($maskedQuoteId);
8291

8392
$this->expectExceptionMessage(
@@ -92,7 +101,7 @@ public function testGetGuestCart()
92101
*/
93102
public function testGetAnotherCustomerCart()
94103
{
95-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items');
104+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_item_with_items');
96105
$query = $this->getCartQuery($maskedQuoteId);
97106

98107
$this->expectExceptionMessage(
@@ -156,18 +165,6 @@ private function getCartQuery(
156165
QUERY;
157166
}
158167

159-
/**
160-
* @param string $reversedQuoteId
161-
* @return string
162-
*/
163-
private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string
164-
{
165-
$quote = $this->quoteFactory->create();
166-
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id');
167-
168-
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
169-
}
170-
171168
/**
172169
* @param string $username
173170
* @param string $password

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php

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

88
namespace Magento\GraphQl\Quote\Customer;
99

10+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1011
use Magento\Integration\Api\CustomerTokenServiceInterface;
11-
use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId;
1212
use Magento\Quote\Model\QuoteFactory;
1313
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1414
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
@@ -21,9 +21,9 @@
2121
class SetBillingAddressOnCartTest extends GraphQlAbstract
2222
{
2323
/**
24-
* @var GetMaskedQuoteIdByReversedQuoteId
24+
* @var GetMaskedQuoteIdByReservedOrderId
2525
*/
26-
private $getMaskedQuoteIdByReversedQuoteId;
26+
private $getMaskedQuoteIdByReservedOrderId;
2727

2828
/**
2929
* @var QuoteResource
@@ -48,7 +48,7 @@ class SetBillingAddressOnCartTest extends GraphQlAbstract
4848
protected function setUp()
4949
{
5050
$objectManager = Bootstrap::getObjectManager();
51-
$this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class);
51+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
5252
$this->quoteResource = $objectManager->get(QuoteResource::class);
5353
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
5454
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
@@ -314,12 +314,12 @@ public function testSetNewBillingAddressAndFromAddressBookAtSameTime()
314314
* @magentoApiDataFixture Magento/Customer/_files/customer.php
315315
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
316316
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
317-
* @throws \Exception
318-
* @throws \Magento\Framework\Exception\NoSuchEntityException
319317
*/
320318
public function testSetBillingAddressToGuestCart()
321319
{
322-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address');
320+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute(
321+
'test_order_with_simple_product_without_address'
322+
);
323323

324324
$query = <<<QUERY
325325
mutation {
@@ -489,16 +489,16 @@ private function getHeaderMap(string $username = 'customer@example.com', string
489489
}
490490

491491
/**
492-
* @param string $reversedQuoteId
492+
* @param string $reversedOrderId
493493
* @param int $customerId
494494
* @return string
495495
*/
496496
private function assignQuoteToCustomer(
497-
string $reversedQuoteId = 'test_order_with_simple_product_without_address',
497+
string $reversedOrderId = 'test_order_with_simple_product_without_address',
498498
int $customerId = 1
499499
): string {
500500
$quote = $this->quoteFactory->create();
501-
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id');
501+
$this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id');
502502
$quote->setCustomerId($customerId);
503503
$this->quoteResource->save($quote);
504504
return $this->quoteIdToMaskedId->execute((int)$quote->getId());

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetPaymentMethodOnCartTest.php

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace Magento\GraphQl\Quote\Customer;
99

10+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1011
use Magento\Integration\Api\CustomerTokenServiceInterface;
1112
use Magento\OfflinePayments\Model\Checkmo;
12-
use Magento\QuoteGraphQl\Model\GetMaskedQuoteIdByReversedQuoteId;
1313
use Magento\Quote\Model\QuoteFactory;
1414
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1515
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
@@ -22,14 +22,14 @@
2222
class SetPaymentMethodOnCartTest extends GraphQlAbstract
2323
{
2424
/**
25-
* @var CustomerTokenServiceInterface
25+
* @var GetMaskedQuoteIdByReservedOrderId
2626
*/
27-
private $customerTokenService;
27+
private $getMaskedQuoteIdByReservedOrderId;
2828

2929
/**
30-
* @var GetMaskedQuoteIdByReversedQuoteId
30+
* @var CustomerTokenServiceInterface
3131
*/
32-
private $getMaskedQuoteIdByReversedQuoteId;
32+
private $customerTokenService;
3333

3434
/**
3535
* @var QuoteResource
@@ -52,7 +52,7 @@ class SetPaymentMethodOnCartTest extends GraphQlAbstract
5252
protected function setUp()
5353
{
5454
$objectManager = Bootstrap::getObjectManager();
55-
$this->getMaskedQuoteIdByReversedQuoteId = $objectManager->get(GetMaskedQuoteIdByReversedQuoteId::class);
55+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
5656
$this->quoteResource = $objectManager->get(QuoteResource::class);
5757
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
5858
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
@@ -61,13 +61,11 @@ protected function setUp()
6161

6262
/**
6363
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
64-
* @throws \Exception
65-
* @throws \Magento\Framework\Exception\NoSuchEntityException
6664
*/
6765
public function testSetPaymentWithVirtualProduct()
6866
{
6967
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
70-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_virtual_product');
68+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_with_virtual_product');
7169

7270
$query = $this->prepareMutationQuery($maskedQuoteId, $methodCode);
7371
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
@@ -80,13 +78,11 @@ public function testSetPaymentWithVirtualProduct()
8078

8179
/**
8280
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
83-
* @throws \Exception
84-
* @throws \Magento\Framework\Exception\NoSuchEntityException
8581
*/
8682
public function testSetPaymentWithSimpleProduct()
8783
{
8884
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
89-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1');
85+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
9086

9187
$query = $this->prepareMutationQuery($maskedQuoteId, $methodCode);
9288
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
@@ -120,7 +116,7 @@ public function testSetPaymentWithSimpleProductWithoutAddress()
120116
public function testSetNonExistingPaymentMethod()
121117
{
122118
$methodCode = 'noway';
123-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1');
119+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
124120

125121
$query = $this->prepareMutationQuery($maskedQuoteId, $methodCode);
126122
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
@@ -129,13 +125,13 @@ public function testSetNonExistingPaymentMethod()
129125
/**
130126
* @magentoApiDataFixture Magento/Customer/_files/customer.php
131127
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
132-
* @throws \Exception
133-
* @throws \Magento\Framework\Exception\NoSuchEntityException
134128
*/
135129
public function testSetPaymentMethodToGuestCart()
136130
{
137131
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
138-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_with_simple_product_without_address');
132+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute(
133+
'test_order_with_simple_product_without_address'
134+
);
139135

140136
$query = $this->prepareMutationQuery($maskedQuoteId, $methodCode);
141137

@@ -149,13 +145,11 @@ public function testSetPaymentMethodToGuestCart()
149145
/**
150146
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
151147
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
152-
* @throws \Exception
153-
* @throws \Magento\Framework\Exception\NoSuchEntityException
154148
*/
155149
public function testSetPaymentMethodToAnotherCustomerCart()
156150
{
157151
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
158-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId->execute('test_order_1');
152+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
159153

160154
$query = $this->prepareMutationQuery($maskedQuoteId, $methodCode);
161155

@@ -192,7 +186,7 @@ public function testPaymentMethodOnNonExistentCart()
192186
public function testReSetPayment()
193187
{
194188
/** @var \Magento\Quote\Model\Quote $quote */
195-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1_with_payment');
189+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1_with_payment');
196190
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
197191
$query = $this->prepareMutationQuery($maskedQuoteId, $methodCode);
198192
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
@@ -231,16 +225,16 @@ private function prepareMutationQuery(
231225
}
232226

233227
/**
234-
* @param string $reversedQuoteId
228+
* @param string $reversedOrderId
235229
* @param int $customerId
236230
* @return string
237231
*/
238232
private function assignQuoteToCustomer(
239-
string $reversedQuoteId,
233+
string $reversedOrderId,
240234
int $customerId
241235
): string {
242236
$quote = $this->quoteFactory->create();
243-
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id');
237+
$this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id');
244238
$quote->setCustomerId($customerId);
245239
$this->quoteResource->save($quote);
246240
return $this->quoteIdToMaskedId->execute((int)$quote->getId());

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,16 +513,16 @@ private function getHeaderMap(string $username = 'customer@example.com', string
513513
}
514514

515515
/**
516-
* @param string $reversedQuoteId
516+
* @param string $reversedOrderId
517517
* @param int $customerId
518518
* @return string
519519
*/
520520
private function assignQuoteToCustomer(
521-
string $reversedQuoteId = 'test_order_with_simple_product_without_address',
521+
string $reversedOrderId = 'test_order_with_simple_product_without_address',
522522
int $customerId = 1
523523
): string {
524524
$quote = $this->quoteFactory->create();
525-
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id');
525+
$this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id');
526526
$quote->setCustomerId($customerId);
527527
$this->quoteResource->save($quote);
528528
return $this->quoteIdToMaskedId->execute((int)$quote->getId());

0 commit comments

Comments
 (0)