7
7
8
8
namespace Magento \GraphQl \Customer ;
9
9
10
+ use Exception ;
10
11
use Magento \Customer \Api \CustomerRepositoryInterface ;
11
12
use Magento \Customer \Api \AddressRepositoryInterface ;
12
13
use Magento \TestFramework \Helper \Bootstrap ;
@@ -33,13 +34,19 @@ class DeleteCustomerAddressTest extends GraphQlAbstract
33
34
*/
34
35
private $ addressRepository ;
35
36
37
+ /**
38
+ * @var LockCustomer
39
+ */
40
+ private $ lockCustomer ;
41
+
36
42
protected function setUp ()
37
43
{
38
44
parent ::setUp ();
39
45
40
46
$ this ->customerTokenService = Bootstrap::getObjectManager ()->get (CustomerTokenServiceInterface::class);
41
47
$ this ->customerRepository = Bootstrap::getObjectManager ()->get (CustomerRepositoryInterface::class);
42
48
$ this ->addressRepository = Bootstrap::getObjectManager ()->get (AddressRepositoryInterface::class);
49
+ $ this ->lockCustomer = Bootstrap::getObjectManager ()->get (LockCustomer::class);
43
50
}
44
51
45
52
/**
@@ -64,7 +71,7 @@ public function testDeleteCustomerAddress()
64
71
}
65
72
66
73
/**
67
- * @expectedException \ Exception
74
+ * @expectedException Exception
68
75
* @expectedExceptionMessage The current customer isn't authorized.
69
76
*/
70
77
public function testDeleteCustomerAddressIfUserIsNotAuthorized ()
@@ -83,7 +90,7 @@ public function testDeleteCustomerAddressIfUserIsNotAuthorized()
83
90
* @magentoApiDataFixture Magento/Customer/_files/customer.php
84
91
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
85
92
*
86
- * @expectedException \ Exception
93
+ * @expectedException Exception
87
94
* @expectedExceptionMessage Customer Address 2 is set as default shipping address and can not be deleted
88
95
*/
89
96
public function testDeleteDefaultShippingCustomerAddress ()
@@ -109,7 +116,7 @@ public function testDeleteDefaultShippingCustomerAddress()
109
116
* @magentoApiDataFixture Magento/Customer/_files/customer.php
110
117
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
111
118
*
112
- * @expectedException \ Exception
119
+ * @expectedException Exception
113
120
* @expectedExceptionMessage Customer Address 2 is set as default billing address and can not be deleted
114
121
*/
115
122
public function testDeleteDefaultBillingCustomerAddress ()
@@ -134,7 +141,7 @@ public function testDeleteDefaultBillingCustomerAddress()
134
141
/**
135
142
* @magentoApiDataFixture Magento/Customer/_files/customer.php
136
143
*
137
- * @expectedException \ Exception
144
+ * @expectedException Exception
138
145
* @expectedExceptionMessage Could not find a address with ID "9999"
139
146
*/
140
147
public function testDeleteNonExistCustomerAddress ()
@@ -150,6 +157,111 @@ public function testDeleteNonExistCustomerAddress()
150
157
$ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password ));
151
158
}
152
159
160
+ /**
161
+ * Delete address with invalid ID
162
+ *
163
+ * @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
164
+ * @dataProvider invalidIdDataProvider
165
+ * @param string $addressId
166
+ * @param $exceptionMessage
167
+ * @throws Exception
168
+ */
169
+ public function testCreateCustomerAddressWithInvalidId ($ addressId , $ exceptionMessage )
170
+ {
171
+
172
+ $ password = 'password ' ;
173
+ $ mutation
174
+ = <<<MUTATION
175
+ mutation {
176
+ deleteCustomerAddress( $ addressId)
177
+ }
178
+ MUTATION ;
179
+
180
+ self ::expectException (Exception::class);
181
+ self ::expectExceptionMessage ($ exceptionMessage );
182
+ $ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password )); }
183
+
184
+ /**
185
+ * @return array
186
+ */
187
+ public function invalidIdDataProvider ()
188
+ {
189
+ return [
190
+ ['' , 'GraphQL response contains errors: Syntax Error: Expected Name, found ) ' ],
191
+ //TODO: why here the internal server error being trowed?
192
+ ['id: "" ' , 'GraphQL response contains errors: Internal server error ' ]
193
+ ];
194
+ }
195
+
196
+ /**
197
+ * @magentoApiDataFixture Magento/Customer/_files/two_customers.php
198
+ * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
199
+ *
200
+ * @expectedException Exception
201
+ * @expectedExceptionMessage GraphQL response contains errors: Current customer does not have permission to address with ID "2"
202
+ */
203
+ public function testDeleteAnotherCustomerAddress ()
204
+ {
205
+
206
+ $ password = 'password ' ;
207
+ $ addressId = 2 ;
208
+
209
+ $ mutation
210
+ = <<<MUTATION
211
+ mutation {
212
+ deleteCustomerAddress(id: {$ addressId })
213
+ }
214
+ MUTATION ;
215
+ $ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password ));
216
+ }
217
+
218
+ /**
219
+ * @magentoApiDataFixture Magento/Customer/_files/inactive_customer.php
220
+ * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
221
+ * @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
222
+ *
223
+ * @expectedException Exception
224
+ * @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.
225
+ */
226
+ public function testDeleteInactiveCustomerAddress ()
227
+ {
228
+
229
+ $ password = 'password ' ;
230
+ $ addressId = 2 ;
231
+
232
+ $ mutation
233
+ = <<<MUTATION
234
+ mutation {
235
+ deleteCustomerAddress(id: {$ addressId })
236
+ }
237
+ MUTATION ;
238
+ $ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password ));
239
+ }
240
+
241
+ /**
242
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
243
+ * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
244
+ *
245
+ * @expectedException Exception
246
+ * @expectedExceptionMessage GraphQL response contains errors: The account is locked
247
+ */
248
+ public function testDeleteCustomerAddressIfAccountIsLocked ()
249
+ {
250
+
251
+ $ password = 'password ' ;
252
+ $ addressId = 2 ;
253
+
254
+ $ this ->lockCustomer ->execute (1 );
255
+
256
+ $ mutation
257
+ = <<<MUTATION
258
+ mutation {
259
+ deleteCustomerAddress(id: {$ addressId })
260
+ }
261
+ MUTATION ;
262
+ $ this ->graphQlMutation ($ mutation , [], '' , $ this ->getCustomerAuthHeaders ($ userName , $ password ));
263
+ }
264
+
153
265
/**
154
266
* @param string $email
155
267
* @param string $password
0 commit comments