@@ -54,6 +54,47 @@ protected function setUp()
54
54
$ this ->getQuoteShippingAddressIdByReservedQuoteId = $ objectManager ->get (GetQuoteShippingAddressIdByReservedQuoteId::class);
55
55
}
56
56
57
+ /**
58
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
59
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
60
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
61
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
62
+ * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php
63
+ *
64
+ * @param string $methodCode
65
+ * @param string $methodLabel
66
+ * @dataProvider availableForCartShippingMethods
67
+ */
68
+ public function testSetAvailableUpsShippingMethodOnCart (string $ methodCode , string $ methodLabel )
69
+ {
70
+ $ quoteReservedId = 'test_quote ' ;
71
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ($ quoteReservedId );
72
+ $ shippingAddressId = $ this ->getQuoteShippingAddressIdByReservedQuoteId ->execute ($ quoteReservedId );
73
+
74
+ $ query = $ this ->getQuery ($ maskedQuoteId , $ shippingAddressId , self ::CARRIER_CODE , $ methodCode );
75
+ $ response = $ this ->graphQlQuery ($ query );
76
+
77
+ self ::assertArrayHasKey ('setShippingMethodsOnCart ' , $ response );
78
+ self ::assertArrayHasKey ('cart ' , $ response ['setShippingMethodsOnCart ' ]);
79
+ self ::assertArrayHasKey ('shipping_addresses ' , $ response ['setShippingMethodsOnCart ' ]['cart ' ]);
80
+ self ::assertCount (1 , $ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ]);
81
+
82
+ $ shippingAddress = current ($ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ]);
83
+ self ::assertArrayHasKey ('selected_shipping_method ' , $ shippingAddress );
84
+
85
+ self ::assertArrayHasKey ('carrier_code ' , $ shippingAddress ['selected_shipping_method ' ]);
86
+ self ::assertEquals (self ::CARRIER_CODE , $ shippingAddress ['selected_shipping_method ' ]['carrier_code ' ]);
87
+
88
+ self ::assertArrayHasKey ('method_code ' , $ shippingAddress ['selected_shipping_method ' ]);
89
+ self ::assertEquals ($ methodCode , $ shippingAddress ['selected_shipping_method ' ]['method_code ' ]);
90
+
91
+ self ::assertArrayHasKey ('label ' , $ shippingAddress ['selected_shipping_method ' ]);
92
+ self ::assertEquals (
93
+ self ::CARRIER_LABEL . ' - ' . $ methodLabel ,
94
+ $ shippingAddress ['selected_shipping_method ' ]['label ' ]
95
+ );
96
+ }
97
+
57
98
/**
58
99
* Set "Next Day Air Early AM" UPS shipping method
59
100
*
@@ -239,9 +280,55 @@ public function testSetGroundUpsShippingMethod()
239
280
self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ], $ expectedResult );
240
281
}
241
282
283
+ /**
284
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
285
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
286
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
287
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
288
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
289
+ * @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php
290
+ *
291
+ * @param string $carrierMethodCode
292
+ * @param string $carrierMethodLabel
293
+ * @dataProvider notAvailableForCartShippingMethods
294
+ */
295
+ public function testSetNotAvailableForCartUpsShippingMethod (string $ carrierMethodCode , string $ carrierMethodLabel )
296
+ {
297
+ $ quoteReservedId = 'test_quote ' ;
298
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ($ quoteReservedId );
299
+ $ shippingAddressId = $ this ->getQuoteShippingAddressIdByReservedQuoteId ->execute ($ quoteReservedId );
300
+
301
+ $ query = $ this ->getQuery (
302
+ $ maskedQuoteId ,
303
+ $ shippingAddressId ,
304
+ self ::CARRIER_CODE ,
305
+ $ carrierMethodCode
306
+ );
307
+
308
+ $ this ->expectExceptionMessage (
309
+ "GraphQL response contains errors: Carrier with such method not found: " . self ::CARRIER_CODE . ", " . $ carrierMethodCode
310
+ );
311
+
312
+ $ response = $ this ->sendRequestWithToken ($ query );
242
313
314
+ $ addressesInformation = $ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ];
315
+ $ expectedResult = [
316
+ 'carrier_code ' => self ::CARRIER_CODE ,
317
+ 'method_code ' => $ carrierMethodCode ,
318
+ 'label ' => self ::CARRIER_LABEL . ' - ' . $ carrierMethodLabel ,
319
+ ];
320
+ self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ], $ expectedResult );
321
+ }
243
322
323
+ /**
324
+ * @return array
325
+ */
326
+ public function availableForCartShippingMethods (): array
327
+ {
328
+ $ shippingMethods = ['1DM ' , '1DA ' , '2DA ' , '3DS ' , 'GND ' ];
244
329
330
+ return $ this ->filterShippingMethodsByCodes ($ shippingMethods );
331
+ }
245
332
246
333
/**
247
334
* @return array
@@ -253,6 +340,21 @@ public function notAvailableForCartShippingMethods(): array
253
340
return $ this ->filterShippingMethodsByCodes ($ shippingMethods );
254
341
}
255
342
343
+ /**
344
+ * @param array $filter
345
+ * @return array
346
+ */
347
+ private function filterShippingMethodsByCodes (array $ filter ):array
348
+ {
349
+ $ result = [];
350
+ foreach ($ this ->getAllUpsShippingMethods () as $ shippingMethod ) {
351
+ if (in_array ($ shippingMethod [0 ], $ filter )) {
352
+ $ result [] = $ shippingMethod ;
353
+ }
354
+ }
355
+ return $ result ;
356
+ }
357
+
256
358
private function getAllUpsShippingMethods ():array
257
359
{
258
360
return [
@@ -334,6 +436,6 @@ private function sendRequestWithToken(string $query): array
334
436
$ customerToken = $ this ->customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
335
437
$ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
336
438
337
- return $ this ->graphQlMutation ($ query , [], '' , $ headerMap );
439
+ return $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
338
440
}
339
441
}
0 commit comments