Skip to content

Commit 63d91c6

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-636' into PR_L3_18_04_2022
2 parents 5f0d6c1 + 04a9690 commit 63d91c6

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

app/code/Magento/LoginAsCustomerGraphQl/Model/LoginAsCustomer/CreateCustomerToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(
5252
*/
5353
public function execute(string $email, StoreInterface $store): array
5454
{
55-
$customer = $this->customerFactory->create()->setWebsiteId((int)$store->getId())->loadByEmail($email);
55+
$customer = $this->customerFactory->create()->setWebsiteId((int)$store->getWebsiteId())->loadByEmail($email);
5656

5757
/* Check if customer email exist */
5858
if (!$customer->getId()) {

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)