Skip to content

Commit 9d489a5

Browse files
committed
magento/graphql-ce#283: [Shipping methods] Support of FedEx shipping method
1 parent dfa3331 commit 9d489a5

File tree

4 files changed

+77
-42
lines changed

4 files changed

+77
-42
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/FedEx/SetFedExShippingMethodsOnCartTest.php

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,91 +7,109 @@
77

88
namespace Magento\GraphQl\FedEx;
99

10+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
11+
use Magento\GraphQl\Quote\GetQuoteShippingAddressIdByReservedQuoteId;
1012
use Magento\Integration\Api\CustomerTokenServiceInterface;
11-
use Magento\Quote\Model\QuoteFactory;
12-
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
13-
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1413
use Magento\TestFramework\Helper\Bootstrap;
1514
use Magento\TestFramework\TestCase\GraphQlAbstract;
1615

1716
/**
1817
* Test for setting "FedEx" shipping method on cart
18+
* | Code | Label
19+
* --------------------------------------
20+
* | FEDEX_GROUND | Ground
1921
*/
2022
class SetFedExShippingMethodsOnCartTest extends GraphQlAbstract
2123
{
2224
/**
23-
* Defines carrier code for "FedEx" shipping method
24-
*/
25-
const CARRIER_CODE = 'fedex';
26-
27-
/**
28-
* Defines method code for the "Ground" FedEx shipping
25+
* Defines carrier label for "FedEx" shipping method
2926
*/
30-
const CARRIER_METHOD_CODE_GROUND = 'FEDEX_GROUND';
27+
const CARRIER_LABEL = 'Federal Express';
3128

3229
/**
33-
* @var QuoteFactory
30+
* Defines carrier code for "FedEx" shipping method
3431
*/
35-
private $quoteFactory;
32+
const CARRIER_CODE = 'fedex';
3633

3734
/**
3835
* @var CustomerTokenServiceInterface
3936
*/
4037
private $customerTokenService;
4138

4239
/**
43-
* @var QuoteResource
40+
* @var GetMaskedQuoteIdByReservedOrderId
4441
*/
45-
private $quoteResource;
42+
private $getMaskedQuoteIdByReservedOrderId;
4643

4744
/**
48-
* @var QuoteIdToMaskedQuoteIdInterface
45+
* @var GetQuoteShippingAddressIdByReservedQuoteId
4946
*/
50-
private $quoteIdToMaskedId;
47+
private $getQuoteShippingAddressIdByReservedQuoteId;
5148

5249
/**
5350
* @inheritdoc
5451
*/
5552
protected function setUp()
5653
{
5754
$objectManager = Bootstrap::getObjectManager();
58-
$this->quoteResource = $objectManager->get(QuoteResource::class);
59-
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
60-
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
6155
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
56+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
57+
$this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get(
58+
GetQuoteShippingAddressIdByReservedQuoteId::class
59+
);
6260
}
6361

6462
/**
6563
* @magentoApiDataFixture Magento/Customer/_files/customer.php
66-
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
64+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
65+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_weight_to_simple_product.php
6766
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
6867
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
6968
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
70-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
71-
* @magentoApiDataFixture Magento/Fedex/_files/enable_fedex_shipping_method.php
69+
* @magentoApiDataFixture Magento/GraphQl/FedEx/_files/enable_fedex_shipping_method.php
70+
*
71+
* @dataProvider dataProviderShippingMethods
72+
* @param string $methodCode
73+
* @param string $methodLabel
7274
*/
73-
public function testSetFedExShippingMethod()
75+
public function testSetFedExShippingMethod(string $methodCode, string $methodLabel)
7476
{
75-
$quote = $this->quoteFactory->create();
76-
$this->quoteResource->load($quote, 'test_quote', 'reserved_order_id');
77-
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
78-
$shippingAddressId = (int)$quote->getShippingAddress()->getId();
79-
80-
$query = $this->getAddFedExShippingMethodQuery(
81-
$maskedQuoteId,
82-
$shippingAddressId,
83-
self::CARRIER_CODE,
84-
self::CARRIER_METHOD_CODE_GROUND
85-
);
77+
$quoteReservedId = 'test_quote';
78+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
79+
$shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId);
8680

81+
$query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode);
8782
$response = $this->sendRequestWithToken($query);
88-
$addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses'];
89-
$expectedResult = [
90-
'carrier_code' => self::CARRIER_CODE,
91-
'method_code' => self::CARRIER_METHOD_CODE_GROUND,
92-
'label' => 'Federal Express - Ground',
83+
84+
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
85+
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
86+
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);
87+
self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
88+
89+
$shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
90+
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
91+
92+
self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']);
93+
self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']);
94+
95+
self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']);
96+
self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']);
97+
98+
self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']);
99+
self::assertEquals(
100+
self::CARRIER_LABEL . ' - ' . $methodLabel,
101+
$shippingAddress['selected_shipping_method']['label']
102+
);
103+
}
104+
105+
/**
106+
* @return array
107+
*/
108+
public function dataProviderShippingMethods(): array
109+
{
110+
return [
111+
'Ground' => ['FEDEX_GROUND', 'Ground'],
93112
];
94-
self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult);
95113
}
96114

97115
/**
@@ -103,7 +121,7 @@ public function testSetFedExShippingMethod()
103121
* @param string $methodCode
104122
* @return string
105123
*/
106-
private function getAddFedExShippingMethodQuery(
124+
private function getQuery(
107125
string $maskedQuoteId,
108126
int $shippingAddressId,
109127
string $carrierCode,
@@ -147,6 +165,6 @@ private function sendRequestWithToken(string $query): array
147165
$customerToken = $this->customerTokenService->createCustomerAccessToken('[email protected]', 'password');
148166
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
149167

150-
return $this->graphQlQuery($query, [], '', $headerMap);
168+
return $this->graphQlMutation($query, [], '', $headerMap);
151169
}
152170
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
$objectManager = Bootstrap::getObjectManager();
12+
/** @var ProductRepositoryInterface $productRepository */
13+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
14+
15+
$product = $productRepository->get('simple_product');
16+
$product->setWeight(1.0);
17+
$productRepository->save($product);

0 commit comments

Comments
 (0)