Skip to content

Commit 810780b

Browse files
authored
Merge pull request #4039 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
2 parents abd84ea + 1834026 commit 810780b

16 files changed

+912
-270
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php

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

88
namespace Magento\GraphQl\CatalogInventory;
99

10+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1011
use Magento\TestFramework\Helper\Bootstrap;
1112
use Magento\TestFramework\TestCase\GraphQlAbstract;
12-
use Magento\Quote\Model\QuoteFactory;
13-
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
14-
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1513

1614
/**
17-
* Test for adding products to cart
15+
* Add simple product to cart testcases related to inventory
1816
*/
1917
class AddProductToCartTest extends GraphQlAbstract
2018
{
2119
/**
22-
* @var QuoteResource
20+
* @var GetMaskedQuoteIdByReservedOrderId
2321
*/
24-
private $quoteResource;
25-
26-
/**
27-
* @var QuoteFactory
28-
*/
29-
private $quoteFactory;
30-
31-
/**
32-
* @var QuoteIdToMaskedQuoteIdInterface
33-
*/
34-
private $quoteIdToMaskedId;
22+
private $getMaskedQuoteIdByReservedOrderId;
3523

3624
/**
3725
* @inheritdoc
3826
*/
3927
protected function setUp()
4028
{
4129
$objectManager = Bootstrap::getObjectManager();
42-
$this->quoteResource = $objectManager->get(QuoteResource::class);
43-
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
44-
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
30+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
4531
}
4632

4733
/**
@@ -54,11 +40,10 @@ public function testAddProductIfQuantityIsNotAvailable()
5440
{
5541
$sku = 'simple';
5642
$qty = 200;
43+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
5744

58-
$maskedQuoteId = $this->getMaskedQuoteId();
59-
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
45+
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
6046
$this->graphQlMutation($query);
61-
self::fail('Should be "The requested qty is not available" error message.');
6247
}
6348

6449
/**
@@ -74,22 +59,26 @@ public function testAddMoreProductsThatAllowed()
7459

7560
$sku = 'custom-design-simple-product';
7661
$qty = 7;
62+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
7763

78-
$maskedQuoteId = $this->getMaskedQuoteId();
79-
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
64+
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
8065
$this->graphQlMutation($query);
81-
self::fail('Should be "The most you may purchase is 5." error message.');
8266
}
8367

8468
/**
85-
* @return string
69+
* @magentoApiDataFixture Magento/Catalog/_files/products.php
70+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
71+
* @expectedException \Exception
72+
* @expectedExceptionMessage Please enter a number greater than 0 in this field.
8673
*/
87-
public function getMaskedQuoteId() : string
74+
public function testAddSimpleProductToCartWithNegativeQty()
8875
{
89-
$quote = $this->quoteFactory->create();
90-
$this->quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
76+
$sku = 'simple';
77+
$qty = -2;
78+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
9179

92-
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
80+
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
81+
$this->graphQlMutation($query);
9382
}
9483

9584
/**
@@ -98,7 +87,7 @@ public function getMaskedQuoteId() : string
9887
* @param int $qty
9988
* @return string
10089
*/
101-
public function getAddSimpleProductQuery(string $maskedQuoteId, string $sku, int $qty) : string
90+
private function getQuery(string $maskedQuoteId, string $sku, int $qty) : string
10291
{
10392
return <<<QUERY
10493
mutation {

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddConfigurableProductToCartTest.php renamed to dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,29 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\GraphQl\Quote;
8+
namespace Magento\GraphQl\ConfigurableProduct;
99

10+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1011
use Magento\TestFramework\Helper\Bootstrap;
1112
use Magento\TestFramework\TestCase\GraphQlAbstract;
12-
use Magento\Quote\Model\Quote;
13-
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
14-
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1513

1614
/**
17-
* Add configurable product to cart tests
15+
* Add configurable product to cart testcases
1816
*/
1917
class AddConfigurableProductToCartTest extends GraphQlAbstract
2018
{
2119
/**
22-
* @var QuoteResource
20+
* @var GetMaskedQuoteIdByReservedOrderId
2321
*/
24-
private $quoteResource;
25-
26-
/**
27-
* @var Quote
28-
*/
29-
private $quote;
30-
31-
/**
32-
* @var QuoteIdToMaskedQuoteIdInterface
33-
*/
34-
private $quoteIdToMaskedId;
22+
private $getMaskedQuoteIdByReservedOrderId;
3523

3624
/**
3725
* @inheritdoc
3826
*/
3927
protected function setUp()
4028
{
4129
$objectManager = Bootstrap::getObjectManager();
42-
$this->quoteResource = $objectManager->get(QuoteResource::class);
43-
$this->quote = $objectManager->create(Quote::class);
44-
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
30+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
4531
}
4632

4733
/**
@@ -52,12 +38,11 @@ public function testAddConfigurableProductToCart()
5238
{
5339
$variantSku = 'simple_41';
5440
$qty = 2;
41+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
5542

56-
$maskedQuoteId = $this->getMaskedQuoteId();
57-
58-
$query = $this->getAddConfigurableProductMutationQuery($maskedQuoteId, $variantSku, $qty);
59-
43+
$query = $this->getQuery($maskedQuoteId, $variantSku, $qty);
6044
$response = $this->graphQlMutation($query);
45+
6146
$cartItems = $response['addConfigurableProductsToCart']['cart']['items'];
6247
self::assertEquals($qty, $cartItems[0]['qty']);
6348
self::assertEquals($variantSku, $cartItems[0]['product']['sku']);
@@ -73,10 +58,9 @@ public function testAddProductIfQuantityIsNotAvailable()
7358
{
7459
$variantSku = 'simple_41';
7560
$qty = 200;
61+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
7662

77-
$maskedQuoteId = $this->getMaskedQuoteId();
78-
$query = $this->getAddConfigurableProductMutationQuery($maskedQuoteId, $variantSku, $qty);
79-
63+
$query = $this->getQuery($maskedQuoteId, $variantSku, $qty);
8064
$this->graphQlMutation($query);
8165
}
8266

@@ -90,35 +74,19 @@ public function testAddOutOfStockProduct()
9074
{
9175
$variantSku = 'simple_1010';
9276
$qty = 1;
93-
$maskedQuoteId = $this->getMaskedQuoteId();
94-
$query = $this->getAddConfigurableProductMutationQuery($maskedQuoteId, $variantSku, $qty);
77+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
9578

79+
$query = $this->getQuery($maskedQuoteId, $variantSku, $qty);
9680
$this->graphQlMutation($query);
9781
}
9882

99-
/**
100-
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
101-
* @return string
102-
* @throws \Magento\Framework\Exception\NoSuchEntityException
103-
*/
104-
private function getMaskedQuoteId()
105-
{
106-
$this->quoteResource->load(
107-
$this->quote,
108-
'test_order_1',
109-
'reserved_order_id'
110-
);
111-
return $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
112-
}
113-
11483
/**
11584
* @param string $maskedQuoteId
116-
* @param string $sku
85+
* @param string $variantSku
11786
* @param int $qty
118-
*
11987
* @return string
12088
*/
121-
private function getAddConfigurableProductMutationQuery(string $maskedQuoteId, string $variantSku, int $qty): string
89+
private function getQuery(string $maskedQuoteId, string $variantSku, int $qty): string
12290
{
12391
return <<<QUERY
12492
mutation {

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

Lines changed: 0 additions & 166 deletions
This file was deleted.

0 commit comments

Comments
 (0)