Skip to content

Commit 354fcbd

Browse files
committed
Added test case for adding available QTY + 1
1 parent bf83c7f commit 354fcbd

File tree

2 files changed

+43
-119
lines changed

2 files changed

+43
-119
lines changed

dev/tests/api-functional/phpunit_graphql.xml.dist

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

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testAddSimpleProductWithOptions()
7373
json_encode($itemOptions)
7474
);
7575

76-
$query = $this->getQuery($maskedQuoteId, $qty, $sku, trim($productOptionsQuery, '{}'));
76+
$query = $this->getAddToCartMutation($maskedQuoteId, $qty, $sku, trim($productOptionsQuery, '{}'));
7777
$response = $this->graphQlMutation($query);
7878

7979
self::assertArrayHasKey('items', $response['addProductsToCart']['cart']);
@@ -109,7 +109,7 @@ public function testAddProductWithWrongSku(string $sku, string $message)
109109
{
110110
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
111111

112-
$query = $this->getQuery($maskedQuoteId, 1, $sku, '');
112+
$query = $this->getAddToCartMutation($maskedQuoteId, 1, $sku, '');
113113
$response = $this->graphQlMutation($query);
114114

115115
self::assertArrayHasKey('userInputErrors', $response['addProductsToCart']);
@@ -120,6 +120,34 @@ public function testAddProductWithWrongSku(string $sku, string $message)
120120
);
121121
}
122122

123+
/**
124+
* The test covers the case when upon adding available_qty + 1 to the shopping cart, the cart is being
125+
* cleared
126+
*
127+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_without_custom_options.php
128+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
129+
*/
130+
public function testAddToCartWithQtyPlusOne()
131+
{
132+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
133+
$sku = 'simple-2';
134+
135+
$query = $this->getAddToCartMutation($maskedQuoteId, 100, $sku, '');
136+
$response = $this->graphQlMutation($query);
137+
138+
self::assertEquals(100, $response['addProductsToCart']['cart']['total_quantity']);
139+
140+
$query = $this->getAddToCartMutation($maskedQuoteId, 1, $sku, '');
141+
$response = $this->graphQlMutation($query);
142+
143+
self::assertArrayHasKey('userInputErrors', $response['addProductsToCart']);
144+
self::assertEquals(
145+
'The requested qty is not available',
146+
$response['addProductsToCart']['userInputErrors'][0]['message']
147+
);
148+
self::assertEquals(100, $response['addProductsToCart']['cart']['total_quantity']);
149+
}
150+
123151
/**
124152
* @param int $quantity
125153
* @param string $message
@@ -134,7 +162,7 @@ public function testAddProductWithWrongQuantity(int $quantity, string $message)
134162
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
135163
$sku = 'simple-2';
136164

137-
$query = $this->getQuery($maskedQuoteId, $quantity, $sku, '');
165+
$query = $this->getAddToCartMutation($maskedQuoteId, $quantity, $sku, '');
138166
$response = $this->graphQlMutation($query);
139167
self::assertArrayHasKey('userInputErrors', $response['addProductsToCart']);
140168
self::assertCount(1, $response['addProductsToCart']['userInputErrors']);
@@ -188,7 +216,7 @@ public function wrongQuantityDataProvider(): array
188216
* @param string $customizableOptions
189217
* @return string
190218
*/
191-
private function getQuery(
219+
private function getAddToCartMutation(
192220
string $maskedQuoteId,
193221
int $qty,
194222
string $sku,
@@ -207,6 +235,7 @@ private function getQuery(
207235
]
208236
) {
209237
cart {
238+
total_quantity
210239
items {
211240
quantity
212241
... on SimpleCartItem {
@@ -227,4 +256,14 @@ private function getQuery(
227256
}
228257
MUTATION;
229258
}
259+
260+
private function getCartQuery(string $maskedQuoteId)
261+
{
262+
return <<<QUERY
263+
{
264+
cart(cart_id: "{$maskedQuoteId}") {
265+
total_quantity
266+
}
267+
QUERY;
268+
}
230269
}

0 commit comments

Comments
 (0)