From 62f5c324e0384aec0082b86a71fc3f47e6e2d6b8 Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Wed, 20 May 2020 20:59:01 +0300 Subject: [PATCH] =?UTF-8?q?magento/magento2#:=20Add=20additional=20test=20?= =?UTF-8?q?coverage=20to=20=E2=80=9CupdateCustomer=E2=80=9D=20mutation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GraphQl/Customer/UpdateCustomerTest.php | 104 ++++++++++++++++-- 1 file changed, 95 insertions(+), 9 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerTest.php index 6e90e85782bb2..c42450d86fd58 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerTest.php @@ -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 = 'customer@example.com'; @@ -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 = 'customer@example.com'; @@ -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 = 'customer@example.com'; @@ -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 = 'customer@example.com'; $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 = 'customer@example.com'; + $currentPassword = 'password'; + $invalidEmail = 'customer.example.com'; + + $query = <<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 = 'customer@example.com'; @@ -310,10 +343,63 @@ public function testEmptyCustomerName() $this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword)); } + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testEmptyCustomerLastName() + { + $query = <<expectException(Exception::class); + $this->expectExceptionMessage('Required parameters are missing: Last Name'); + + $this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders('customer@example.com', 'password')); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testUpdateCustomerIfDobIsInvalid() + { + $invalidDob = 'bla-bla-bla'; + + $query = <<expectException(Exception::class); + $this->expectExceptionMessage('Invalid date'); + + $this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders('customer@example.com', 'password')); + } + /** * @param string $email * @param string $password * @return array + * @throws AuthenticationException */ private function getCustomerAuthHeaders(string $email, string $password): array {