This repository was archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
GraphQl-439: Improve coverage for mutation addSimpleProductToCart or Cart contains a product after product got status Out of Stock #475
Closed
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
76b25c2
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 9bb2932
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 6df7a81
GraphQl-439: Improve coverage for mutation addSimpleProductToCart or …
XxXgeoXxX 09c7897
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 9fd75e9
GraphQl-439: Improve coverage for mutation addSimpleProductToCart or …
XxXgeoXxX f9a5784
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 58cfea5
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 20f0d55
Delete mypatch.patch
XxXgeoXxX 9664559
Delete Fix_the_special_price_expression.patch
XxXgeoXxX 74ddb92
Delete AddProductToCartTest.php
XxXgeoXxX 24b0339
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 5234a6d
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 0431ed2
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 198ba53
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX ce3af88
Merge branch '2.3-develop' of github.com:magento/magento2 into 2.3-de…
XxXgeoXxX fcfc435
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 3f63007
Merge branch '2.3-develop' of github.com:magento/magento2 into 2.3-de…
XxXgeoXxX 1a5675b
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 66f42b0
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 304eae3
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 5f38def
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX d4419da
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX a98f4e2
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX 24697ea
Improve coverage for mutation addSimpleProductToCart or Cart contains…
XxXgeoXxX abec8b4
Merge remote-tracking branch 'origin/2.3-develop' into 2.3-develop#439
TomashKhamlai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/code/Magento/QuoteGraphQl/Model/Resolver/CartMessages.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Quote\Model\Quote; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class CartMessages implements ResolverInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
if (!isset($value['model'])) { | ||
throw new LocalizedException(__('"model" value should be specified')); | ||
} | ||
$cart = $value['model']; | ||
if (empty($cart->getData('has_error'))) { | ||
return []; | ||
} | ||
return $this->getCartErrors($cart); | ||
} | ||
|
||
/** | ||
* Collecting cart errors | ||
* | ||
* @param Quote $cart | ||
* @return array | ||
*/ | ||
private function getCartErrors(Quote $cart): array | ||
{ | ||
$errorMessages = []; | ||
|
||
/** @var AbstractMessage $error */ | ||
foreach ($cart->getMessages() as $idettifier => $error) { | ||
$errorMessages[] = [ | ||
'identifier' => $idettifier, | ||
'text' => $error->getText() | ||
]; | ||
} | ||
|
||
return $errorMessages; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CartMessagesTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Quote; | ||
|
||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
use Magento\Quote\Model\QuoteFactory; | ||
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; | ||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; | ||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; | ||
use Magento\Integration\Api\CustomerTokenServiceInterface; | ||
|
||
/** | ||
* Class GetCartMessagesTest | ||
* | ||
* @package Magento\GraphQl\Quote | ||
*/ | ||
class CartMessagesTest extends GraphQlAbstract | ||
{ | ||
/** | ||
* @var QuoteResource | ||
*/ | ||
private $quoteResource; | ||
|
||
/** | ||
* @var QuoteFactory | ||
*/ | ||
private $quoteFactory; | ||
|
||
/** | ||
* @var QuoteIdToMaskedQuoteIdInterface | ||
*/ | ||
private $quoteIdToMaskedId; | ||
|
||
/** | ||
* @var GetMaskedQuoteIdByReservedOrderId | ||
*/ | ||
private $getMaskedQuoteIdByReservedOrderId; | ||
|
||
/** | ||
* @var CustomerTokenServiceInterface | ||
*/ | ||
private $customerTokenService; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$this->quoteResource = $objectManager->get(QuoteResource::class); | ||
$this->quoteFactory = $objectManager->get(QuoteFactory::class); | ||
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); | ||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); | ||
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php | ||
*/ | ||
public function testCartWithoutErrors() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteId(); | ||
|
||
$query = $this->getCartMessagesQuery($maskedQuoteId); | ||
$response = $this->graphQlMutation($query); | ||
self::assertEquals([], $response['cart']['messages']); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php | ||
*/ | ||
public function testCartWithOutOfStockProduct() | ||
{ | ||
$reservedOrderId = 'test_quote'; | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId); | ||
|
||
$query = $this->getCartMessagesQuery($maskedQuoteId); | ||
|
||
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap()); | ||
self::assertEquals('Some of the products are out of stock.', $response['cart']['messages'][0]['text']); | ||
} | ||
|
||
/** | ||
* @return string | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function getMaskedQuoteId() : string | ||
{ | ||
$quote = $this->quoteFactory->create(); | ||
$this->quoteResource->load($quote, 'test_order_1', 'reserved_order_id'); | ||
|
||
return $this->quoteIdToMaskedId->execute((int)$quote->getId()); | ||
} | ||
|
||
/** | ||
* @param string $maskedQuoteId | ||
* @return string | ||
*/ | ||
public function getCartMessagesQuery(string $maskedQuoteId): string | ||
{ | ||
return <<<QUERY | ||
{ | ||
cart(cart_id:"{$maskedQuoteId}"){ | ||
messages{ | ||
text | ||
} | ||
} | ||
} | ||
QUERY; | ||
} | ||
|
||
/** | ||
* Retrieve customer authorization headers | ||
* | ||
* @param string $username | ||
* @param string $password | ||
* @return array | ||
* @throws AuthenticationException | ||
*/ | ||
private function getHeaderMap(string $username = '[email protected]', string $password = 'password'): array | ||
{ | ||
$customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password); | ||
$headerMap = ['Authorization' => 'Bearer ' . $customerToken]; | ||
return $headerMap; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't move this logic after error checking.
Now it works as:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes were reverted