Skip to content

Commit 0dbf0e9

Browse files
ENGCOM-5233: GraphQl-673: isEmailAvailable test coverage #706
- Merge Pull Request magento/graphql-ce#706 from magento/graphql-ce:673-isEmailAvailable_tests - Merged commits: 1. a90b493 2. 7e71a40 3. 0c843c8 4. fa1acbb 5. 7cd32cf
2 parents 9473b31 + 7cd32cf commit 0dbf0e9

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1414
use Magento\Framework\GraphQl\Query\ResolverInterface;
1515
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\Framework\Validator\EmailAddress as EmailValidator;
1617

1718
/**
1819
* Is Customer Email Available
@@ -24,13 +25,21 @@ class IsEmailAvailable implements ResolverInterface
2425
*/
2526
private $accountManagement;
2627

28+
/**
29+
* @var EmailValidator
30+
*/
31+
private $emailValidator;
32+
2733
/**
2834
* @param AccountManagementInterface $accountManagement
35+
* @param EmailValidator $emailValidator
2936
*/
3037
public function __construct(
31-
AccountManagementInterface $accountManagement
38+
AccountManagementInterface $accountManagement,
39+
EmailValidator $emailValidator
3240
) {
3341
$this->accountManagement = $accountManagement;
42+
$this->emailValidator = $emailValidator;
3443
}
3544

3645
/**
@@ -47,6 +56,10 @@ public function resolve(
4756
throw new GraphQlInputException(__('Email must be specified'));
4857
}
4958

59+
if (!$this->emailValidator->isValid($args['email'])) {
60+
throw new GraphQlInputException(__('Email is invalid'));
61+
}
62+
5063
try {
5164
$isEmailAvailable = $this->accountManagement->isEmailAvailable($args['email']);
5265
} catch (LocalizedException $e) {

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
use Magento\TestFramework\TestCase\GraphQlAbstract;
1111

12+
/**
13+
* Test email availability functionality
14+
*/
1215
class IsEmailAvailableTest extends GraphQlAbstract
1316
{
1417
/**
@@ -31,6 +34,9 @@ public function testEmailNotAvailable()
3134
self::assertFalse($response['isEmailAvailable']['is_email_available']);
3235
}
3336

37+
/**
38+
* Verify email availability
39+
*/
3440
public function testEmailAvailable()
3541
{
3642
$query =
@@ -47,4 +53,55 @@ public function testEmailAvailable()
4753
self::assertArrayHasKey('is_email_available', $response['isEmailAvailable']);
4854
self::assertTrue($response['isEmailAvailable']['is_email_available']);
4955
}
56+
57+
/**
58+
* @expectedException \Exception
59+
* @expectedExceptionMessage GraphQL response contains errors: Email must be specified
60+
*/
61+
public function testEmailAvailableEmptyValue()
62+
{
63+
$query =
64+
<<<QUERY
65+
{
66+
isEmailAvailable(email: "") {
67+
is_email_available
68+
}
69+
}
70+
QUERY;
71+
$this->graphQlQuery($query);
72+
}
73+
74+
/**
75+
* @expectedException \Exception
76+
* @expectedExceptionMessage Field "isEmailAvailable" argument "email" of type "String!" is required
77+
*/
78+
public function testEmailAvailableMissingValue()
79+
{
80+
$query =
81+
<<<QUERY
82+
{
83+
isEmailAvailable {
84+
is_email_available
85+
}
86+
}
87+
QUERY;
88+
$this->graphQlQuery($query);
89+
}
90+
91+
/**
92+
* @expectedException \Exception
93+
* @expectedExceptionMessage GraphQL response contains errors: Email is invalid
94+
*/
95+
public function testEmailAvailableInvalidValue()
96+
{
97+
$query =
98+
<<<QUERY
99+
{
100+
isEmailAvailable(email: "invalid-email") {
101+
is_email_available
102+
}
103+
}
104+
QUERY;
105+
$this->graphQlQuery($query);
106+
}
50107
}

0 commit comments

Comments
 (0)