This repository has been archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/2.3-develop' into 2.3-develop-gr…
…aphql-PR-yogesh-5
- Loading branch information
Showing
29 changed files
with
905 additions
and
659 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -7,10 +7,8 @@ | |
|
||
namespace Magento\GraphQl\Quote\Customer; | ||
|
||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; | ||
use Magento\Integration\Api\CustomerTokenServiceInterface; | ||
use Magento\Quote\Model\QuoteFactory; | ||
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; | ||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
|
@@ -25,75 +23,70 @@ class GetAvailablePaymentMethodsTest extends GraphQlAbstract | |
private $customerTokenService; | ||
|
||
/** | ||
* @var QuoteResource | ||
* @var GetMaskedQuoteIdByReservedOrderId | ||
*/ | ||
private $quoteResource; | ||
|
||
/** | ||
* @var QuoteFactory | ||
*/ | ||
private $quoteFactory; | ||
|
||
/** | ||
* @var QuoteIdToMaskedQuoteIdInterface | ||
*/ | ||
private $quoteIdToMaskedId; | ||
private $getMaskedQuoteIdByReservedOrderId; | ||
|
||
/** | ||
* @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/quote_with_items_saved.php | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php | ||
*/ | ||
public function testGetCartWithPaymentMethods() | ||
public function testGetAvailablePaymentMethods() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('cart', $response); | ||
self::assertArrayHasKey('available_payment_methods', $response['cart']); | ||
|
||
self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); | ||
self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']); | ||
self::assertGreaterThan( | ||
0, | ||
count($response['cart']['available_payment_methods']), | ||
'There are no available payment methods for customer cart!' | ||
); | ||
} | ||
|
||
/** | ||
* _security | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php | ||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php | ||
*/ | ||
public function testGetPaymentMethodsFromGuestCart() | ||
public function testGetAvailablePaymentMethodsFromGuestCart() | ||
{ | ||
$guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId( | ||
'test_order_with_virtual_product_without_address' | ||
); | ||
$query = $this->getQuery($guestQuoteMaskedId); | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
||
$this->expectExceptionMessage( | ||
"The current user cannot perform operations on cart \"$guestQuoteMaskedId\"" | ||
"The current user cannot perform operations on cart \"$maskedQuoteId\"" | ||
); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
} | ||
|
||
/** | ||
* _security | ||
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php | ||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php | ||
*/ | ||
public function testGetPaymentMethodsFromAnotherCustomerCart() | ||
public function testGetAvailablePaymentMethodsFromAnotherCustomerCart() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
||
$this->expectExceptionMessage( | ||
|
@@ -103,24 +96,31 @@ public function testGetPaymentMethodsFromAnotherCustomerCart() | |
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php | ||
* @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/disable_all_active_payment_methods.php | ||
*/ | ||
public function testGetPaymentMethodsIfPaymentsAreNotSet() | ||
public function testGetAvailablePaymentMethodsIfPaymentsAreNotPresent() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertEquals(0, count($response['cart']['available_payment_methods'])); | ||
self::assertArrayHasKey('cart', $response); | ||
self::assertArrayHasKey('available_payment_methods', $response['cart']); | ||
self::assertEmpty($response['cart']['available_payment_methods']); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* | ||
* @expectedException \Exception | ||
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" | ||
*/ | ||
public function testGetPaymentMethodsOfNonExistentCart() | ||
public function testGetAvailablePaymentMethodsOfNonExistentCart() | ||
{ | ||
$maskedQuoteId = 'non_existent_masked_id'; | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
@@ -132,9 +132,8 @@ public function testGetPaymentMethodsOfNonExistentCart() | |
* @param string $maskedQuoteId | ||
* @return string | ||
*/ | ||
private function getQuery( | ||
string $maskedQuoteId | ||
): string { | ||
private function getQuery(string $maskedQuoteId): string | ||
{ | ||
return <<<QUERY | ||
{ | ||
cart(cart_id: "$maskedQuoteId") { | ||
|
@@ -158,16 +157,4 @@ private function getHeaderMap(string $username = '[email protected]', string | |
$headerMap = ['Authorization' => 'Bearer ' . $customerToken]; | ||
return $headerMap; | ||
} | ||
|
||
/** | ||
* @param string $reservedOrderId | ||
* @return string | ||
*/ | ||
private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string | ||
{ | ||
$quote = $this->quoteFactory->create(); | ||
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); | ||
|
||
return $this->quoteIdToMaskedId->execute((int)$quote->getId()); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.