@@ -263,4 +263,77 @@ public function testGetMyAddress()
263
263
$ requestData = ['cartId ' => $ quote ->getId ()];
264
264
$ this ->assertEquals ($ addressData , $ this ->_webApiCall ($ serviceInfo , $ requestData ));
265
265
}
266
+
267
+ /**
268
+ * Test setting shipping address based on the customer's authentication token.
269
+ *
270
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
271
+ */
272
+ public function testSetMyAddress ()
273
+ {
274
+ // get customer ID token
275
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
276
+ $ customerTokenService = $ this ->objectManager ->create (
277
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
278
+ );
279
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
280
+
281
+ /** @var \Magento\Quote\Model\Quote $quote */
282
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
283
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
284
+
285
+ $ serviceInfo = [
286
+ 'rest ' => [
287
+ 'resourcePath ' => self ::RESOURCE_PATH . 'mine/shipping-address ' ,
288
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST ,
289
+ 'token ' => $ token
290
+ ],
291
+ 'soap ' => [
292
+ 'service ' => self ::SERVICE_NAME ,
293
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
294
+ 'operation ' => self ::SERVICE_NAME . 'Assign ' ,
295
+ 'token ' => $ token
296
+ ],
297
+ ];
298
+
299
+ $ addressData = [
300
+ 'firstname ' => 'John ' ,
301
+ 'lastname ' => 'Smith ' ,
302
+ 'email ' => 'cat@dog.com ' ,
303
+ 'company ' => 'eBay Inc ' ,
304
+ 'street ' => ['Typical Street ' , 'Tiny House 18 ' ],
305
+ 'city ' => 'Big City ' ,
306
+ 'region_id ' => 12 ,
307
+ 'region ' => 'California ' ,
308
+ 'region_code ' => 'CA ' ,
309
+ 'postcode ' => '0985432 ' ,
310
+ 'country_id ' => 'US ' ,
311
+ 'telephone ' => '88776655 ' ,
312
+ 'fax ' => '44332255 ' ,
313
+ ];
314
+ $ requestData = [
315
+ "cartId " => $ quote ->getId (),
316
+ 'address ' => $ addressData ,
317
+ ];
318
+
319
+ $ addressId = $ this ->_webApiCall ($ serviceInfo , $ requestData );
320
+
321
+ //reset $quote to reload data
322
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
323
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
324
+ $ address = $ quote ->getShippingAddress ();
325
+ $ address ->getRegionCode ();
326
+ $ savedData = $ address ->getData ();
327
+ $ this ->assertEquals ($ addressId , $ savedData ['address_id ' ], 'Invalid address ID ' );
328
+ $ this ->assertEquals (0 , $ savedData ['same_as_billing ' ]);
329
+ //custom checks for street, region and address_type
330
+ $ this ->assertEquals ($ addressData ['street ' ], $ quote ->getShippingAddress ()->getStreet ());
331
+ unset($ addressData ['street ' ]);
332
+
333
+ $ this ->assertEquals ('shipping ' , $ savedData ['address_type ' ]);
334
+ //check the rest of fields
335
+ foreach ($ addressData as $ key => $ value ) {
336
+ $ this ->assertEquals ($ value , $ savedData [$ key ], 'Invalid value for ' . $ key );
337
+ }
338
+ }
266
339
}
0 commit comments