Skip to content

Commit 970ee2a

Browse files
committed
ACP2E-636: Cannot get graphql customer token
1 parent 603f6dd commit 970ee2a

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/LoginAsCustomerGraphQl/GenerateLoginCustomerTokenTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,57 @@ private function getAdminHeaderAuthentication(string $userName, string $password
224224
);
225225
}
226226
}
227+
228+
/**
229+
* Verify customer token as admin with store
230+
*
231+
* @magentoApiDataFixture Magento/LoginAsCustomer/_files/admin.php
232+
* @magentoConfigFixture admin_store login_as_customer/general/enabled 1
233+
* @magentoApiDataFixture Magento/Store/_files/second_store.php
234+
* @magentoApiDataFixture Magento/Customer/_files/customer_for_second_store.php
235+
* @throws Exception
236+
*/
237+
public function testGenerateCustomerValidTokenAsAdminWithStore()
238+
{
239+
$customerEmail = '[email protected]';
240+
241+
$mutation = $this->getQuery($customerEmail);
242+
243+
$response = $this->graphQlMutation(
244+
$mutation,
245+
[],
246+
'',
247+
$this->getAdminHeaderAuthenticationWithStore(
248+
'TestAdmin1',
249+
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
250+
'fixture_second_store'
251+
)
252+
);
253+
$this->assertArrayHasKey('generateCustomerTokenAsAdmin', $response);
254+
$this->assertIsArray($response['generateCustomerTokenAsAdmin']);
255+
}
256+
257+
/**
258+
* To get admin access token with store
259+
*
260+
* @param string $userName
261+
* @param string $password
262+
* @param string $storeCode
263+
* @return string[]
264+
* @throws AuthenticationException
265+
*/
266+
private function getAdminHeaderAuthenticationWithStore(string $userName, string $password, string $storeCode)
267+
{
268+
try {
269+
$adminAccessToken = $this->adminTokenService->createAdminAccessToken($userName, $password);
270+
return ['Authorization' => 'Bearer ' . $adminAccessToken, 'store' => $storeCode];
271+
} catch (\Exception $e) {
272+
throw new AuthenticationException(
273+
__(
274+
'The account sign-in was incorrect or your account is disabled temporarily. '
275+
. 'Please wait and try again later.'
276+
)
277+
);
278+
}
279+
}
227280
}

0 commit comments

Comments
 (0)