Skip to content

Commit

Permalink
Added check, test case and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Usik2203 committed May 20, 2020
1 parent e4d9a05 commit b059e51
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\GiftMessage\Api\CartRepositoryInterface;
use Magento\GiftMessage\Helper\Message as GiftMessageHelper;

/**
* Class provides ability to get GiftMessage for cart
Expand All @@ -27,14 +28,20 @@ class GiftMessage implements ResolverInterface
private $cartRepository;

/**
* GiftMessage constructor.
*
* @var GiftMessageHelper
*/
private $giftMessageHelper;

/**
* @param CartRepositoryInterface $cartRepository
* @param GiftMessageHelper $giftMessageHelper
*/
public function __construct(
CartRepositoryInterface $cartRepository
CartRepositoryInterface $cartRepository,
GiftMessageHelper $giftMessageHelper
) {
$this->cartRepository = $cartRepository;
$this->giftMessageHelper = $giftMessageHelper;
}

/**
Expand All @@ -61,8 +68,13 @@ public function resolve(
if (!isset($value['model'])) {
throw new GraphQlInputException(__('"model" value should be specified'));
}

$cart = $value['model'];

if (!$this->giftMessageHelper->isMessagesAllowed('order', $cart)) {
return null;
}

try {
$giftCartMessage = $this->cartRepository->get($cart->getId());
} catch (LocalizedException $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ class GiftMessageTest extends GraphQlAbstract
*/
private $getMaskedQuoteIdByReservedOrderId;

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

/**
* @magentoConfigFixture default_store sales/gift_options/allow_order 1
* @magentoApiDataFixture Magento/GiftMessage/_files/quote_with_message.php
* @throws NoSuchEntityException
* @throws Exception
Expand All @@ -41,6 +42,20 @@ public function testGiftMessageForCart()
self::assertSame('I thought all for the best.', $response['cart']['gift_message']['message']);
}

/**
* @magentoConfigFixture default_store sales/gift_options/allow_order 0
* @magentoApiDataFixture Magento/GiftMessage/_files/quote_with_message.php
* @throws NoSuchEntityException
* @throws Exception
*/
public function testGiftMessageForCartWithNotAllow()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('message_order_21');
$response = $this->requestCartAndAssertResult($maskedQuoteId);
self::assertArrayHasKey('gift_message', $response['cart']);
self::assertNull($response['cart']['gift_message']);
}

/**
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
Expand Down

0 comments on commit b059e51

Please sign in to comment.