Skip to content

Commit 52fee67

Browse files
author
Vitaliy Boyko
committed
graphQl-674: extended test coverage for customer addresses
1 parent 211dd25 commit 52fee67

File tree

6 files changed

+593
-123
lines changed

6 files changed

+593
-123
lines changed

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Customer;
99

10+
use Exception;
1011
use Magento\Customer\Api\AddressRepositoryInterface;
1112
use Magento\Customer\Api\Data\AddressInterface;
1213
use Magento\TestFramework\Helper\Bootstrap;
@@ -133,7 +134,7 @@ public function testCreateCustomerAddress()
133134
}
134135

135136
/**
136-
* @expectedException \Exception
137+
* @expectedException Exception
137138
* @expectedExceptionMessage The current customer isn't authorized.
138139
*/
139140
public function testCreateCustomerAddressIfUserIsNotAuthorized()
@@ -169,7 +170,7 @@ public function testCreateCustomerAddressIfUserIsNotAuthorized()
169170
* with missing required Firstname attribute
170171
*
171172
* @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
172-
* @expectedException \Exception
173+
* @expectedException Exception
173174
* @expectedExceptionMessage Required parameters are missing: firstname
174175
*/
175176
public function testCreateCustomerAddressWithMissingAttribute()
@@ -267,6 +268,46 @@ public function testCreateCustomerAddressWithRedundantStreetLine()
267268
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
268269
}
269270

271+
/**
272+
* Create new address with invalid input
273+
*
274+
* @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
275+
* @dataProvider invalidInputDataProvider
276+
* @param string $input
277+
* @param $exceptionMessage
278+
* @throws Exception
279+
*/
280+
public function testCreateCustomerAddressWithInvalidInput($input, $exceptionMessage)
281+
{
282+
$mutation
283+
= <<<MUTATION
284+
mutation {
285+
createCustomerAddress($input) {
286+
id
287+
}
288+
}
289+
MUTATION;
290+
291+
$userName = '[email protected]';
292+
$password = 'password';
293+
294+
self::expectException(Exception::class);
295+
self::expectExceptionMessage($exceptionMessage);
296+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
297+
}
298+
299+
/**
300+
* @return array
301+
*/
302+
public function invalidInputDataProvider()
303+
{
304+
return [
305+
['', 'GraphQL response contains errors: Syntax Error: Expected Name, found )'],
306+
['input: ""', 'GraphQL response contains errors: Expected type CustomerAddressInput!, found "".'],
307+
['input: "foo"', 'GraphQL response contains errors: Expected type CustomerAddressInput!, found "foo".']
308+
];
309+
}
310+
270311
/**
271312
* Verify the fields for Customer address
272313
*

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

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Customer;
99

10+
use Exception;
1011
use Magento\Customer\Api\CustomerRepositoryInterface;
1112
use Magento\Customer\Api\AddressRepositoryInterface;
1213
use Magento\TestFramework\Helper\Bootstrap;
@@ -33,13 +34,19 @@ class DeleteCustomerAddressTest extends GraphQlAbstract
3334
*/
3435
private $addressRepository;
3536

37+
/**
38+
* @var LockCustomer
39+
*/
40+
private $lockCustomer;
41+
3642
protected function setUp()
3743
{
3844
parent::setUp();
3945

4046
$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
4147
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
4248
$this->addressRepository = Bootstrap::getObjectManager()->get(AddressRepositoryInterface::class);
49+
$this->lockCustomer = Bootstrap::getObjectManager()->get(LockCustomer::class);
4350
}
4451

4552
/**
@@ -64,7 +71,7 @@ public function testDeleteCustomerAddress()
6471
}
6572

6673
/**
67-
* @expectedException \Exception
74+
* @expectedException Exception
6875
* @expectedExceptionMessage The current customer isn't authorized.
6976
*/
7077
public function testDeleteCustomerAddressIfUserIsNotAuthorized()
@@ -83,7 +90,7 @@ public function testDeleteCustomerAddressIfUserIsNotAuthorized()
8390
* @magentoApiDataFixture Magento/Customer/_files/customer.php
8491
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
8592
*
86-
* @expectedException \Exception
93+
* @expectedException Exception
8794
* @expectedExceptionMessage Customer Address 2 is set as default shipping address and can not be deleted
8895
*/
8996
public function testDeleteDefaultShippingCustomerAddress()
@@ -109,7 +116,7 @@ public function testDeleteDefaultShippingCustomerAddress()
109116
* @magentoApiDataFixture Magento/Customer/_files/customer.php
110117
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
111118
*
112-
* @expectedException \Exception
119+
* @expectedException Exception
113120
* @expectedExceptionMessage Customer Address 2 is set as default billing address and can not be deleted
114121
*/
115122
public function testDeleteDefaultBillingCustomerAddress()
@@ -134,7 +141,7 @@ public function testDeleteDefaultBillingCustomerAddress()
134141
/**
135142
* @magentoApiDataFixture Magento/Customer/_files/customer.php
136143
*
137-
* @expectedException \Exception
144+
* @expectedException Exception
138145
* @expectedExceptionMessage Could not find a address with ID "9999"
139146
*/
140147
public function testDeleteNonExistCustomerAddress()
@@ -150,6 +157,111 @@ public function testDeleteNonExistCustomerAddress()
150157
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
151158
}
152159

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+
$userName = '[email protected]';
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+
$userName = '[email protected]';
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+
$userName = '[email protected]';
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+
$userName = '[email protected]';
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+
153265
/**
154266
* @param string $email
155267
* @param string $password

0 commit comments

Comments
 (0)