Skip to content

Commit

Permalink
ENGCOM-7593: magento/magento2#: Add additional test coverage to “upda…
Browse files Browse the repository at this point in the history
…teCustomer” mutation #28304

 - Merge Pull Request #28304 from atwixfirster/magento2:graphql-updateCustomer
 - Merged commits:
   1. 62f5c32
  • Loading branch information
magento-engcom-team committed Jun 2, 2020
2 parents 97f9b00 + 62f5c32 commit efc4244
Showing 1 changed file with 95 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

namespace Magento\GraphQl\Customer;

use Exception;
use Magento\Customer\Model\CustomerAuthUpdate;
use Magento\Customer\Model\CustomerRegistry;
use Magento\Framework\Exception\AuthenticationException;
use Magento\Integration\Api\CustomerTokenServiceInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;
Expand Down Expand Up @@ -113,7 +114,7 @@ public function testUpdateCustomer()
*/
public function testUpdateCustomerIfInputDataIsEmpty()
{
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->expectExceptionMessage('"input" value should be specified');

$currentEmail = '[email protected]';
Expand All @@ -139,7 +140,7 @@ public function testUpdateCustomerIfInputDataIsEmpty()
*/
public function testUpdateCustomerIfUserIsNotAuthorized()
{
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->expectExceptionMessage('The current customer isn\'t authorized.');

$newFirstname = 'Richard';
Expand All @@ -165,7 +166,7 @@ public function testUpdateCustomerIfUserIsNotAuthorized()
*/
public function testUpdateCustomerIfAccountIsLocked()
{
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->expectExceptionMessage('The account is locked.');

$this->lockCustomer->execute(1);
Expand Down Expand Up @@ -195,7 +196,7 @@ public function testUpdateCustomerIfAccountIsLocked()
*/
public function testUpdateEmailIfPasswordIsMissed()
{
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->expectExceptionMessage('Provide the current "password" to change "email".');

$currentEmail = '[email protected]';
Expand Down Expand Up @@ -223,7 +224,7 @@ public function testUpdateEmailIfPasswordIsMissed()
*/
public function testUpdateEmailIfPasswordIsInvalid()
{
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid login or password.');

$currentEmail = '[email protected]';
Expand Down Expand Up @@ -253,8 +254,10 @@ public function testUpdateEmailIfPasswordIsInvalid()
*/
public function testUpdateEmailIfEmailAlreadyExists()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('A customer with the same email address already exists in an associated website.');
$this->expectException(Exception::class);
$this->expectExceptionMessage(
'A customer with the same email address already exists in an associated website.'
);

$currentEmail = '[email protected]';
$currentPassword = 'password';
Expand All @@ -281,12 +284,42 @@ public function testUpdateEmailIfEmailAlreadyExists()
$this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*/
public function testUpdateEmailIfEmailIsInvalid()
{
$currentEmail = '[email protected]';
$currentPassword = 'password';
$invalidEmail = 'customer.example.com';

$query = <<<QUERY
mutation {
updateCustomer(
input: {
email: "{$invalidEmail}"
password: "{$currentPassword}"
}
) {
customer {
email
}
}
}
QUERY;

$this->expectException(Exception::class);
$this->expectExceptionMessage('"' . $invalidEmail . '" is not a valid email address.');

$this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*/
public function testEmptyCustomerName()
{
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->expectExceptionMessage('Required parameters are missing: First Name');

$currentEmail = '[email protected]';
Expand All @@ -310,10 +343,63 @@ public function testEmptyCustomerName()
$this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*/
public function testEmptyCustomerLastName()
{
$query = <<<QUERY
mutation {
updateCustomer(
input: {
lastname: ""
}
) {
customer {
lastname
}
}
}
QUERY;

$this->expectException(Exception::class);
$this->expectExceptionMessage('Required parameters are missing: Last Name');

$this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders('[email protected]', 'password'));
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*/
public function testUpdateCustomerIfDobIsInvalid()
{
$invalidDob = 'bla-bla-bla';

$query = <<<QUERY
mutation {
updateCustomer(
input: {
date_of_birth: "{$invalidDob}"
}
) {
customer {
date_of_birth
}
}
}
QUERY;

$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid date');

$this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders('[email protected]', 'password'));
}

/**
* @param string $email
* @param string $password
* @return array
* @throws AuthenticationException
*/
private function getCustomerAuthHeaders(string $email, string $password): array
{
Expand Down

0 comments on commit efc4244

Please sign in to comment.