Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
GraphQL-605: [Test coverage] Add simple product to cart
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav committed Apr 17, 2019
1 parent 8afaf80 commit 8c34f6c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class AddSimpleProductToCartTest extends GraphQlAbstract
*/
private $getMaskedQuoteIdByReservedOrderId;

protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
Expand All @@ -49,40 +56,39 @@ public function testAddSimpleProductToCart()
/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
*
* @expectedException \Exception
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
*/
public function testAddProductToNonExistentCart()
{
$sku = 'simple_product';
$qty = 2;
$maskedQuoteId = 'non_existent_masked_id';
$query = $this->getQuery($maskedQuoteId, $sku, $qty);

$this->expectExceptionMessage(
"Could not find a cart with ID \"$maskedQuoteId\""
);

$query = $this->getQuery($maskedQuoteId, $sku, $qty);
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
*
* @expectedException \Exception
* @expectedExceptionMessage Could not find a product with SKU "simple_product"
*/
public function testNonExistentProductToCart()
{
$sku = 'simple_product';
$qty = 2;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
$query = $this->getQuery($maskedQuoteId, $sku, $qty);

$this->expectExceptionMessage(
"Could not find a product with SKU \"simple_product\""
);

$query = $this->getQuery($maskedQuoteId, $sku, $qty);
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
}

/**
* _security
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
Expand All @@ -102,9 +108,10 @@ public function testAddSimpleProductToGuestCart()
}

/**
* _security
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
*/
public function testAddSimpleProductToAnotherCustomerCart()
{
Expand All @@ -120,15 +127,10 @@ public function testAddSimpleProductToAnotherCustomerCart()
$this->graphQlMutation($query, [], '', $this->getHeaderMap('customer2@search.example.com'));
}

protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
}

/**
* @param string $maskedQuoteId
* @param string $sku
* @param int $qty
* @return string
*/
private function getQuery(string $maskedQuoteId, string $sku, int $qty): string
Expand All @@ -140,8 +142,8 @@ private function getQuery(string $maskedQuoteId, string $sku, int $qty): string
cartItems: [
{
data: {
qty: $qty
sku: "$sku"
qty: {$qty}
sku: "{$sku}"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,17 @@ public function testAddProductToNonExistentCart()

/**
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
*
* @expectedException \Exception
* @expectedExceptionMessage Could not find a product with SKU "simple_product"
*/
public function testNonExistentProductToCart()
{
$sku = 'simple_product';
$qty = 1;
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
$query = $this->getQuery($maskedQuoteId, $sku, $qty);

$this->expectExceptionMessage(
"Could not find a product with SKU \"simple_product\""
);

$query = $this->getQuery($maskedQuoteId, $sku, $qty);
$this->graphQlMutation($query);
}

Expand Down

0 comments on commit 8c34f6c

Please sign in to comment.