-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added setting shipping method on cart test coverage concept
- Loading branch information
Showing
1 changed file
with
120 additions
and
0 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/SetShippingMethodOnCartTest.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,120 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Quote; | ||
|
||
use Magento\Integration\Api\CustomerTokenServiceInterface; | ||
use Magento\Quote\Model\Quote; | ||
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; | ||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
/** | ||
* Test for setting shipping methods on cart | ||
*/ | ||
class SetShippingMethodOnCartTest extends GraphQlAbstract | ||
{ | ||
/** | ||
* @var CustomerTokenServiceInterface | ||
*/ | ||
private $customerTokenService; | ||
|
||
/** | ||
* @var QuoteResource | ||
*/ | ||
private $quoteResource; | ||
|
||
/** | ||
* @var Quote | ||
*/ | ||
private $quote; | ||
|
||
/** | ||
* @var QuoteIdToMaskedQuoteIdInterface | ||
*/ | ||
private $quoteIdToMaskedId; | ||
|
||
protected function setUp() | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$this->quoteResource = $objectManager->create(QuoteResource::class); | ||
$this->quote = $objectManager->create(Quote::class); | ||
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class); | ||
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php | ||
*/ | ||
public function testSetShippingOnCart() | ||
{ | ||
$this->quoteResource->load( | ||
$this->quote, | ||
'test_order_1', | ||
'reserved_order_id' | ||
); | ||
|
||
$shippingAddress = $this->quote->getShippingAddress(); | ||
$shippingAddressId = $shippingAddress->getId(); | ||
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId()); | ||
$query = <<<QUERY | ||
mutation { | ||
setShippingMethodsOnCart(input: | ||
{ | ||
cart_id: "$maskedQuoteId", | ||
shipping_methods: [ | ||
{ | ||
shipping_method_code: "flatrate" | ||
shipping_carrier_code: "flatrate" | ||
cart_address_id: $shippingAddressId | ||
} | ||
]}) { | ||
cart { | ||
cart_id, | ||
addresses { | ||
firstname | ||
lastname | ||
company | ||
address_type | ||
city | ||
street | ||
region { | ||
code | ||
label | ||
} | ||
postcode | ||
country { | ||
code | ||
label | ||
} | ||
selected_shipping_method { | ||
code | ||
label | ||
} | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
|
||
$customerToken = $this->customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); | ||
$headerMap = ['Authorization' => 'Bearer ' . $customerToken]; | ||
$response = $this->graphQlQuery($query, [], '', $headerMap); | ||
|
||
self::assertArrayHasKey('setShippingMethodsOnCart', $response); | ||
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']); | ||
self::assertEquals($maskedQuoteId, $response['setShippingMethodsOnCart']['cart']['cart_id']); | ||
|
||
// TODO: check shipping method code and description | ||
} | ||
|
||
// TODO: cover all other cases | ||
} |