Skip to content

Commit

Permalink
Merge pull request #4039 from magento-engcom/graphql-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - GraphQL
  • Loading branch information
naydav authored Apr 12, 2019
2 parents abd84ea + 1834026 commit 810780b
Show file tree
Hide file tree
Showing 16 changed files with 912 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,27 @@

namespace Magento\GraphQl\CatalogInventory;

use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;
use Magento\Quote\Model\QuoteFactory;
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;

/**
* Test for adding products to cart
* Add simple product to cart testcases related to inventory
*/
class AddProductToCartTest extends GraphQlAbstract
{
/**
* @var QuoteResource
* @var GetMaskedQuoteIdByReservedOrderId
*/
private $quoteResource;

/**
* @var QuoteFactory
*/
private $quoteFactory;

/**
* @var QuoteIdToMaskedQuoteIdInterface
*/
private $quoteIdToMaskedId;
private $getMaskedQuoteIdByReservedOrderId;

/**
* @inheritdoc
*/
protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->quoteResource = $objectManager->get(QuoteResource::class);
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
}

/**
Expand All @@ -54,11 +40,10 @@ public function testAddProductIfQuantityIsNotAvailable()
{
$sku = 'simple';
$qty = 200;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

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

/**
Expand All @@ -74,22 +59,26 @@ public function testAddMoreProductsThatAllowed()

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

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

/**
* @return string
* @magentoApiDataFixture Magento/Catalog/_files/products.php
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
* @expectedException \Exception
* @expectedExceptionMessage Please enter a number greater than 0 in this field.
*/
public function getMaskedQuoteId() : string
public function testAddSimpleProductToCartWithNegativeQty()
{
$quote = $this->quoteFactory->create();
$this->quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
$sku = 'simple';
$qty = -2;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

return $this->quoteIdToMaskedId->execute((int)$quote->getId());
$query = $this->getQuery($maskedQuoteId, $sku, $qty);
$this->graphQlMutation($query);
}

/**
Expand All @@ -98,7 +87,7 @@ public function getMaskedQuoteId() : string
* @param int $qty
* @return string
*/
public function getAddSimpleProductQuery(string $maskedQuoteId, string $sku, int $qty) : string
private function getQuery(string $maskedQuoteId, string $sku, int $qty) : string
{
return <<<QUERY
mutation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,29 @@
*/
declare(strict_types=1);

namespace Magento\GraphQl\Quote;
namespace Magento\GraphQl\ConfigurableProduct;

use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;

/**
* Add configurable product to cart tests
* Add configurable product to cart testcases
*/
class AddConfigurableProductToCartTest extends GraphQlAbstract
{
/**
* @var QuoteResource
* @var GetMaskedQuoteIdByReservedOrderId
*/
private $quoteResource;

/**
* @var Quote
*/
private $quote;

/**
* @var QuoteIdToMaskedQuoteIdInterface
*/
private $quoteIdToMaskedId;
private $getMaskedQuoteIdByReservedOrderId;

/**
* @inheritdoc
*/
protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->quoteResource = $objectManager->get(QuoteResource::class);
$this->quote = $objectManager->create(Quote::class);
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
}

/**
Expand All @@ -52,12 +38,11 @@ public function testAddConfigurableProductToCart()
{
$variantSku = 'simple_41';
$qty = 2;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$maskedQuoteId = $this->getMaskedQuoteId();

$query = $this->getAddConfigurableProductMutationQuery($maskedQuoteId, $variantSku, $qty);

$query = $this->getQuery($maskedQuoteId, $variantSku, $qty);
$response = $this->graphQlMutation($query);

$cartItems = $response['addConfigurableProductsToCart']['cart']['items'];
self::assertEquals($qty, $cartItems[0]['qty']);
self::assertEquals($variantSku, $cartItems[0]['product']['sku']);
Expand All @@ -73,10 +58,9 @@ public function testAddProductIfQuantityIsNotAvailable()
{
$variantSku = 'simple_41';
$qty = 200;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$maskedQuoteId = $this->getMaskedQuoteId();
$query = $this->getAddConfigurableProductMutationQuery($maskedQuoteId, $variantSku, $qty);

$query = $this->getQuery($maskedQuoteId, $variantSku, $qty);
$this->graphQlMutation($query);
}

Expand All @@ -90,35 +74,19 @@ public function testAddOutOfStockProduct()
{
$variantSku = 'simple_1010';
$qty = 1;
$maskedQuoteId = $this->getMaskedQuoteId();
$query = $this->getAddConfigurableProductMutationQuery($maskedQuoteId, $variantSku, $qty);
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');

$query = $this->getQuery($maskedQuoteId, $variantSku, $qty);
$this->graphQlMutation($query);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
private function getMaskedQuoteId()
{
$this->quoteResource->load(
$this->quote,
'test_order_1',
'reserved_order_id'
);
return $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
}

/**
* @param string $maskedQuoteId
* @param string $sku
* @param string $variantSku
* @param int $qty
*
* @return string
*/
private function getAddConfigurableProductMutationQuery(string $maskedQuoteId, string $variantSku, int $qty): string
private function getQuery(string $maskedQuoteId, string $variantSku, int $qty): string
{
return <<<QUERY
mutation {
Expand Down

This file was deleted.

Loading

0 comments on commit 810780b

Please sign in to comment.