Skip to content

Commit 39ade1f

Browse files
added webapi test
1 parent c47a6a2 commit 39ade1f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Exception;
1111
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1212
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
1314
use Magento\TestFramework\TestCase\GraphQlAbstract;
1415

1516
/**
@@ -79,6 +80,30 @@ public function testAddSimpleProductToCart()
7980
self::assertEquals('USD', $rowTotalIncludingTax['currency']);
8081
}
8182

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+
82107
/**
83108
* @expectedException Exception
84109
* @expectedExceptionMessage Required parameter "cart_id" is missing
@@ -191,7 +216,7 @@ public function testAddSimpleProductToCustomerCart()
191216
private function getQuery(string $maskedQuoteId, string $sku, float $quantity): string
192217
{
193218
return <<<QUERY
194-
mutation {
219+
mutation {
195220
addSimpleProductsToCart(
196221
input: {
197222
cart_id: "{$maskedQuoteId}"

0 commit comments

Comments
 (0)