Skip to content

Commit 38b106f

Browse files
committed
Merge remote-tracking branch 'origin/540-new-fixture-for-SetUpsShippingMethodsOnCartTest' into 540-new-fixture-for-SetUpsShippingMethodsOnCartTest
2 parents 3d891d3 + 844fc58 commit 38b106f

File tree

1 file changed

+127
-21
lines changed

1 file changed

+127
-21
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php

Lines changed: 127 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
namespace Magento\GraphQl\Ups;
99

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

@@ -20,19 +19,14 @@
2019
class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract
2120
{
2221
/**
23-
* Defines carrier code for "UPS" shipping method
24-
*/
25-
const CARRIER_CODE = 'ups';
26-
27-
/**
28-
* Defines method code for the "Ground" UPS shipping
22+
* Defines carrier label for "UPS" shipping method
2923
*/
30-
const CARRIER_METHOD_CODE_GROUND = 'GND';
24+
const CARRIER_LABEL = 'United Parcel Service';
3125

3226
/**
33-
* @var Quote
27+
* Defines carrier code for "UPS" shipping method
3428
*/
35-
private $quote;
29+
const CARRIER_CODE = 'ups';
3630

3731
/**
3832
* @var CustomerTokenServiceInterface
@@ -44,49 +38,161 @@ class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract
4438
*/
4539
private $getMaskedQuoteIdByReservedOrderId;
4640

41+
/**
42+
* @var GetQuoteShippingAddressIdByReservedQuoteId
43+
*/
44+
private $getQuoteShippingAddressIdByReservedQuoteId;
45+
4746
/**
4847
* @inheritdoc
4948
*/
5049
protected function setUp()
5150
{
5251
$objectManager = Bootstrap::getObjectManager();
53-
$this->quote = $objectManager->create(Quote::class);
5452
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
5553
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
54+
$this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get(GetQuoteShippingAddressIdByReservedQuoteId::class);
5655
}
5756

5857
/**
5958
* @magentoApiDataFixture Magento/Customer/_files/customer.php
60-
* @magentoApiDataFixture Magento/Catalog/_files/products.php
59+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
6160
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
6261
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
6362
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
6463
* @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php
64+
*
65+
* @param string $carrierMethodCode
66+
* @param string $carrierMethodLabel
67+
* @dataProvider availableForCartShippingMethods
6568
*/
66-
public function testSetUpsShippingMethod()
69+
public function testSetAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel)
6770
{
6871
$quoteReservedId = 'test_quote';
6972
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
70-
$quote = $this->quote->load($quoteReservedId, 'reserved_order_id');
71-
$shippingAddressId = (int)$quote->getShippingAddress()->getId();
73+
$shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId);
7274

73-
$query = $this->getAddUpsShippingMethodQuery(
75+
$query = $this->getQuery(
7476
$maskedQuoteId,
7577
$shippingAddressId,
7678
self::CARRIER_CODE,
77-
self::CARRIER_METHOD_CODE_GROUND
79+
$carrierMethodCode
7880
);
7981

8082
$response = $this->sendRequestWithToken($query);
83+
8184
$addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses'];
8285
$expectedResult = [
8386
'carrier_code' => self::CARRIER_CODE,
84-
'method_code' => self::CARRIER_METHOD_CODE_GROUND,
85-
'label' => 'United Parcel Service - Ground',
87+
'method_code' => $carrierMethodCode,
88+
'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel,
8689
];
8790
self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult);
8891
}
8992

93+
/**
94+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
95+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
96+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
97+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
98+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
99+
* @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php
100+
*
101+
* @param string $carrierMethodCode
102+
* @param string $carrierMethodLabel
103+
* @dataProvider notAvailableForCartShippingMethods
104+
*/
105+
public function testSetNotAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel)
106+
{
107+
$quoteReservedId = 'test_quote';
108+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
109+
$shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId);
110+
111+
$query = $this->getQuery(
112+
$maskedQuoteId,
113+
$shippingAddressId,
114+
self::CARRIER_CODE,
115+
$carrierMethodCode
116+
);
117+
118+
$this->expectExceptionMessage(
119+
"GraphQL response contains errors: Carrier with such method not found: " . self::CARRIER_CODE . ", " . $carrierMethodCode
120+
);
121+
122+
$response = $this->sendRequestWithToken($query);
123+
124+
$addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses'];
125+
$expectedResult = [
126+
'carrier_code' => self::CARRIER_CODE,
127+
'method_code' => $carrierMethodCode,
128+
'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel,
129+
];
130+
self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult);
131+
}
132+
133+
/**
134+
* @return array
135+
*/
136+
public function availableForCartShippingMethods(): array
137+
{
138+
$shippingMethods = ['1DM', '1DA', '2DA', '3DS', 'GND'];
139+
140+
return $this->filterShippingMethodsByCodes($shippingMethods);
141+
}
142+
143+
/**
144+
* @return array
145+
*/
146+
public function notAvailableForCartShippingMethods(): array
147+
{
148+
$shippingMethods = ['1DML', '1DAL', '1DAPI', '1DP', '1DPL', '2DM', '2DML', '2DAL', 'GNDCOM', 'GNDRES', 'STD', 'XPR', 'WXS', 'XPRL', 'XDM', 'XDML', 'XPD'];
149+
150+
return $this->filterShippingMethodsByCodes($shippingMethods);
151+
}
152+
153+
/**
154+
* @param array $filter
155+
* @return array
156+
*/
157+
private function filterShippingMethodsByCodes(array $filter):array
158+
{
159+
$result = [];
160+
foreach ($this->getAllUpsShippingMethods() as $shippingMethod) {
161+
if (in_array($shippingMethod[0], $filter)) {
162+
$result[] = $shippingMethod;
163+
}
164+
}
165+
return $result;
166+
}
167+
168+
private function getAllUpsShippingMethods():array
169+
{
170+
return [
171+
['1DM', 'Next Day Air Early AM'],
172+
['1DML', 'Next Day Air Early AM Letter'],
173+
['1DA', 'Next Day Air'],
174+
['1DAL', 'Next Day Air Letter'],
175+
['1DAPI', 'Next Day Air Intra (Puerto Rico)'],
176+
['1DP', 'Next Day Air Saver'],
177+
['1DPL', 'Next Day Air Saver Letter'],
178+
['2DM', '2nd Day Air AM'],
179+
['2DML', '2nd Day Air AM Letter'],
180+
['2DA', '2nd Day Air'],
181+
['2DAL', '2nd Day Air Letter'],
182+
['3DS', '3 Day Select'],
183+
['GND', 'Ground'],
184+
['GNDCOM', 'Ground Commercial'],
185+
['GNDRES', 'Ground Residential'],
186+
['STD', 'Canada Standard'],
187+
['XPR', 'Worldwide Express'],
188+
['WXS', 'Worldwide Express Saver'],
189+
['XPRL', 'Worldwide Express Letter'],
190+
['XDM', 'Worldwide Express Plus'],
191+
['XDML', 'Worldwide Express Plus Letter'],
192+
['XPD', 'Worldwide Expedited'],
193+
];
194+
}
195+
90196
/**
91197
* Generates query for setting the specified shipping method on cart
92198
*
@@ -96,7 +202,7 @@ public function testSetUpsShippingMethod()
96202
* @param string $methodCode
97203
* @return string
98204
*/
99-
private function getAddUpsShippingMethodQuery(
205+
private function getQuery(
100206
string $maskedQuoteId,
101207
int $shippingAddressId,
102208
string $carrierCode,

0 commit comments

Comments
 (0)