@@ -132,4 +132,130 @@ public function testSetAddress()
132
132
$ this ->assertEquals ($ value , $ savedData [$ key ]);
133
133
}
134
134
}
135
+
136
+ /**
137
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
138
+ */
139
+ public function testGetMyAddress ()
140
+ {
141
+ // get customer ID token
142
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
143
+ $ customerTokenService = $ this ->objectManager ->create (
144
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
145
+ );
146
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
147
+
148
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
149
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
150
+
151
+ /** @var \Magento\Quote\Model\Quote\Address $address */
152
+ $ address = $ quote ->getBillingAddress ();
153
+
154
+ $ data = [
155
+ AddressInterface::KEY_COUNTRY_ID => $ address ->getCountryId (),
156
+ AddressInterface::KEY_ID => (int )$ address ->getId (),
157
+ AddressInterface::KEY_CUSTOMER_ID => $ address ->getCustomerId (),
158
+ AddressInterface::KEY_REGION => $ address ->getRegion (),
159
+ AddressInterface::KEY_REGION_ID => $ address ->getRegionId (),
160
+ AddressInterface::KEY_REGION_CODE => $ address ->getRegionCode (),
161
+ AddressInterface::KEY_STREET => $ address ->getStreet (),
162
+ AddressInterface::KEY_COMPANY => $ address ->getCompany (),
163
+ AddressInterface::KEY_TELEPHONE => $ address ->getTelephone (),
164
+ AddressInterface::KEY_POSTCODE => $ address ->getPostcode (),
165
+ AddressInterface::KEY_CITY => $ address ->getCity (),
166
+ AddressInterface::KEY_FIRSTNAME => $ address ->getFirstname (),
167
+ AddressInterface::KEY_LASTNAME => $ address ->getLastname (),
168
+ AddressInterface::KEY_EMAIL => $ address ->getEmail ()
169
+ ];
170
+
171
+ $ cartId = $ quote ->getId ();
172
+
173
+ $ serviceInfo = [
174
+ 'rest ' => [
175
+ 'resourcePath ' => self ::RESOURCE_PATH . 'mine/billing-address ' ,
176
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_GET ,
177
+ 'token ' => $ token
178
+ ],
179
+ 'soap ' => [
180
+ 'service ' => self ::SERVICE_NAME ,
181
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
182
+ 'operation ' => self ::SERVICE_NAME . 'Get ' ,
183
+ 'token ' => $ token
184
+ ],
185
+ ];
186
+
187
+ $ requestData = ["cartId " => $ cartId ];
188
+ $ this ->assertEquals ($ data , $ this ->_webApiCall ($ serviceInfo , $ requestData ));
189
+ }
190
+
191
+ /**
192
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
193
+ */
194
+ public function testSetMyAddress ()
195
+ {
196
+ // get customer ID token
197
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
198
+ $ customerTokenService = $ this ->objectManager ->create (
199
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
200
+ );
201
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
202
+
203
+ /** @var \Magento\Quote\Model\Quote $quote */
204
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
205
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
206
+
207
+ $ serviceInfo = [
208
+ 'rest ' => [
209
+ 'resourcePath ' => self ::RESOURCE_PATH . 'mine/billing-address ' ,
210
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST ,
211
+ 'token ' => $ token
212
+ ],
213
+ 'soap ' => [
214
+ 'service ' => self ::SERVICE_NAME ,
215
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
216
+ 'operation ' => self ::SERVICE_NAME . 'Assign ' ,
217
+ 'token ' => $ token
218
+ ],
219
+ ];
220
+
221
+ $ addressData = [
222
+ 'firstname ' => 'John ' ,
223
+ 'lastname ' => 'Smith ' ,
224
+ 'email ' => 'cat@dog.com ' ,
225
+ 'company ' => 'eBay Inc ' ,
226
+ 'street ' => ['Typical Street ' , 'Tiny House 18 ' ],
227
+ 'city ' => 'Big City ' ,
228
+ 'region_id ' => 12 ,
229
+ 'region ' => 'California ' ,
230
+ 'region_code ' => 'CA ' ,
231
+ 'postcode ' => '0985432 ' ,
232
+ 'country_id ' => 'US ' ,
233
+ 'telephone ' => '88776655 ' ,
234
+ 'fax ' => '44332255 ' ,
235
+ ];
236
+ $ requestData = [
237
+ "cartId " => $ quote ->getId (),
238
+ 'address ' => $ addressData ,
239
+ ];
240
+
241
+ $ addressId = $ this ->_webApiCall ($ serviceInfo , $ requestData );
242
+
243
+ //reset $quote to reload data
244
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
245
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
246
+ $ address = $ quote ->getBillingAddress ();
247
+ $ address ->getRegionCode ();
248
+ $ savedData = $ address ->getData ();
249
+ $ this ->assertEquals ($ addressId , $ savedData ['address_id ' ]);
250
+ //custom checks for street, region and address_type
251
+ foreach ($ addressData ['street ' ] as $ streetLine ) {
252
+ $ this ->assertContains ($ streetLine , $ quote ->getBillingAddress ()->getStreet ());
253
+ }
254
+ unset($ addressData ['street ' ]);
255
+ $ this ->assertEquals ('billing ' , $ savedData ['address_type ' ]);
256
+ //check the rest of fields
257
+ foreach ($ addressData as $ key => $ value ) {
258
+ $ this ->assertEquals ($ value , $ savedData [$ key ]);
259
+ }
260
+ }
135
261
}
0 commit comments