@@ -25,6 +25,7 @@ class CustomerRepositoryTest extends WebapiAbstract
25
25
const SERVICE_VERSION = 'V1 ' ;
26
26
const SERVICE_NAME = 'customerCustomerRepositoryV1 ' ;
27
27
const RESOURCE_PATH = '/V1/customers ' ;
28
+ const RESOURCE_PATH_CUSTOMER_TOKEN = "/V1/integration/customer/token " ;
28
29
29
30
/**
30
31
* Sample values for testing
@@ -141,6 +142,55 @@ public function tearDown()
141
142
unset($ this ->customerRepository );
142
143
}
143
144
145
+ /**
146
+ * Validate update by invalid customer.
147
+ *
148
+ * @expectedException \Exception
149
+ * @expectedExceptionMessage Consumer is not authorized to access %resources
150
+ */
151
+ public function testInvalidCustomerUpdate ()
152
+ {
153
+ $ this ->_markTestAsRestOnly ();
154
+
155
+ //Create first customer and retrieve customer token.
156
+ $ firstCustomerData = $ this ->_createCustomer ();
157
+
158
+ // get customer ID token
159
+ /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
160
+ //$customerTokenService = $this->objectManager->create(CustomerTokenServiceInterface::class);
161
+ $ customerTokenService = Bootstrap::getObjectManager ()->create (
162
+ 'Magento\Integration\Api\CustomerTokenServiceInterface '
163
+ );
164
+ $ token = $ customerTokenService ->createCustomerAccessToken ($ firstCustomerData [Customer::EMAIL ], 'test@123 ' );
165
+
166
+ //Create second customer and update lastname.
167
+ $ customerData = $ this ->_createCustomer ();
168
+ $ existingCustomerDataObject = $ this ->_getCustomerData ($ customerData [Customer::ID ]);
169
+ $ lastName = $ existingCustomerDataObject ->getLastname ();
170
+ $ customerData [Customer::LASTNAME ] = $ lastName . 'Updated ' ;
171
+ $ newCustomerDataObject = $ this ->customerDataFactory ->create ();
172
+ $ this ->dataObjectHelper ->populateWithArray (
173
+ $ newCustomerDataObject ,
174
+ $ customerData ,
175
+ '\Magento\Customer\Api\Data\CustomerInterface '
176
+ );
177
+
178
+ $ serviceInfo = [
179
+ 'rest ' => [
180
+ 'resourcePath ' => self ::RESOURCE_PATH . "/ {$ customerData [Customer::ID ]}" ,
181
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_PUT ,
182
+ 'token ' => $ token ,
183
+ ]
184
+ ];
185
+
186
+ $ newCustomerDataObject = $ this ->dataObjectProcessor ->buildOutputDataArray (
187
+ $ newCustomerDataObject ,
188
+ 'Magento\Customer\Api\Data\CustomerInterface '
189
+ );
190
+ $ requestData = ['customer ' => $ newCustomerDataObject ];
191
+ $ this ->_webApiCall ($ serviceInfo , $ requestData );
192
+ }
193
+
144
194
public function testDeleteCustomer ()
145
195
{
146
196
$ customerData = $ this ->_createCustomer ();
0 commit comments