-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL-428: Test coverage: GetAvailableShippingMethodsTest
- Loading branch information
Showing
6 changed files
with
80 additions
and
97 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,40 +23,32 @@ class GetAvailableShippingMethodsTest extends GraphQlAbstract | |
private $customerTokenService; | ||
|
||
/** | ||
* @var QuoteIdToMaskedQuoteIdInterface | ||
* @var GetMaskedQuoteIdByReservedOrderId | ||
*/ | ||
private $quoteIdToMaskedId; | ||
|
||
/** | ||
* @var QuoteFactory | ||
*/ | ||
private $quoteFactory; | ||
|
||
/** | ||
* @var QuoteResource | ||
*/ | ||
private $quoteResource; | ||
private $getMaskedQuoteIdByReservedOrderId; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$this->quoteFactory = $objectManager->get(QuoteFactory::class); | ||
$this->quoteResource = $objectManager->get(QuoteResource::class); | ||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); | ||
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); | ||
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); | ||
} | ||
|
||
/** | ||
* Test case: get available shipping methods from current customer quote | ||
* | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_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 testGetAvailableShippingMethods() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('cart', $response); | ||
|
@@ -84,40 +74,62 @@ public function testGetAvailableShippingMethods() | |
); | ||
} | ||
|
||
/** | ||
* _security | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.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 testGetAvailableShippingMethodsFromGuestCart() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
||
$this->expectExceptionMessage( | ||
"The current user cannot perform operations on cart \"$maskedQuoteId\"" | ||
); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
} | ||
|
||
/** | ||
* Test case: get available shipping methods from quote of another customer | ||
* | ||
* _security | ||
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_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 testGetAvailableShippingMethodsFromAnotherCustomerCart() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
||
$this->expectExceptionMessage( | ||
"The current user cannot perform operations on cart \"$maskedQuoteId\"" | ||
); | ||
|
||
$this->graphQlQuery( | ||
$this->getQuery($maskedQuoteId), | ||
[], | ||
'', | ||
$this->getHeaderMap('[email protected]') | ||
); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap('[email protected]')); | ||
} | ||
|
||
/** | ||
* Test case: get available shipping methods when all shipping methods are disabled | ||
* | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php | ||
* @magentoApiDataFixture Magento/OfflineShipping/_files/disable_offline_shipping_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_offline_shipping_methods.php | ||
*/ | ||
public function testGetAvailableShippingMethodsIfAllShippingsAreDisabled() | ||
public function testGetAvailableShippingMethodsIfShippingMethodsAreNotPresent() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); | ||
|
||
self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods'])); | ||
self::assertEmpty($response['cart']['shipping_addresses'][0]['available_shipping_methods']); | ||
} | ||
|
||
/** | ||
|
@@ -173,16 +185,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
4 changes: 1 addition & 3 deletions
4
...ntegration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php
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
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
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
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