Skip to content

Commit ed86fbd

Browse files
author
Tanniru, Murali(mtanniru)
committed
MAGETWO-51862: API-Functional: Automate test to create API Request to access other customer data using customer token.
- Updated function to retrieve customer token. - Marked test as Rest Only.
1 parent 0fd0863 commit ed86fbd

File tree

1 file changed

+14
-39
lines changed

1 file changed

+14
-39
lines changed

dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerRepositoryTest.php

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ class CustomerRepositoryTest extends WebapiAbstract
8484
*/
8585
private $dataObjectProcessor;
8686

87-
/**
88-
* @var TokenModel
89-
*/
90-
private $token;
91-
9287
/**
9388
* Execute per test initialization.
9489
*/
@@ -154,14 +149,21 @@ public function tearDown()
154149
* @expectedException \Exception
155150
* @expectedExceptionMessage Consumer is not authorized to access %resources
156151
*
157-
*/
152+
*/
158153
public function testInvalidCustomerUpdate()
159154
{
160-
//Create customer 1 and retrieve customer token.
161-
$customerData1 = $this->_createCustomer();
162-
$this->resetTokenForCustomer(($customerData1[Customer::EMAIL]), 'test@123');
155+
$this->_markTestAsRestOnly();
156+
157+
//Create first customer and retrieve customer token.
158+
$firstCustomerData = $this->_createCustomer();
159+
160+
// get customer ID token
161+
/** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
162+
//$customerTokenService = $this->objectManager->create(CustomerTokenServiceInterface::class);
163+
$customerTokenService = Bootstrap::getObjectManager()->create('Magento\Integration\Api\CustomerTokenServiceInterface');
164+
$token = $customerTokenService->createCustomerAccessToken($firstCustomerData[Customer::EMAIL], 'test@123');
163165

164-
//Create customer 2 and update lastname.
166+
//Create second customer and update lastname.
165167
$customerData = $this->_createCustomer();
166168
$existingCustomerDataObject = $this->_getCustomerData($customerData[Customer::ID]);
167169
$lastName = $existingCustomerDataObject->getLastname();
@@ -177,14 +179,8 @@ public function testInvalidCustomerUpdate()
177179
'rest' => [
178180
'resourcePath' => self::RESOURCE_PATH . "/{$customerData[Customer::ID]}",
179181
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
180-
'token' => $this->token,
181-
],
182-
'soap' => [
183-
'service' => self::SERVICE_NAME,
184-
'serviceVersion' => self::SERVICE_VERSION,
185-
'operation' => self::SERVICE_NAME . 'Save',
186-
'token' => $this->token,
187-
],
182+
'token' => $token,
183+
]
188184
];
189185

190186
$newCustomerDataObject = $this->dataObjectProcessor->buildOutputDataArray(
@@ -804,25 +800,4 @@ protected function _createCustomer()
804800
$this->currentCustomerId[] = $customerData['id'];
805801
return $customerData;
806802
}
807-
808-
/**
809-
* Sets the test's access token for a particular username and password.
810-
*
811-
* @param string $username
812-
* @param string $password
813-
*/
814-
815-
protected function resetTokenForCustomer($username, $password)
816-
{
817-
818-
// get customer ID token
819-
$serviceInfo = [
820-
'rest' => [
821-
'resourcePath' => self::RESOURCE_PATH_CUSTOMER_TOKEN,
822-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
823-
],
824-
];
825-
$requestData = ['username' => $username, 'password' => $password];
826-
$this->token = $this->_webApiCall($serviceInfo, $requestData);
827-
}
828803
}

0 commit comments

Comments
 (0)