@@ -117,6 +117,50 @@ public function testSetMethodWithoutShippingAddress()
117
117
$ this ->assertEquals ('Shipping address is not set ' , $ message );
118
118
}
119
119
120
+ /**
121
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
122
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
123
+ */
124
+ public function testSetMethodForMyCart ()
125
+ {
126
+ $ this ->_markTestAsRestOnly ();
127
+
128
+ $ this ->quote ->load ('test_order_1 ' , 'reserved_order_id ' );
129
+
130
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
131
+ $ customerTokenService = $ this ->objectManager ->create (
132
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
133
+ );
134
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
135
+
136
+ $ serviceInfo = [
137
+ 'rest ' => [
138
+ 'resourcePath ' => '/V1/carts/mine/selected-shipping-method ' ,
139
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_PUT ,
140
+ 'token ' => $ token
141
+ ]
142
+ ];
143
+
144
+ $ requestData = [
145
+ 'cartId ' => 999 ,
146
+ 'carrierCode ' => 'flatrate ' ,
147
+ 'methodCode ' => 'flatrate ' ,
148
+ ]; // cartId 999 will be overridden
149
+
150
+ $ result = $ this ->_webApiCall ($ serviceInfo , $ requestData );
151
+ $ this ->assertEquals (true , $ result );
152
+
153
+ /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $ShippingMethodManagementService */
154
+ $ ShippingMethodManagementService = $ this ->objectManager ->create (
155
+ 'Magento\Quote\Api\ShippingMethodManagementInterface '
156
+ );
157
+ $ shippingMethod = $ ShippingMethodManagementService ->get ($ this ->quote ->getId ());
158
+
159
+ $ this ->assertNotNull ($ shippingMethod );
160
+ $ this ->assertEquals ('flatrate ' , $ shippingMethod ->getCarrierCode ());
161
+ $ this ->assertEquals ('flatrate ' , $ shippingMethod ->getMethodCode ());
162
+ }
163
+
120
164
/**
121
165
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php
122
166
*/
@@ -169,6 +213,41 @@ public function testGetMethodOfCartWithNoShippingMethod()
169
213
$ this ->assertEquals ([], $ result );
170
214
}
171
215
216
+ /**
217
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
218
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
219
+ */
220
+ public function testGetMethodForMyCart ()
221
+ {
222
+ $ this ->_markTestAsRestOnly ();
223
+
224
+ $ this ->quote ->load ('test_order_1 ' , 'reserved_order_id ' );
225
+
226
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
227
+ $ customerTokenService = $ this ->objectManager ->create (
228
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
229
+ );
230
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
231
+
232
+ /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagementService */
233
+ $ shippingMethodManagementService = $ this ->objectManager ->create (
234
+ 'Magento\Quote\Api\ShippingMethodManagementInterface '
235
+ );
236
+ $ shippingMethodManagementService ->set ($ this ->quote ->getId (), 'flatrate ' , 'flatrate ' );
237
+
238
+ $ serviceInfo = [
239
+ 'rest ' => [
240
+ 'resourcePath ' => '/V1/carts/mine/selected-shipping-method ' ,
241
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_GET ,
242
+ 'token ' => $ token
243
+ ]
244
+ ];
245
+
246
+ $ result = $ this ->_webApiCall ($ serviceInfo , []);
247
+ $ this ->assertEquals ('flatrate ' , $ result [ShippingMethodInterface::KEY_CARRIER_CODE ]);
248
+ $ this ->assertEquals ('flatrate ' , $ result [ShippingMethodInterface::KEY_METHOD_CODE ]);
249
+ }
250
+
172
251
/**
173
252
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
174
253
*
@@ -204,6 +283,57 @@ public function testGetList()
204
283
$ this ->assertEquals ($ expectedData , $ returnedRates );
205
284
}
206
285
286
+ /**
287
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
288
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
289
+ */
290
+ public function testGetListForMyCart ()
291
+ {
292
+ $ this ->_markTestAsRestOnly ();
293
+
294
+ $ this ->quote ->load ('test_order_1 ' , 'reserved_order_id ' );
295
+
296
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
297
+ $ customerTokenService = $ this ->objectManager ->create (
298
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
299
+ );
300
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
301
+
302
+ /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagementService */
303
+ $ shippingMethodManagementService = $ this ->objectManager ->create (
304
+ 'Magento\Quote\Api\ShippingMethodManagementInterface '
305
+ );
306
+ $ shippingMethodManagementService ->set ($ this ->quote ->getId (), 'flatrate ' , 'flatrate ' );
307
+
308
+ $ serviceInfo = [
309
+ 'rest ' => [
310
+ 'resourcePath ' => '/V1/carts/mine/shipping-methods ' ,
311
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_GET ,
312
+ 'token ' => $ token
313
+ ]
314
+ ];
315
+
316
+ $ result = $ this ->_webApiCall ($ serviceInfo , []);
317
+ $ this ->assertNotEmpty ($ result );
318
+
319
+ /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $ShippingMethodManagementService */
320
+ $ ShippingMethodManagementService = $ this ->objectManager ->create (
321
+ 'Magento\Quote\Api\ShippingMethodManagementInterface '
322
+ );
323
+ $ shippingMethod = $ ShippingMethodManagementService ->get ($ this ->quote ->getId ());
324
+ $ expectedData = [
325
+ ShippingMethodInterface::KEY_CARRIER_CODE => $ shippingMethod ->getCarrierCode (),
326
+ ShippingMethodInterface::KEY_METHOD_CODE => $ shippingMethod ->getMethodCode (),
327
+ ShippingMethodInterface::KEY_CARRIER_TITLE => $ shippingMethod ->getCarrierTitle (),
328
+ ShippingMethodInterface::KEY_METHOD_TITLE => $ shippingMethod ->getMethodTitle (),
329
+ ShippingMethodInterface::KEY_SHIPPING_AMOUNT => $ shippingMethod ->getAmount (),
330
+ ShippingMethodInterface::KEY_BASE_SHIPPING_AMOUNT => $ shippingMethod ->getBaseAmount (),
331
+ ShippingMethodInterface::KEY_AVAILABLE => $ shippingMethod ->getAvailable (),
332
+ ];
333
+
334
+ $ this ->assertEquals ($ expectedData , $ result [0 ]);
335
+ }
336
+
207
337
/**
208
338
* @param string $cartId
209
339
* @return array
0 commit comments