-
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.
ENGCOM-7593: magento/magento2#: Add additional test coverage to “upda…
…teCustomer” mutation #28304 - Merge Pull Request #28304 from atwixfirster/magento2:graphql-updateCustomer - Merged commits: 1. 62f5c32
- Loading branch information
Showing
1 changed file
with
95 additions
and
9 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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; | ||
|
@@ -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]'; | ||
|
@@ -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'; | ||
|
@@ -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); | ||
|
@@ -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]'; | ||
|
@@ -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]'; | ||
|
@@ -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'; | ||
|
@@ -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 { | ||
} | ||
} | ||
} | ||
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]'; | ||
|
@@ -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 | ||
{ | ||
|