Skip to content

Commit 9de77c9

Browse files
committed
MCP-606: [MCP-584] Fix failed Web API tests
- Fix failed and add new tests;
1 parent 1f62d95 commit 9de77c9

File tree

4 files changed

+191
-0
lines changed

4 files changed

+191
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public function testPlaceOrderWithNoPaymentMethod()
203203
}
204204

205205
/**
206+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 1
206207
* @magentoApiDataFixture Magento/Customer/_files/customer.php
207208
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
208209
* @magentoConfigFixture default_store carriers/flatrate/active 1
@@ -225,6 +226,30 @@ public function testPlaceOrderWithOutOfStockProduct()
225226
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
226227
}
227228

229+
/**
230+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
231+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
232+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
233+
* @magentoConfigFixture default_store carriers/flatrate/active 1
234+
* @magentoConfigFixture default_store carriers/tablerate/active 1
235+
* @magentoConfigFixture default_store carriers/freeshipping/active 1
236+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
237+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
238+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
239+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
240+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
241+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
242+
*/
243+
public function testPlaceOrderWithOutOfStockProductWithDisabledInventoryCheck()
244+
{
245+
$reservedOrderId = 'test_quote';
246+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
247+
$query = $this->getQuery($maskedQuoteId);
248+
249+
self::expectExceptionMessage('Unable to place order: Enter a valid payment method and try again.');
250+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
251+
}
252+
228253
/**
229254
* _security
230255
* @magentoApiDataFixture Magento/Customer/_files/customer.php

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function testSetPaymentOnCartWithSimpleProduct()
8989
}
9090

9191
/**
92+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 1
9293
* @magentoApiDataFixture Magento/Customer/_files/customer.php
9394
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
9495
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
@@ -126,6 +127,45 @@ public function testSetPaymentOnCartWithException(string $input, string $message
126127
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
127128
}
128129

130+
/**
131+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
132+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
133+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
134+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
135+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
136+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
137+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
138+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
139+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
140+
*
141+
* @dataProvider dataProviderSetPaymentOnCartWithExceptionWithDisabledInventoryCheck
142+
* @param string $input
143+
* @param string $message
144+
* @throws \Exception
145+
*/
146+
public function testSetPaymentOnCartWithExceptionWithDisabledInventoryCheck(string $input, string $message)
147+
{
148+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
149+
$input = str_replace('cart_id_value', $maskedQuoteId, $input);
150+
151+
$query = <<<QUERY
152+
mutation {
153+
setPaymentMethodAndPlaceOrder(
154+
input: {
155+
{$input}
156+
}
157+
) {
158+
order {
159+
order_number
160+
}
161+
}
162+
}
163+
QUERY;
164+
165+
$this->expectExceptionMessage($message);
166+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
167+
}
168+
129169
/**
130170
* @return array
131171
*/
@@ -142,6 +182,22 @@ public function dataProviderSetPaymentOnCartWithException(): array
142182
];
143183
}
144184

185+
/**
186+
* @return array
187+
*/
188+
public function dataProviderSetPaymentOnCartWithExceptionWithDisabledInventoryCheck(): array
189+
{
190+
return [
191+
'place_order_with_out_of_stock_products' => [
192+
'cart_id: "cart_id_value"
193+
payment_method: {
194+
code: "' . Checkmo::PAYMENT_METHOD_CHECKMO_CODE . '"
195+
}',
196+
'Unable to place order: There are no source items with the in stock status',
197+
],
198+
];
199+
}
200+
145201
/**
146202
* @magentoApiDataFixture Magento/Customer/_files/customer.php
147203
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public function testAddDisabledProductToCart(): void
206206
/**
207207
* Add out of stock product to cart
208208
*
209+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 1
209210
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
210211
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
211212
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
@@ -230,6 +231,90 @@ public function testAddOutOfStockProductToCart(): void
230231
$this->graphQlMutation($query);
231232
}
232233

234+
/**
235+
* Add out of stock product to cart with disabled quote item check
236+
*
237+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
238+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
239+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
240+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
241+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
242+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
243+
* @return void
244+
* @throws NoSuchEntityException
245+
*/
246+
public function testAddOutOfStockProductToCartWithDisabledInventoryCheck(): void
247+
{
248+
$sku = 'simple1';
249+
$quantity = 1;
250+
251+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
252+
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
253+
$response = $this->graphQlMutation($query);
254+
255+
$this->assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
256+
$this->assertCount(2, $response['addSimpleProductsToCart']['cart']['items']);
257+
$cartItems = $response['addSimpleProductsToCart']['cart']['items'];
258+
$this->assertEquals(2, $cartItems[0]['quantity']);
259+
$this->assertEquals(1, $cartItems[1]['quantity']);
260+
}
261+
262+
/**
263+
* Add out of stock simple product to cart with disabled quote item check
264+
*
265+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 1
266+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
267+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
268+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
269+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
270+
* @return void
271+
* @throws NoSuchEntityException
272+
*/
273+
public function testAddOutOfStockSimpleProductToCart(): void
274+
{
275+
$sku = 'simple_product';
276+
$quantity = 1;
277+
278+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
279+
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
280+
281+
$this->expectException(ResponseContainsErrorsException::class);
282+
$this->expectExceptionMessage(
283+
'Could not add the product with SKU ' . $sku . ' to the shopping cart: ' .
284+
'Product that you are trying to add is not available.'
285+
);
286+
287+
$this->graphQlMutation($query);
288+
}
289+
290+
/**
291+
* Add out of stock simple product to cart with disabled quote item check
292+
*
293+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
294+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
295+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
296+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
297+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
298+
* @return void
299+
* @throws NoSuchEntityException
300+
*/
301+
public function testAddOutOfStockSimpleProductToCartWithDisabledInventoryCheck(): void
302+
{
303+
$sku = 'simple_product';
304+
$quantity = 1;
305+
306+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
307+
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
308+
309+
$this->expectException(ResponseContainsErrorsException::class);
310+
$this->expectExceptionMessage(
311+
'Could not add the product with SKU ' . $sku . ' to the shopping cart: ' .
312+
'Product that you are trying to add is not available.'
313+
);
314+
315+
$this->graphQlMutation($query);
316+
}
317+
233318
/**
234319
*/
235320
public function testAddSimpleProductToCartIfCartIdIsEmpty()

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ public function testPlaceOrderWithNoPaymentMethod()
276276
}
277277

278278
/**
279+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 1
279280
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
280281
* @magentoConfigFixture default_store carriers/flatrate/active 1
281282
* @magentoConfigFixture default_store carriers/tablerate/active 1
@@ -298,6 +299,30 @@ public function testPlaceOrderWithOutOfStockProduct()
298299
$this->graphQlMutation($query);
299300
}
300301

302+
/**
303+
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
304+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
305+
* @magentoConfigFixture default_store carriers/flatrate/active 1
306+
* @magentoConfigFixture default_store carriers/tablerate/active 1
307+
* @magentoConfigFixture default_store carriers/freeshipping/active 1
308+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
309+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
310+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
311+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
312+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
313+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
314+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
315+
*/
316+
public function testPlaceOrderWithOutOfStockProductWithDisabledInventoryCheck()
317+
{
318+
$reservedOrderId = 'test_quote';
319+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
320+
$query = $this->getQuery($maskedQuoteId);
321+
322+
self::expectExceptionMessage('Unable to place order: Enter a valid payment method and try again.');
323+
$this->graphQlMutation($query);
324+
}
325+
301326
/**
302327
* _security
303328
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php

0 commit comments

Comments
 (0)