Skip to content

Commit

Permalink
ENGCOM-5220: magento#681: [Test coverage] missed or empty "cart_id" i…
Browse files Browse the repository at this point in the history
…n cart operations magento#711
  • Loading branch information
lenaorobei authored Jun 10, 2019
2 parents c9089bf + 2c00485 commit 9d4885b
Show file tree
Hide file tree
Showing 10 changed files with 640 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\GraphQl\Quote\Customer;

use Exception;
use Magento\Framework\Exception\AuthenticationException;
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\Integration\Api\CustomerTokenServiceInterface;
Expand Down Expand Up @@ -53,11 +54,117 @@ public function testAddSimpleProductToCart()
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_id" is missing
*/
public function testAddSimpleProductToCartIfCartIdIsMissed()
{
$query = <<<QUERY
mutation {
addSimpleProductsToCart(
input: {
cart_items: []
}
) {
cart {
items {
id
}
}
}
}
QUERY;

$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_id" is missing
*/
public function testAddSimpleProductToCartIfCartIdIsEmpty()
{
$query = <<<QUERY
mutation {
addSimpleProductsToCart(
input: {
cart_id: "",
cart_items: []
}
) {
cart {
items {
id
}
}
}
}
QUERY;

$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_items" is missing
*/
public function testAddSimpleProductToCartIfCartItemsAreMissed()
{
$query = <<<QUERY
mutation {
addSimpleProductsToCart(
input: {
cart_id: "cart_id"
}
) {
cart {
items {
id
}
}
}
}
QUERY;

$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_items" is missing
*/
public function testAddSimpleProductToCartIfCartItemsAreEmpty()
{
$query = <<<QUERY
mutation {
addSimpleProductsToCart(
input: {
cart_id: "cart_id",
cart_items: []
}
) {
cart {
items {
id
}
}
}
}
QUERY;

$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
*
* @expectedException \Exception
* @expectedException Exception
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
*/
public function testAddProductToNonExistentCart()
Expand All @@ -74,7 +181,7 @@ public function testAddProductToNonExistentCart()
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
*
* @expectedException \Exception
* @expectedException Exception
* @expectedExceptionMessage Could not find a product with SKU "simple_product"
*/
public function testNonExistentProductToCart()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\GraphQl\Quote\Customer;

use Exception;
use Magento\Framework\Exception\AuthenticationException;
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\Integration\Api\CustomerTokenServiceInterface;
Expand Down Expand Up @@ -53,11 +54,117 @@ public function testAddVirtualProductToCart()
self::assertEquals($sku, $response['addVirtualProductsToCart']['cart']['items'][0]['product']['sku']);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_id" is missing
*/
public function testAddVirtualProductToCartIfCartIdIsMissed()
{
$query = <<<QUERY
mutation {
addSimpleProductsToCart(
input: {
cart_items: []
}
) {
cart {
items {
id
}
}
}
}
QUERY;

$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_id" is missing
*/
public function testAddVirtualProductToCartIfCartIdIsEmpty()
{
$query = <<<QUERY
mutation {
addSimpleProductsToCart(
input: {
cart_id: "",
cart_items: []
}
) {
cart {
items {
id
}
}
}
}
QUERY;

$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_items" is missing
*/
public function testAddVirtualProductToCartIfCartItemsAreMissed()
{
$query = <<<QUERY
mutation {
addSimpleProductsToCart(
input: {
cart_id: "cart_id"
}
) {
cart {
items {
id
}
}
}
}
QUERY;

$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_items" is missing
*/
public function testAddVirtualProductToCartIfCartItemsAreEmpty()
{
$query = <<<QUERY
mutation {
addSimpleProductsToCart(
input: {
cart_id: "cart_id",
cart_items: []
}
) {
cart {
items {
id
}
}
}
}
QUERY;

$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/virtual_product.php
*
* @expectedException \Exception
* @expectedException Exception
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
*/
public function testAddVirtualToNonExistentCart()
Expand All @@ -74,7 +181,7 @@ public function testAddVirtualToNonExistentCart()
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
*
* @expectedException \Exception
* @expectedException Exception
* @expectedExceptionMessage Could not find a product with SKU "virtual_product"
*/
public function testNonExistentProductToCart()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\GraphQl\Quote\Customer;

use Exception;
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\Integration\Api\CustomerTokenServiceInterface;
use Magento\TestFramework\Helper\Bootstrap;
Expand Down Expand Up @@ -94,10 +95,41 @@ public function testGetAnotherCustomerCart()
$this->graphQlQuery($query, [], '', $this->getHeaderMap('customer2@search.example.com'));
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_id" is missing
*/
public function testGetCartIfCartIdIsEmpty()
{
$maskedQuoteId = '';
$query = $this->getQuery($maskedQuoteId);

$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Field "cart" argument "cart_id" of type "String!" is required but not provided.
*/
public function testGetCartIfCartIdIsMissed()
{
$query = <<<QUERY
{
cart {
email
}
}
QUERY;

$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*
* @expectedException \Exception
* @expectedException Exception
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
*/
public function testGetNonExistentCart()
Expand All @@ -113,7 +145,7 @@ public function testGetNonExistentCart()
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/make_cart_inactive.php
*
* @expectedException \Exception
* @expectedException Exception
* @expectedExceptionMessage Current user does not have an active cart.
*/
public function testGetInactiveCart()
Expand Down Expand Up @@ -145,7 +177,7 @@ public function testGetCartWithNotDefaultStore()
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
* @magentoApiDataFixture Magento/Store/_files/second_store.php
*
* @expectedException \Exception
* @expectedException Exception
* @expectedExceptionMessage Wrong store code specified for cart
*/
public function testGetCartWithWrongStore()
Expand All @@ -162,7 +194,7 @@ public function testGetCartWithWrongStore()
/**
* @magentoApiDataFixture Magento/Checkout/_files/active_quote_customer_not_default_store.php
*
* @expectedException \Exception
* @expectedException Exception
* @expectedExceptionMessage Requested store is not found
*/
public function testGetCartWithNotExistingStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\GraphQl\Quote\Customer;

use Exception;
use Magento\Framework\Registry;
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\Integration\Api\CustomerTokenServiceInterface;
Expand Down Expand Up @@ -83,6 +84,39 @@ public function testPlaceOrder()
self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_id']);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_id" is missing
*/
public function testPlaceOrderIfCartIdIsEmpty()
{
$maskedQuoteId = '';
$query = $this->getQuery($maskedQuoteId);

$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException Exception
* @expectedExceptionMessage Required parameter "cart_id" is missing
*/
public function testPlaceOrderIfCartIdIsMissed()
{
$query = <<<QUERY
mutation {
placeOrder(input: {}) {
order {
order_id
}
}
}
QUERY;

$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
Expand Down
Loading

0 comments on commit 9d4885b

Please sign in to comment.