Skip to content

Commit 35293ae

Browse files
committed
#675: [Test coverage] Generate customer token
- test refactoring
1 parent b75f352 commit 35293ae

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

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

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,7 @@ public function testGenerateCustomerValidToken()
2424
$email = 'customer@example.com';
2525
$password = 'password';
2626

27-
$mutation
28-
= <<<MUTATION
29-
mutation {
30-
generateCustomerToken(
31-
email: "{$email}"
32-
password: "{$password}"
33-
) {
34-
token
35-
}
36-
}
37-
MUTATION;
27+
$mutation = $this->getQuery($email, $password);
3828

3929
$response = $this->graphQlMutation($mutation);
4030
$this->assertArrayHasKey('generateCustomerToken', $response);
@@ -52,19 +42,9 @@ public function testGenerateCustomerValidToken()
5242
* @param string $password
5343
* @param string $message
5444
*/
55-
public function testGenerateCustomerTokenNegativeCases(string $email, string $password, string $message)
45+
public function testGenerateCustomerTokenInvalidData(string $email, string $password, string $message)
5646
{
57-
$mutation
58-
= <<<MUTATION
59-
mutation {
60-
generateCustomerToken(
61-
email: "{$email}"
62-
password: "{$password}"
63-
) {
64-
token
65-
}
66-
}
67-
MUTATION;
47+
$mutation = $this->getQuery($email, $password);
6848
$this->expectExceptionMessage($message);
6949
$this->graphQlMutation($mutation);
7050
}
@@ -79,17 +59,7 @@ public function testRegenerateCustomerToken()
7959
$email = 'customer@example.com';
8060
$password = 'password';
8161

82-
$mutation
83-
= <<<MUTATION
84-
mutation {
85-
generateCustomerToken(
86-
email: "{$email}"
87-
password: "{$password}"
88-
) {
89-
token
90-
}
91-
}
92-
MUTATION;
62+
$mutation = $this->getQuery($email, $password);
9363

9464
$response1 = $this->graphQlMutation($mutation);
9565
$token1 = $response1['generateCustomerToken']['token'];
@@ -131,4 +101,22 @@ public function dataProviderInvalidCustomerInfo(): array
131101
]
132102
];
133103
}
104+
105+
/**
106+
* @param string $email
107+
* @param string $password
108+
* @return string
109+
*/
110+
private function getQuery(string $email, string $password) : string {
111+
return <<<MUTATION
112+
mutation {
113+
generateCustomerToken(
114+
email: "{$email}"
115+
password: "{$password}"
116+
) {
117+
token
118+
}
119+
}
120+
MUTATION;
121+
}
134122
}

0 commit comments

Comments
 (0)