Skip to content

magento/magento2#: Add additional test coverage to “updateCustomer” mutation #28304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 @@ -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