Skip to content

Commit ca0c135

Browse files
committed
GraphQL-129. Add generate customer token test
1 parent ea9b2a8 commit ca0c135

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Customer;
9+
10+
use Magento\TestFramework\TestCase\GraphQlAbstract;
11+
12+
class GenerateCustomerTokenTest extends GraphQlAbstract
13+
{
14+
15+
/**
16+
* Verify customer token with valid credentials
17+
*
18+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
19+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
20+
*/
21+
public function testGenerateCustomerValidToken()
22+
{
23+
$userName = 'customer@example.com';
24+
$password = 'password';
25+
26+
$mutation
27+
= <<<MUTATION
28+
mutation {
29+
generateCustomerToken(
30+
email: "{$userName}"
31+
password: "{$password}"
32+
)
33+
}
34+
MUTATION;
35+
36+
$response = $this->graphQlQuery($mutation);
37+
$this->assertArrayHasKey('generateCustomerToken', $response);
38+
$this->assertInternalType('string', $response['generateCustomerToken']);
39+
}
40+
41+
/**
42+
* Verify customer with invalid credentials
43+
*
44+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
45+
*/
46+
public function testGenerateCustomerTokenWithInvalidCredentials()
47+
{
48+
$userName = 'customer@example.com';
49+
$password = 'bad-password';
50+
51+
$mutation
52+
= <<<MUTATION
53+
mutation {
54+
generateCustomerToken(
55+
email: "{$userName}"
56+
password: "{$password}"
57+
)
58+
}
59+
MUTATION;
60+
61+
$this->expectException(\Exception::class);
62+
$this->expectExceptionMessage('GraphQL response contains errors: ' .
63+
'The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.');
64+
$this->graphQlQuery($mutation);
65+
}
66+
}

0 commit comments

Comments
 (0)