Skip to content

Commit ec8352e

Browse files
authored
LYNX-619 updateCustomerEmail mutation issue fix
1 parent feacf5d commit ec8352e

File tree

2 files changed

+139
-5
lines changed

2 files changed

+139
-5
lines changed

app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomerEmail.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -77,6 +77,7 @@ public function resolve(
7777
}
7878

7979
$customer = $this->getCustomer->execute($context);
80+
$customer->setData('ignore_validation_flag', true);
8081
$this->updateCustomerAccount->execute(
8182
$customer,
8283
[
@@ -86,8 +87,6 @@ public function resolve(
8687
$context->getExtensionAttributes()->getStore()
8788
);
8889

89-
$data = $this->extractCustomerData->execute($customer);
90-
91-
return ['customer' => $data];
90+
return ['customer' => $this->extractCustomerData->execute($customer)];
9291
}
9392
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Customer;
9+
10+
use Exception;
11+
use Magento\Customer\Api\CustomerMetadataInterface;
12+
use Magento\Customer\Test\Fixture\Customer;
13+
use Magento\Eav\Test\Fixture\Attribute;
14+
use Magento\Integration\Api\CustomerTokenServiceInterface;
15+
use Magento\TestFramework\Fixture\DataFixture;
16+
use Magento\Framework\Exception\AuthenticationException;
17+
use Magento\TestFramework\TestCase\GraphQlAbstract;
18+
use Magento\TestFramework\Helper\Bootstrap;
19+
20+
#[
21+
DataFixture(Customer::class, ['email' => 'customer@example.com'], as: 'customer'),
22+
DataFixture(
23+
Attribute::class,
24+
[
25+
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
26+
'is_required' => true,
27+
],
28+
'customer_attribute'
29+
)
30+
]
31+
class CustomerEmailUpdateTest extends GraphQlAbstract
32+
{
33+
/**
34+
* Test customer email update
35+
*
36+
* @return void
37+
* @throws Exception
38+
*/
39+
public function testUpdateCustomerEmail(): void
40+
{
41+
$response = $this->graphQlMutation(
42+
$this->getQuery('newcustomer@example.com', 'password'),
43+
[],
44+
'',
45+
$this->getCustomerAuthHeaders('customer@example.com', 'password')
46+
);
47+
48+
$this->assertEquals('newcustomer@example.com', $response['updateCustomerEmail']['customer']['email']);
49+
}
50+
51+
/**
52+
* Test customer email update with empty fields
53+
*
54+
* @param string $email
55+
* @param string $password
56+
* @param string $message
57+
* @dataProvider customerInputFieldDataProvider
58+
* @return void
59+
* @throws AuthenticationException
60+
*/
61+
public function testUpdateCustomerEmailWithEmptyFields(
62+
string $email,
63+
string $password,
64+
string $message
65+
): void {
66+
$this->expectException(Exception::class);
67+
$this->expectExceptionMessage($message);
68+
$this->graphQlMutation(
69+
$this->getQuery($email, $password),
70+
[],
71+
'',
72+
$this->getCustomerAuthHeaders('customer@example.com', 'password')
73+
);
74+
}
75+
76+
/**
77+
* Data provider for testUpdateCustomerEmailWithEmptyFields
78+
*
79+
* @return array
80+
*/
81+
public static function customerInputFieldDataProvider(): array
82+
{
83+
return [
84+
[
85+
'email' => 'newcustomer@example.com',
86+
'password' => '',
87+
'message' => 'Provide the current "password" to change "email".',
88+
],
89+
[
90+
'email' => '',
91+
'password' => 'password',
92+
'message' => '"" is not a valid email address.',
93+
]
94+
];
95+
}
96+
97+
/**
98+
* Get customer email update mutation
99+
*
100+
* @param string $newEmail
101+
* @param string $currentPassword
102+
* @return string
103+
*/
104+
private function getQuery(string $newEmail, string $currentPassword): string
105+
{
106+
return <<<MUTATION
107+
mutation {
108+
updateCustomerEmail(
109+
email: "{$newEmail}"
110+
password: "{$currentPassword}"
111+
) {
112+
customer {
113+
email
114+
}
115+
}
116+
}
117+
MUTATION;
118+
}
119+
120+
/**
121+
* Get customer authorization headers
122+
*
123+
* @param string $email
124+
* @param string $password
125+
* @return array
126+
* @throws AuthenticationException
127+
*/
128+
private function getCustomerAuthHeaders(string $email, string $password): array
129+
{
130+
$customerToken = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class)
131+
->createCustomerAccessToken($email, $password);
132+
133+
return ['Authorization' => 'Bearer ' . $customerToken];
134+
}
135+
}

0 commit comments

Comments
 (0)