Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 7c5bea3

Browse files
committed
GraphQL-248: Test coverage
1 parent f2b43e1 commit 7c5bea3

File tree

1 file changed

+168
-1
lines changed

1 file changed

+168
-1
lines changed

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

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function setUp()
3535
/**
3636
* @throws \Exception
3737
*/
38-
public function testCreateCustomerAccount()
38+
public function testCreateCustomerAccountWithPassword()
3939
{
4040
$newFirstname = 'Richard';
4141
$newLastname = 'Rowe';
@@ -70,4 +70,171 @@ public function testCreateCustomerAccount()
7070
$this->assertEquals($newEmail, $response['createCustomer']['customer']['email']);
7171
$this->assertEquals(true, $response['createCustomer']['customer']['is_subscribed']);
7272
}
73+
74+
/**
75+
* @throws \Exception
76+
*/
77+
public function testCreateCustomerAccountWithoutPassword()
78+
{
79+
$newFirstname = 'Richard';
80+
$newLastname = 'Rowe';
81+
$newEmail = 'customer_created' . rand(1, 2000000) . '@example.com';
82+
83+
$query = <<<QUERY
84+
mutation {
85+
createCustomer(
86+
input: {
87+
firstname: "{$newFirstname}"
88+
lastname: "{$newLastname}"
89+
email: "{$newEmail}"
90+
is_subscribed: true
91+
}
92+
) {
93+
customer {
94+
id
95+
firstname
96+
lastname
97+
email
98+
is_subscribed
99+
}
100+
}
101+
}
102+
QUERY;
103+
$response = $this->graphQlQuery($query);
104+
105+
$this->assertEquals($newFirstname, $response['createCustomer']['customer']['firstname']);
106+
$this->assertEquals($newLastname, $response['createCustomer']['customer']['lastname']);
107+
$this->assertEquals($newEmail, $response['createCustomer']['customer']['email']);
108+
$this->assertEquals(true, $response['createCustomer']['customer']['is_subscribed']);
109+
}
110+
111+
/**
112+
* @expectedException \Exception
113+
* @expectedExceptionMessage "input" value should be specified
114+
*/
115+
public function testCreateCustomerIfInputDataIsEmpty()
116+
{
117+
$query = <<<QUERY
118+
mutation {
119+
createCustomer(
120+
input: {
121+
122+
}
123+
) {
124+
customer {
125+
id
126+
firstname
127+
lastname
128+
email
129+
is_subscribed
130+
}
131+
}
132+
}
133+
QUERY;
134+
$this->graphQlQuery($query);
135+
}
136+
137+
/**
138+
* @expectedException \Exception
139+
* @expectedExceptionMessage The customer email is missing. Enter and try again.
140+
*/
141+
public function testCreateCustomerIfEmailMissed()
142+
{
143+
$newFirstname = 'Richard';
144+
$newLastname = 'Rowe';
145+
$currentPassword = 'test123#';
146+
147+
$query = <<<QUERY
148+
mutation {
149+
createCustomer(
150+
input: {
151+
firstname: "{$newFirstname}"
152+
lastname: "{$newLastname}"
153+
password: "{$currentPassword}"
154+
is_subscribed: true
155+
}
156+
) {
157+
customer {
158+
id
159+
firstname
160+
lastname
161+
email
162+
is_subscribed
163+
}
164+
}
165+
}
166+
QUERY;
167+
$this->graphQlQuery($query);
168+
}
169+
170+
/**
171+
* @expectedException \Exception
172+
* @expectedExceptionMessage "Email" is not a valid email address.
173+
*/
174+
public function testCreateCustomerIfEmailIsNotValid()
175+
{
176+
$newFirstname = 'Richard';
177+
$newLastname = 'Rowe';
178+
$currentPassword = 'test123#';
179+
$newEmail = 'email';
180+
181+
$query = <<<QUERY
182+
mutation {
183+
createCustomer(
184+
input: {
185+
firstname: "{$newFirstname}"
186+
lastname: "{$newLastname}"
187+
email: "{$newEmail}"
188+
password: "{$currentPassword}"
189+
is_subscribed: true
190+
}
191+
) {
192+
customer {
193+
id
194+
firstname
195+
lastname
196+
email
197+
is_subscribed
198+
}
199+
}
200+
}
201+
QUERY;
202+
$this->graphQlQuery($query);
203+
}
204+
205+
/**
206+
* @expectedException \Exception
207+
* @expectedExceptionMessage Field "test123" is not defined by type CustomerInput.
208+
*/
209+
public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput()
210+
{
211+
$newFirstname = 'Richard';
212+
$newLastname = 'Rowe';
213+
$currentPassword = 'test123#';
214+
$newEmail = 'customer_created' . rand(1, 2000000) . '@example.com';
215+
216+
$query = <<<QUERY
217+
mutation {
218+
createCustomer(
219+
input: {
220+
firstname: "{$newFirstname}"
221+
lastname: "{$newLastname}"
222+
test123: "123test123"
223+
email: "{$newEmail}"
224+
password: "{$currentPassword}"
225+
is_subscribed: true
226+
}
227+
) {
228+
customer {
229+
id
230+
firstname
231+
lastname
232+
email
233+
is_subscribed
234+
}
235+
}
236+
}
237+
QUERY;
238+
$this->graphQlQuery($query);
239+
}
73240
}

0 commit comments

Comments
 (0)