Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
namespace Magento\GraphQl\Customer;

use Magento\TestFramework\TestCase\GraphQlAbstract;
use PHPUnit\Framework\TestResult;

/**
* Class GenerateCustomerTokenTest
* @package Magento\GraphQl\Customer
* API-functional tests cases for generateCustomerToken mutation
*/
class GenerateCustomerTokenTest extends GraphQlAbstract
{
Expand All @@ -23,87 +21,95 @@ class GenerateCustomerTokenTest extends GraphQlAbstract
*/
public function testGenerateCustomerValidToken()
{
$userName = '[email protected]';
$email = '[email protected]';
$password = 'password';

$mutation
= <<<MUTATION
mutation {
generateCustomerToken(
email: "{$userName}"
password: "{$password}"
) {
token
}
}
MUTATION;
$mutation = $this->getQuery($email, $password);

$response = $this->graphQlMutation($mutation);
$this->assertArrayHasKey('generateCustomerToken', $response);
$this->assertInternalType('array', $response['generateCustomerToken']);
}

/**
* Verify customer with invalid credentials
* Test customer with invalid data.
*
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException \Exception
*
* @dataProvider dataProviderInvalidCustomerInfo
* @param string $email
* @param string $password
* @param string $message
*/
public function testGenerateCustomerTokenWithInvalidCredentials()
public function testGenerateCustomerTokenInvalidData(string $email, string $password, string $message)
{
$userName = '[email protected]';
$password = 'bad-password';

$mutation
= <<<MUTATION
mutation {
generateCustomerToken(
email: "{$userName}"
password: "{$password}"
) {
token
}
}
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.');
$mutation = $this->getQuery($email, $password);
$this->expectExceptionMessage($message);
$this->graphQlMutation($mutation);
}

/**
* Verify customer with empty email
* Test customer token regeneration.
*
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*/
public function testGenerateCustomerTokenWithEmptyEmail()
public function testRegenerateCustomerToken()
{
$email = '';
$password = 'bad-password';
$email = '[email protected]';
$password = 'password';

$mutation
= <<<MUTATION
mutation {
generateCustomerToken(
email: "{$email}"
password: "{$password}"
) {
token
}
}
MUTATION;
$mutation = $this->getQuery($email, $password);

$this->expectException(\Exception::class);
$this->expectExceptionMessage('GraphQL response contains errors: Specify the "email" value.');
$this->graphQlMutation($mutation);
$response1 = $this->graphQlMutation($mutation);
$token1 = $response1['generateCustomerToken']['token'];

$response2 = $this->graphQlMutation($mutation);
$token2 = $response2['generateCustomerToken']['token'];

$this->assertNotEquals($token1, $token2, 'Tokens should not be identical!');
}

/**
* Verify customer with empty password
* @return array
*/
public function testGenerateCustomerTokenWithEmptyPassword()
public function dataProviderInvalidCustomerInfo(): array
{
$email = '[email protected]';
$password = '';
return [
'invalid_email' => [
'[email protected]',
'password',
'The account sign-in was incorrect or your account is disabled temporarily. ' .
'Please wait and try again later.'
],
'empty_email' => [
'',
'password',
'Specify the "email" value.'
],
'invalid_password' => [
'[email protected]',
'invalid_password',
'The account sign-in was incorrect or your account is disabled temporarily. ' .
'Please wait and try again later.'
],
'empty_password' => [
'[email protected]',
'',
'Specify the "password" value.'

]
];
}

$mutation
= <<<MUTATION
/**
* @param string $email
* @param string $password
* @return string
*/
private function getQuery(string $email, string $password) : string
{
return <<<MUTATION
mutation {
generateCustomerToken(
email: "{$email}"
Expand All @@ -113,9 +119,5 @@ public function testGenerateCustomerTokenWithEmptyPassword()
}
}
MUTATION;

$this->expectException(\Exception::class);
$this->expectExceptionMessage('GraphQL response contains errors: Specify the "password" value.');
$this->graphQlMutation($mutation);
}
}