|
10 | 10 | use Exception;
|
11 | 11 | use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
12 | 12 | use Magento\TestFramework\Helper\Bootstrap;
|
| 13 | +use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException; |
13 | 14 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
14 | 15 |
|
15 | 16 | /**
|
@@ -79,6 +80,30 @@ public function testAddSimpleProductToCart()
|
79 | 80 | self::assertEquals('USD', $rowTotalIncludingTax['currency']);
|
80 | 81 | }
|
81 | 82 |
|
| 83 | + /** |
| 84 | + * Add out of stock product to cart |
| 85 | + * |
| 86 | + * @@magentoApiDataFixture Magento/Catalog/_files/multiple_products.php |
| 87 | + * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php |
| 88 | + * @return void |
| 89 | + */ |
| 90 | + public function testAddProductToCartWithError(): void |
| 91 | + { |
| 92 | + $disabledProductSku = 'simple3'; |
| 93 | + $quantity = 2; |
| 94 | + |
| 95 | + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); |
| 96 | + $query = $this->getQuery($maskedQuoteId, $disabledProductSku, $quantity); |
| 97 | + |
| 98 | + $this->expectException(ResponseContainsErrorsException::class); |
| 99 | + $this->expectExceptionMessage( |
| 100 | + 'Could not add the product with SKU simple3 to the shopping cart: ' . |
| 101 | + 'Product that you are trying to add is not available.' |
| 102 | + ); |
| 103 | + |
| 104 | + $this->graphQlMutation($query); |
| 105 | + } |
| 106 | + |
82 | 107 | /**
|
83 | 108 | * @expectedException Exception
|
84 | 109 | * @expectedExceptionMessage Required parameter "cart_id" is missing
|
@@ -191,7 +216,7 @@ public function testAddSimpleProductToCustomerCart()
|
191 | 216 | private function getQuery(string $maskedQuoteId, string $sku, float $quantity): string
|
192 | 217 | {
|
193 | 218 | return <<<QUERY
|
194 |
| -mutation { |
| 219 | +mutation { |
195 | 220 | addSimpleProductsToCart(
|
196 | 221 | input: {
|
197 | 222 | cart_id: "{$maskedQuoteId}"
|
|
0 commit comments