Skip to content

Commit

Permalink
Added setting shipping method on cart test coverage concept
Browse files Browse the repository at this point in the history
  • Loading branch information
rogyar committed Nov 2, 2018
1 parent c98c3d5 commit 936a223
Showing 1 changed file with 120 additions and 0 deletions.
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
}

0 comments on commit 936a223

Please sign in to comment.