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

Commit

Permalink
#607: Refactored tests for creating empty cart by guests
Browse files Browse the repository at this point in the history
  • Loading branch information
Harniuk Bohdan committed Apr 16, 2019
1 parent 4dd5005 commit 53b5341
Showing 1 changed file with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\TestFramework\TestCase\GraphQlAbstract;
use Magento\Quote\Api\GuestCartRepositoryInterface;
use Magento\Framework\Math\Random as RandomDataGenerator;
use Magento\Framework\Exception\LocalizedException;

/**
* Test for empty cart creation mutation
Expand Down Expand Up @@ -105,19 +106,11 @@ public function testCreateEmptyCartWithNotDefaultStore()
public function testCreateEmptyCartWithCartId()
{
$uniqueHash = $this->randomDataGenerator->getUniqueHash();

$query = <<<QUERY
mutation {
createEmptyCart(
input : {
cart_id : "$uniqueHash"
}
)
}
QUERY;
$query = $this->getQueryWithCartId('cart_id : "' . $uniqueHash . '"');
$response = $this->graphQlMutation($query);

self::assertArrayHasKey('createEmptyCart', $response);
self::assertNotEmpty($response['createEmptyCart']);

$maskedCartId = $response['createEmptyCart'];
$guestCart = $this->guestCartRepository->get($maskedCartId);
Expand All @@ -137,15 +130,7 @@ public function testValidateCreateEmptyCartWithSpecifiedCartId(string $input, st
$input = str_replace('provide_non_unique_id', $this->addEmptyCartWithCartId(), $input);
$input = str_replace('provide_hash_with_prefix', $this->randomDataGenerator->getUniqueHash('prefix'), $input);

$query = <<<QUERY
mutation {
createEmptyCart(
input : {
{$input}
}
)
}
QUERY;
$query = $this->getQueryWithCartId($input);

$this->expectExceptionMessage($message);
$this->graphQlMutation($query);
Expand All @@ -163,6 +148,23 @@ private function getQuery(): string
QUERY;
}

/**
* @param string $input
* @return string
*/
private function getQueryWithCartId(string $input): string
{
return <<<QUERY
mutation {
createEmptyCart(
input : {
{$input}
}
)
}
QUERY;
}

public function tearDown()
{
if (null !== $this->maskedQuoteId) {
Expand All @@ -183,21 +185,12 @@ public function tearDown()
* Return masked id for created empty cart.
*
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
private function addEmptyCartWithCartId()
{
$uniqueHash = $this->randomDataGenerator->getUniqueHash();

$query = <<<QUERY
mutation {
createEmptyCart(
input : {
cart_id : "$uniqueHash"
}
)
}
QUERY;
$query = $this->getQueryWithCartId('cart_id : "' . $uniqueHash . '"');
$response = $this->graphQlMutation($query);

return $response['createEmptyCart'];
Expand Down

0 comments on commit 53b5341

Please sign in to comment.