Skip to content

Commit 52440fb

Browse files
committed
Merge remote-tracking branch 'engcom/ENGCOM-5263-magento-graphql-ce-709' into graphql-develop-prs-fast
2 parents 0e8f149 + e6fd754 commit 52440fb

File tree

6 files changed

+651
-123
lines changed

6 files changed

+651
-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 = 'customer@example.com';
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+
['', 'Syntax Error: Expected Name, found )'],
306+
['input: ""', 'Expected type CustomerAddressInput!, found "".'],
307+
['input: "foo"', '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: 125 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,120 @@ public function testDeleteNonExistCustomerAddress()
150157
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
151158
}
152159

160+
/**
161+
* Delete address with missing ID input.
162+
*
163+
* @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
164+
* @expectedException Exception
165+
* @expectedExceptionMessage Syntax Error: Expected Name, found )
166+
* @throws Exception
167+
*/
168+
public function testDeleteCustomerAddressWithMissingData()
169+
{
170+
$userName = 'customer@example.com';
171+
$password = 'password';
172+
$mutation
173+
= <<<MUTATION
174+
mutation {
175+
deleteCustomerAddress()
176+
}
177+
MUTATION;
178+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
179+
}
180+
181+
/**
182+
* Delete address with incorrect ID input type.
183+
*
184+
* @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
185+
* @expectedException Exception
186+
* @expectedExceptionMessage Expected type Int!, found "".
187+
* @throws Exception
188+
*/
189+
public function testDeleteCustomerAddressWithIncorrectIdType()
190+
{
191+
$this->markTestSkipped(
192+
'Type validation returns wrong message https://github.com/magento/graphql-ce/issues/735'
193+
);
194+
$userName = 'customer@example.com';
195+
$password = 'password';
196+
$mutation
197+
= <<<MUTATION
198+
mutation {
199+
deleteCustomerAddress(id: "string")
200+
}
201+
MUTATION;
202+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
203+
}
204+
205+
/**
206+
* @magentoApiDataFixture Magento/Customer/_files/two_customers.php
207+
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
208+
*
209+
* @expectedException Exception
210+
* @expectedExceptionMessage Current customer does not have permission to address with ID "2"
211+
*/
212+
public function testDeleteAnotherCustomerAddress()
213+
{
214+
$userName = 'customer_two@example.com';
215+
$password = 'password';
216+
$addressId = 2;
217+
218+
$mutation
219+
= <<<MUTATION
220+
mutation {
221+
deleteCustomerAddress(id: {$addressId})
222+
}
223+
MUTATION;
224+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
225+
}
226+
227+
/**
228+
* @magentoApiDataFixture Magento/Customer/_files/inactive_customer.php
229+
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
230+
* @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
231+
*
232+
* @expectedException Exception
233+
* @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily.
234+
*/
235+
public function testDeleteInactiveCustomerAddress()
236+
{
237+
$userName = 'customer@needAconfirmation.com';
238+
$password = 'password';
239+
$addressId = 2;
240+
241+
$mutation
242+
= <<<MUTATION
243+
mutation {
244+
deleteCustomerAddress(id: {$addressId})
245+
}
246+
MUTATION;
247+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
248+
}
249+
250+
/**
251+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
252+
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
253+
*
254+
* @expectedException Exception
255+
* @expectedExceptionMessage The account is locked
256+
*/
257+
public function testDeleteCustomerAddressIfAccountIsLocked()
258+
{
259+
$userName = 'customer@example.com';
260+
$password = 'password';
261+
$addressId = 2;
262+
263+
$this->lockCustomer->execute(1);
264+
265+
$mutation
266+
= <<<MUTATION
267+
mutation {
268+
deleteCustomerAddress(id: {$addressId})
269+
}
270+
MUTATION;
271+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
272+
}
273+
153274
/**
154275
* @param string $email
155276
* @param string $password

0 commit comments

Comments
 (0)