7
7
8
8
namespace Magento \GraphQl \FedEx ;
9
9
10
+ use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
11
+ use Magento \GraphQl \Quote \GetQuoteShippingAddressIdByReservedQuoteId ;
10
12
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 ;
14
13
use Magento \TestFramework \Helper \Bootstrap ;
15
14
use Magento \TestFramework \TestCase \GraphQlAbstract ;
16
15
17
16
/**
18
17
* Test for setting "FedEx" shipping method on cart
18
+ * | Code | Label
19
+ * --------------------------------------
20
+ * | FEDEX_GROUND | Ground
19
21
*/
20
22
class SetFedExShippingMethodsOnCartTest extends GraphQlAbstract
21
23
{
22
24
/**
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
29
26
*/
30
- const CARRIER_METHOD_CODE_GROUND = 'FEDEX_GROUND ' ;
27
+ const CARRIER_LABEL = 'Federal Express ' ;
31
28
32
29
/**
33
- * @var QuoteFactory
30
+ * Defines carrier code for "FedEx" shipping method
34
31
*/
35
- private $ quoteFactory ;
32
+ const CARRIER_CODE = ' fedex ' ;
36
33
37
34
/**
38
35
* @var CustomerTokenServiceInterface
39
36
*/
40
37
private $ customerTokenService ;
41
38
42
39
/**
43
- * @var QuoteResource
40
+ * @var GetMaskedQuoteIdByReservedOrderId
44
41
*/
45
- private $ quoteResource ;
42
+ private $ getMaskedQuoteIdByReservedOrderId ;
46
43
47
44
/**
48
- * @var QuoteIdToMaskedQuoteIdInterface
45
+ * @var GetQuoteShippingAddressIdByReservedQuoteId
49
46
*/
50
- private $ quoteIdToMaskedId ;
47
+ private $ getQuoteShippingAddressIdByReservedQuoteId ;
51
48
52
49
/**
53
50
* @inheritdoc
54
51
*/
55
52
protected function setUp ()
56
53
{
57
54
$ objectManager = Bootstrap::getObjectManager ();
58
- $ this ->quoteResource = $ objectManager ->get (QuoteResource::class);
59
- $ this ->quoteFactory = $ objectManager ->get (QuoteFactory::class);
60
- $ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
61
55
$ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
56
+ $ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
57
+ $ this ->getQuoteShippingAddressIdByReservedQuoteId = $ objectManager ->get (
58
+ GetQuoteShippingAddressIdByReservedQuoteId::class
59
+ );
62
60
}
63
61
64
62
/**
65
63
* @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
67
66
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
68
67
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
69
68
* @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
72
74
*/
73
- public function testSetFedExShippingMethod ()
75
+ public function testSetFedExShippingMethod (string $ methodCode , string $ methodLabel )
74
76
{
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 );
86
80
81
+ $ query = $ this ->getQuery ($ maskedQuoteId , $ shippingAddressId , self ::CARRIER_CODE , $ methodCode );
87
82
$ 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 ' ],
93
112
];
94
- self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ], $ expectedResult );
95
113
}
96
114
97
115
/**
@@ -103,7 +121,7 @@ public function testSetFedExShippingMethod()
103
121
* @param string $methodCode
104
122
* @return string
105
123
*/
106
- private function getAddFedExShippingMethodQuery (
124
+ private function getQuery (
107
125
string $ maskedQuoteId ,
108
126
int $ shippingAddressId ,
109
127
string $ carrierCode ,
@@ -147,6 +165,6 @@ private function sendRequestWithToken(string $query): array
147
165
$ customerToken =
$ this ->
customerTokenService ->
createCustomerAccessToken (
'[email protected] ' ,
'password ' );
148
166
$ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
149
167
150
- return $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
168
+ return $ this ->graphQlMutation ($ query , [], '' , $ headerMap );
151
169
}
152
170
}
0 commit comments