Skip to content

Commit

Permalink
added webapi test
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Charlie committed Mar 12, 2020
1 parent c47a6a2 commit 39ade1f
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Exception;
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
use Magento\TestFramework\TestCase\GraphQlAbstract;

/**
Expand Down Expand Up @@ -79,6 +80,30 @@ public function testAddSimpleProductToCart()
self::assertEquals('USD', $rowTotalIncludingTax['currency']);
}

/**
* Add out of stock product to cart
*
* @@magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @return void
*/
public function testAddProductToCartWithError(): void
{
$disabledProductSku = 'simple3';
$quantity = 2;

$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
$query = $this->getQuery($maskedQuoteId, $disabledProductSku, $quantity);

$this->expectException(ResponseContainsErrorsException::class);
$this->expectExceptionMessage(
'Could not add the product with SKU simple3 to the shopping cart: ' .
'Product that you are trying to add is not available.'
);

$this->graphQlMutation($query);
}

/**
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_id" is missing
Expand Down Expand Up @@ -191,7 +216,7 @@ public function testAddSimpleProductToCustomerCart()
private function getQuery(string $maskedQuoteId, string $sku, float $quantity): string
{
return <<<QUERY
mutation {
mutation {
addSimpleProductsToCart(
input: {
cart_id: "{$maskedQuoteId}"
Expand Down

0 comments on commit 39ade1f

Please sign in to comment.