Skip to content

Commit 62f5c32

Browse files
committed
magento/magento2#: Add additional test coverage to “updateCustomer” mutation
1 parent 2d09485 commit 62f5c32

File tree

1 file changed

+95
-9
lines changed

1 file changed

+95
-9
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerTest.php

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
namespace Magento\GraphQl\Customer;
99

10+
use Exception;
1011
use Magento\Customer\Model\CustomerAuthUpdate;
11-
use Magento\Customer\Model\CustomerRegistry;
12+
use Magento\Framework\Exception\AuthenticationException;
1213
use Magento\Integration\Api\CustomerTokenServiceInterface;
1314
use Magento\TestFramework\Helper\Bootstrap;
1415
use Magento\TestFramework\TestCase\GraphQlAbstract;
@@ -113,7 +114,7 @@ public function testUpdateCustomer()
113114
*/
114115
public function testUpdateCustomerIfInputDataIsEmpty()
115116
{
116-
$this->expectException(\Exception::class);
117+
$this->expectException(Exception::class);
117118
$this->expectExceptionMessage('"input" value should be specified');
118119

119120
$currentEmail = 'customer@example.com';
@@ -139,7 +140,7 @@ public function testUpdateCustomerIfInputDataIsEmpty()
139140
*/
140141
public function testUpdateCustomerIfUserIsNotAuthorized()
141142
{
142-
$this->expectException(\Exception::class);
143+
$this->expectException(Exception::class);
143144
$this->expectExceptionMessage('The current customer isn\'t authorized.');
144145

145146
$newFirstname = 'Richard';
@@ -165,7 +166,7 @@ public function testUpdateCustomerIfUserIsNotAuthorized()
165166
*/
166167
public function testUpdateCustomerIfAccountIsLocked()
167168
{
168-
$this->expectException(\Exception::class);
169+
$this->expectException(Exception::class);
169170
$this->expectExceptionMessage('The account is locked.');
170171

171172
$this->lockCustomer->execute(1);
@@ -195,7 +196,7 @@ public function testUpdateCustomerIfAccountIsLocked()
195196
*/
196197
public function testUpdateEmailIfPasswordIsMissed()
197198
{
198-
$this->expectException(\Exception::class);
199+
$this->expectException(Exception::class);
199200
$this->expectExceptionMessage('Provide the current "password" to change "email".');
200201

201202
$currentEmail = 'customer@example.com';
@@ -223,7 +224,7 @@ public function testUpdateEmailIfPasswordIsMissed()
223224
*/
224225
public function testUpdateEmailIfPasswordIsInvalid()
225226
{
226-
$this->expectException(\Exception::class);
227+
$this->expectException(Exception::class);
227228
$this->expectExceptionMessage('Invalid login or password.');
228229

229230
$currentEmail = 'customer@example.com';
@@ -253,8 +254,10 @@ public function testUpdateEmailIfPasswordIsInvalid()
253254
*/
254255
public function testUpdateEmailIfEmailAlreadyExists()
255256
{
256-
$this->expectException(\Exception::class);
257-
$this->expectExceptionMessage('A customer with the same email address already exists in an associated website.');
257+
$this->expectException(Exception::class);
258+
$this->expectExceptionMessage(
259+
'A customer with the same email address already exists in an associated website.'
260+
);
258261

259262
$currentEmail = 'customer@example.com';
260263
$currentPassword = 'password';
@@ -281,12 +284,42 @@ public function testUpdateEmailIfEmailAlreadyExists()
281284
$this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
282285
}
283286

287+
/**
288+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
289+
*/
290+
public function testUpdateEmailIfEmailIsInvalid()
291+
{
292+
$currentEmail = 'customer@example.com';
293+
$currentPassword = 'password';
294+
$invalidEmail = 'customer.example.com';
295+
296+
$query = <<<QUERY
297+
mutation {
298+
updateCustomer(
299+
input: {
300+
email: "{$invalidEmail}"
301+
password: "{$currentPassword}"
302+
}
303+
) {
304+
customer {
305+
email
306+
}
307+
}
308+
}
309+
QUERY;
310+
311+
$this->expectException(Exception::class);
312+
$this->expectExceptionMessage('"' . $invalidEmail . '" is not a valid email address.');
313+
314+
$this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
315+
}
316+
284317
/**
285318
* @magentoApiDataFixture Magento/Customer/_files/customer.php
286319
*/
287320
public function testEmptyCustomerName()
288321
{
289-
$this->expectException(\Exception::class);
322+
$this->expectException(Exception::class);
290323
$this->expectExceptionMessage('Required parameters are missing: First Name');
291324

292325
$currentEmail = 'customer@example.com';
@@ -310,10 +343,63 @@ public function testEmptyCustomerName()
310343
$this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
311344
}
312345

346+
/**
347+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
348+
*/
349+
public function testEmptyCustomerLastName()
350+
{
351+
$query = <<<QUERY
352+
mutation {
353+
updateCustomer(
354+
input: {
355+
lastname: ""
356+
}
357+
) {
358+
customer {
359+
lastname
360+
}
361+
}
362+
}
363+
QUERY;
364+
365+
$this->expectException(Exception::class);
366+
$this->expectExceptionMessage('Required parameters are missing: Last Name');
367+
368+
$this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders('customer@example.com', 'password'));
369+
}
370+
371+
/**
372+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
373+
*/
374+
public function testUpdateCustomerIfDobIsInvalid()
375+
{
376+
$invalidDob = 'bla-bla-bla';
377+
378+
$query = <<<QUERY
379+
mutation {
380+
updateCustomer(
381+
input: {
382+
date_of_birth: "{$invalidDob}"
383+
}
384+
) {
385+
customer {
386+
date_of_birth
387+
}
388+
}
389+
}
390+
QUERY;
391+
392+
$this->expectException(Exception::class);
393+
$this->expectExceptionMessage('Invalid date');
394+
395+
$this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders('customer@example.com', 'password'));
396+
}
397+
313398
/**
314399
* @param string $email
315400
* @param string $password
316401
* @return array
402+
* @throws AuthenticationException
317403
*/
318404
private function getCustomerAuthHeaders(string $email, string $password): array
319405
{

0 commit comments

Comments
 (0)