Skip to content

Commit 1b5991d

Browse files
committed
GraphQL-293: When maxSaleQty is set and qty is more than maxSaleQty the "The most you may purchase is %1." message should be sent instead of "Internal server error"
1 parent b1c6bc2 commit 1b5991d

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,27 @@ public function testAddProductIfQuantityIsNotAvailable()
5555
$maskedQuoteId = $this->getMaskedQuoteId();
5656
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
5757
$this->graphQlQuery($query);
58+
self::fail('Should be "The requested qty is not available" error message.');
5859
}
5960

6061
/**
6162
* @magentoApiDataFixture Magento/Catalog/_files/products.php
6263
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
6364
* @magentoConfigFixture default cataloginventory/item_options/max_sale_qty 5
65+
* @expectedException \Exception
6466
* @expectedExceptionMessage The most you may purchase is 5.
6567
*/
6668
public function testAddMoreProductsThatAllowed()
6769
{
70+
$this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/167');
71+
6872
$sku = 'custom-design-simple-product';
6973
$qty = 7;
7074

7175
$maskedQuoteId = $this->getMaskedQuoteId();
7276
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
7377
$this->graphQlQuery($query);
78+
self::fail('Should be "The most you may purchase is 5." error message.');
7479
}
7580

7681
/**
@@ -108,7 +113,6 @@ public function getAddSimpleProductQuery(string $maskedQuoteId, string $sku, int
108113
}
109114
) {
110115
cart {
111-
cart_id
112116
items {
113117
qty
114118
}

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

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

1010
use Magento\TestFramework\Helper\Bootstrap;
1111
use Magento\TestFramework\TestCase\GraphQlAbstract;
12-
use Magento\Quote\Model\Quote;
12+
use Magento\Quote\Model\QuoteFactory;
1313
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1414
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1515

@@ -21,9 +21,9 @@ class AddSimpleProductToCartTest extends GraphQlAbstract
2121
private $quoteResource;
2222

2323
/**
24-
* @var Quote
24+
* @var QuoteFactory
2525
*/
26-
private $quote;
26+
private $quoteFactory;
2727

2828
/**
2929
* @var QuoteIdToMaskedQuoteIdInterface
@@ -37,29 +37,48 @@ protected function setUp()
3737
{
3838
$objectManager = Bootstrap::getObjectManager();
3939
$this->quoteResource = $objectManager->get(QuoteResource::class);
40-
$this->quote = $objectManager->create(Quote::class);
40+
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
4141
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
4242
}
4343

4444
/**
4545
* @magentoApiDataFixture Magento/Catalog/_files/products.php
4646
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
47-
* @expectedException \Exception
48-
* @expectedExceptionMessage The requested qty is not available
4947
*/
50-
public function testAddProductIfQuantityIsNotAvailable()
48+
public function testAddSimpleProductToCart()
5149
{
5250
$sku = 'simple';
53-
$qty = 200;
51+
$qty = 2;
52+
$maskedQuoteId = $this->getMaskedQuoteId();
5453

55-
$this->quoteResource->load(
56-
$this->quote,
57-
'test_order_1',
58-
'reserved_order_id'
59-
);
60-
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
54+
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
55+
$response = $this->graphQlQuery($query);
56+
self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
6157

62-
$query = <<<QUERY
58+
self::assertEquals($qty, $response['addSimpleProductsToCart']['cart']['items'][0]['qty']);
59+
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
60+
}
61+
62+
/**
63+
* @return string
64+
*/
65+
public function getMaskedQuoteId() : string
66+
{
67+
$quote = $this->quoteFactory->create();
68+
$this->quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
69+
70+
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
71+
}
72+
73+
/**
74+
* @param string $maskedQuoteId
75+
* @param string $sku
76+
* @param int $qty
77+
* @return string
78+
*/
79+
public function getAddSimpleProductQuery(string $maskedQuoteId, string $sku, int $qty): string
80+
{
81+
return <<<QUERY
6382
mutation {
6483
addSimpleProductsToCart(
6584
input: {
@@ -77,12 +96,13 @@ public function testAddProductIfQuantityIsNotAvailable()
7796
cart {
7897
items {
7998
qty
99+
product {
100+
sku
101+
}
80102
}
81103
}
82104
}
83105
}
84106
QUERY;
85-
86-
$this->graphQlQuery($query);
87107
}
88108
}

0 commit comments

Comments
 (0)