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 156
Add API Test For Selected Shipping Method functionality #491
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4f19d03
Corrected Mutation Query for SetShippingMethodsOnCartTest
yogeshsuhagiya 43f5bce
Covered all the cases of SetShippingMethod for Guest
yogeshsuhagiya 4bdc30e
Fixed issue of undefined variable: objectManager
yogeshsuhagiya f9ecace
Renamed variable and keep name length under 20.
yogeshsuhagiya 60d40e1
Add API Test For Selected Shipping Method functionality #478
06romix f01dc00
Merge remote-tracking branch 'origin/2.3-develop' into 2.3-develop-gr…
naydav 16ce046
Removed duplicate case & applied logic fixes
yogeshsuhagiya c2f15b3
Added data Provider
yogeshsuhagiya 14d5c3d
Merge remote-tracking branch 'yogeshsuhagiya/2.3-develop-graphql-PR-y…
naydav 2643424
Merge remote-tracking branch 'origin/2.3-develop' into 2.3-develop-gr…
naydav cf4eb72
Merge remote-tracking branch 'origin/2.3-develop' into 2.3-develop-gr…
naydav 829a39b
GraphQL-422: Test coverage: SetShippingMethodsOnCartTest for Guest
naydav d0f3920
Merge remote-tracking branch 'origin/2.3-develop' into issue-478
naydav 2ceceb7
Merge branch '2.3-develop-graphql-PR-yogesh-5' into issue-478
naydav 84a21a4
GraphQL-478: [Test Coverage] 'Selected Shipping Method' functionality
naydav 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
223 changes: 223 additions & 0 deletions
223
...ts/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SelectedShippingMethodTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Quote\Customer; | ||
|
||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
class SelectedShippingMethodTest extends GraphQlAbstract | ||
{ | ||
/** | ||
* @var \Magento\TestFramework\ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var \Magento\Framework\Api\SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @var \Magento\Framework\Api\SortOrderBuilder | ||
*/ | ||
private $sortOrderBuilder; | ||
|
||
/** | ||
* @var \Magento\Framework\Api\FilterBuilder | ||
*/ | ||
private $filterBuilder; | ||
|
||
/** | ||
* @var \Magento\Quote\Model\ResourceModel\Quote | ||
*/ | ||
private $quoteResource; | ||
|
||
/** | ||
* @var \Magento\Quote\Model\QuoteFactory | ||
*/ | ||
private $quoteFactory; | ||
|
||
/** | ||
* @var \Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface | ||
*/ | ||
private $quoteIdToMaskedId; | ||
|
||
/** | ||
* @var \Magento\Integration\Api\CustomerTokenServiceInterface | ||
*/ | ||
private $customerTokenService; | ||
|
||
/** | ||
* @param $response | ||
* @return mixed | ||
*/ | ||
public function getSelectedShippingMethod($response) | ||
{ | ||
return $response['cart']['shipping_addresses'][0]['selected_shipping_method']; | ||
} | ||
|
||
protected function setUp() | ||
{ | ||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
|
||
$this->filterBuilder = $this->objectManager->create( | ||
\Magento\Framework\Api\FilterBuilder::class | ||
); | ||
$this->sortOrderBuilder = $this->objectManager->create( | ||
\Magento\Framework\Api\SortOrderBuilder::class | ||
); | ||
$this->searchCriteriaBuilder = $this->objectManager->create( | ||
\Magento\Framework\Api\SearchCriteriaBuilder::class | ||
); | ||
$this->quoteResource = $this->objectManager->get( | ||
\Magento\Quote\Model\ResourceModel\Quote::class | ||
); | ||
$this->quoteFactory = $this->objectManager->get( | ||
\Magento\Quote\Model\QuoteFactory::class | ||
); | ||
$this->quoteIdToMaskedId = $this->objectManager->get( | ||
\Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface::class | ||
); | ||
$this->customerTokenService = $this->objectManager->get( | ||
\Magento\Integration\Api\CustomerTokenServiceInterface::class | ||
); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php | ||
*/ | ||
public function testGetCartWithShippingMethod() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('cart', $response); | ||
self::assertInternalType( | ||
'array', | ||
$response['cart']['shipping_addresses'][0]['selected_shipping_method'], | ||
'There are no selected shipping method for customer cart!' | ||
); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php | ||
*/ | ||
public function testGetShippingMethodFromCustomerCart() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('cart', $response); | ||
|
||
$selectedShippingMethod = $this->getSelectedShippingMethod($response); | ||
|
||
self::assertEquals('flatrate', $selectedShippingMethod['carrier_code']); | ||
self::assertEquals('flatrate', $selectedShippingMethod['method_code']); | ||
self::assertEquals('Flat Rate - Fixed', $selectedShippingMethod['label']); | ||
self::assertEquals(0, $selectedShippingMethod['amount']); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address.php | ||
*/ | ||
public function testGetShippingMethodIfShippingMethodIsNotSet() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
||
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('cart', $response); | ||
|
||
$selectedShippingMethod = $this->getSelectedShippingMethod($response); | ||
|
||
self::assertNull($selectedShippingMethod['carrier_code']); | ||
self::assertNull($selectedShippingMethod['method_code']); | ||
self::assertNull($selectedShippingMethod['label']); | ||
self::assertNull($selectedShippingMethod['amount']); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address.php | ||
*/ | ||
public function testGetShippingMethodOfNonExistentCart() | ||
{ | ||
$query = $this->getQuery('nonExistentCart'); | ||
self::expectException(\Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException::class); | ||
self::expectExceptionMessage( | ||
'GraphQL response contains errors: Could not find a cart with ID "nonExistentCart"' | ||
); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
} | ||
|
||
/** | ||
* Retrieve quote by given reserved order ID | ||
* | ||
* @param string $reservedOrderId | ||
* @return \Magento\Quote\Model\Quote | ||
* @throws \InvalidArgumentException | ||
*/ | ||
protected function getCart($reservedOrderId) | ||
{ | ||
/** @var $cart \Magento\Quote\Model\Quote */ | ||
$cart = $this->objectManager->get(\Magento\Quote\Model\Quote::class); | ||
$cart->load($reservedOrderId, 'reserved_order_id'); | ||
if (!$cart->getId()) { | ||
throw new \InvalidArgumentException('There is no quote with provided reserved order ID.'); | ||
} | ||
return $cart; | ||
} | ||
|
||
/** | ||
* @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()); | ||
} | ||
|
||
/** | ||
* @param string $username | ||
* @param string $password | ||
* @return array | ||
*/ | ||
private function getHeaderMap(string $username = 'customer@example.com', string $password = 'password'): array | ||
{ | ||
$customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password); | ||
$headerMap = ['Authorization' => 'Bearer ' . $customerToken]; | ||
return $headerMap; | ||
} | ||
|
||
/** | ||
* @param string $maskedQuoteId | ||
* @return string | ||
*/ | ||
private function getQuery( | ||
string $maskedQuoteId | ||
): string { | ||
return <<<QUERY | ||
{ | ||
cart(cart_id: "$maskedQuoteId") { | ||
shipping_addresses { | ||
selected_shipping_method { | ||
carrier_code | ||
method_code | ||
label | ||
amount | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
} | ||
} |
Oops, something went wrong.
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.
Please, clear all of not used dependencies