-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL-129. Add generate customer token test
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GenerateCustomerTokenTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Customer; | ||
|
||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
class GenerateCustomerTokenTest extends GraphQlAbstract | ||
{ | ||
|
||
/** | ||
* Verify customer token with valid credentials | ||
* | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||
*/ | ||
public function testGenerateCustomerValidToken() | ||
{ | ||
$userName = 'customer@example.com'; | ||
$password = 'password'; | ||
|
||
$mutation | ||
= <<<MUTATION | ||
mutation { | ||
generateCustomerToken( | ||
email: "{$userName}" | ||
password: "{$password}" | ||
) | ||
} | ||
MUTATION; | ||
|
||
$response = $this->graphQlQuery($mutation); | ||
$this->assertArrayHasKey('generateCustomerToken', $response); | ||
$this->assertInternalType('string', $response['generateCustomerToken']); | ||
} | ||
|
||
/** | ||
* Verify customer with invalid credentials | ||
* | ||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||
*/ | ||
public function testGenerateCustomerTokenWithInvalidCredentials() | ||
{ | ||
$userName = 'customer@example.com'; | ||
$password = 'bad-password'; | ||
|
||
$mutation | ||
= <<<MUTATION | ||
mutation { | ||
generateCustomerToken( | ||
email: "{$userName}" | ||
password: "{$password}" | ||
) | ||
} | ||
MUTATION; | ||
|
||
$this->expectException(\Exception::class); | ||
$this->expectExceptionMessage('GraphQL response contains errors: ' . | ||
'The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.'); | ||
$this->graphQlQuery($mutation); | ||
} | ||
} |