Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

675 test generate customer token #677

Merged
merged 6 commits into from
Jun 12, 2019
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,14 +21,14 @@ class GenerateCustomerTokenTest extends GraphQlAbstract
*/
public function testGenerateCustomerValidToken()
{
$userName = 'customer@example.com';
$email = 'customer@example.com';
$password = 'password';

$mutation
= <<<MUTATION
mutation {
generateCustomerToken(
email: "{$userName}"
email: "{$email}"
password: "{$password}"
) {
token
Expand All @@ -44,38 +42,40 @@ public function testGenerateCustomerValidToken()
}

/**
* Verify customer with invalid credentials
* Verify customer with invalid email
*
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException \Exception
* @expectedExceptionMessage GraphQL response contains errors: The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.
*/
public function testGenerateCustomerTokenWithInvalidCredentials()
public function testGenerateCustomerTokenWithInvalidEmail()
{
$userName = 'customer@example.com';
$password = 'bad-password';
$email = 'customer@example';
$password = 'password';

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

/**
* Verify customer with empty email
*
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*/
public function testGenerateCustomerTokenWithEmptyEmail()
{
$email = '';
$password = 'bad-password';
$password = 'password';

$mutation
= <<<MUTATION
Expand All @@ -94,10 +94,39 @@ public function testGenerateCustomerTokenWithEmptyEmail()
$this->graphQlMutation($mutation);
}

/**
* Verify customer with invalid credentials
*
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException \Exception
* @expectedExceptionMessage GraphQL response contains errors: The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.
*/
public function testGenerateCustomerTokenWithIncorrectPassword()
{
$email = 'customer@example.com';
$password = 'bad-password';

$mutation
= <<<MUTATION
mutation {
generateCustomerToken(
email: "{$email}"
password: "{$password}"
) {
token
}
}
MUTATION;

$this->graphQlMutation($mutation);
}

/**
* Verify customer with empty password
*
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*/
public function testGenerateCustomerTokenWithEmptyPassword()
public function testGenerateCustomerTokenWithInvalidPassword()
{
$email = 'customer@example.com';
$password = '';
Expand All @@ -118,4 +147,35 @@ public function testGenerateCustomerTokenWithEmptyPassword()
$this->expectExceptionMessage('GraphQL response contains errors: Specify the "password" value.');
$this->graphQlMutation($mutation);
}

/**
* Verify customer with empty password
*
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*/
public function testRegenerateCustomerToken()
{
$email = 'customer@example.com';
$password = 'password';

$mutation
= <<<MUTATION
mutation {
generateCustomerToken(
email: "{$email}"
password: "{$password}"
) {
token
}
}
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!');
}
}