@@ -73,7 +73,7 @@ public function testAddSimpleProductWithOptions()
73
73
json_encode ($ itemOptions )
74
74
);
75
75
76
- $ query = $ this ->getQuery ($ maskedQuoteId , $ qty , $ sku , trim ($ productOptionsQuery , '{} ' ));
76
+ $ query = $ this ->getAddToCartMutation ($ maskedQuoteId , $ qty , $ sku , trim ($ productOptionsQuery , '{} ' ));
77
77
$ response = $ this ->graphQlMutation ($ query );
78
78
79
79
self ::assertArrayHasKey ('items ' , $ response ['addProductsToCart ' ]['cart ' ]);
@@ -109,7 +109,7 @@ public function testAddProductWithWrongSku(string $sku, string $message)
109
109
{
110
110
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
111
111
112
- $ query = $ this ->getQuery ($ maskedQuoteId , 1 , $ sku , '' );
112
+ $ query = $ this ->getAddToCartMutation ($ maskedQuoteId , 1 , $ sku , '' );
113
113
$ response = $ this ->graphQlMutation ($ query );
114
114
115
115
self ::assertArrayHasKey ('userInputErrors ' , $ response ['addProductsToCart ' ]);
@@ -120,6 +120,34 @@ public function testAddProductWithWrongSku(string $sku, string $message)
120
120
);
121
121
}
122
122
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
+
123
151
/**
124
152
* @param int $quantity
125
153
* @param string $message
@@ -134,7 +162,7 @@ public function testAddProductWithWrongQuantity(int $quantity, string $message)
134
162
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
135
163
$ sku = 'simple-2 ' ;
136
164
137
- $ query = $ this ->getQuery ($ maskedQuoteId , $ quantity , $ sku , '' );
165
+ $ query = $ this ->getAddToCartMutation ($ maskedQuoteId , $ quantity , $ sku , '' );
138
166
$ response = $ this ->graphQlMutation ($ query );
139
167
self ::assertArrayHasKey ('userInputErrors ' , $ response ['addProductsToCart ' ]);
140
168
self ::assertCount (1 , $ response ['addProductsToCart ' ]['userInputErrors ' ]);
@@ -188,7 +216,7 @@ public function wrongQuantityDataProvider(): array
188
216
* @param string $customizableOptions
189
217
* @return string
190
218
*/
191
- private function getQuery (
219
+ private function getAddToCartMutation (
192
220
string $ maskedQuoteId ,
193
221
int $ qty ,
194
222
string $ sku ,
@@ -207,6 +235,7 @@ private function getQuery(
207
235
]
208
236
) {
209
237
cart {
238
+ total_quantity
210
239
items {
211
240
quantity
212
241
... on SimpleCartItem {
@@ -227,4 +256,14 @@ private function getQuery(
227
256
}
228
257
MUTATION ;
229
258
}
259
+
260
+ private function getCartQuery (string $ maskedQuoteId )
261
+ {
262
+ return <<<QUERY
263
+ {
264
+ cart(cart_id: " {$ maskedQuoteId }") {
265
+ total_quantity
266
+ }
267
+ QUERY ;
268
+ }
230
269
}
0 commit comments