Skip to content

Commit d7c302b

Browse files
committed
magento/graphql-ce#674: [Test coverage] Customer addresses
1 parent 52fee67 commit d7c302b

File tree

4 files changed

+114
-42
lines changed

4 files changed

+114
-42
lines changed

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

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,47 +158,56 @@ public function testDeleteNonExistCustomerAddress()
158158
}
159159

160160
/**
161-
* Delete address with invalid ID
161+
* Delete address with missing ID input.
162162
*
163163
* @magentoApiDataFixture Magento/Customer/_files/customer_without_addresses.php
164-
* @dataProvider invalidIdDataProvider
165-
* @param string $addressId
166-
* @param $exceptionMessage
164+
* @expectedException Exception
165+
* @expectedExceptionMessage Syntax Error: Expected Name, found )
167166
* @throws Exception
168167
*/
169-
public function testCreateCustomerAddressWithInvalidId($addressId, $exceptionMessage)
168+
public function testDeleteCustomerAddressWithMissingData()
170169
{
171170
$userName = 'customer@example.com';
172171
$password = 'password';
173172
$mutation
174173
= <<<MUTATION
175174
mutation {
176-
deleteCustomerAddress($addressId)
175+
deleteCustomerAddress()
177176
}
178177
MUTATION;
179-
180-
self::expectException(Exception::class);
181-
self::expectExceptionMessage($exceptionMessage);
182-
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password)); }
178+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
179+
}
183180

184181
/**
185-
* @return array
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
186188
*/
187-
public function invalidIdDataProvider()
189+
public function testDeleteCustomerAddressWithIncorrectIdType()
188190
{
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-
];
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));
194203
}
195204

196205
/**
197206
* @magentoApiDataFixture Magento/Customer/_files/two_customers.php
198207
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
199208
*
200209
* @expectedException Exception
201-
* @expectedExceptionMessage GraphQL response contains errors: Current customer does not have permission to address with ID "2"
210+
* @expectedExceptionMessage Current customer does not have permission to address with ID "2"
202211
*/
203212
public function testDeleteAnotherCustomerAddress()
204213
{
@@ -221,7 +230,7 @@ public function testDeleteAnotherCustomerAddress()
221230
* @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
222231
*
223232
* @expectedException Exception
224-
* @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.
233+
* @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily.
225234
*/
226235
public function testDeleteInactiveCustomerAddress()
227236
{
@@ -243,7 +252,7 @@ public function testDeleteInactiveCustomerAddress()
243252
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
244253
*
245254
* @expectedException Exception
246-
* @expectedExceptionMessage GraphQL response contains errors: The account is locked
255+
* @expectedExceptionMessage The account is locked
247256
*/
248257
public function testDeleteCustomerAddressIfAccountIsLocked()
249258
{

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Magento\TestFramework\TestCase\GraphQlAbstract;
1717
use Magento\Integration\Api\CustomerTokenServiceInterface;
1818

19+
/**
20+
* Test for customer address retrieval.
21+
*/
1922
class GetAddressesTest extends GraphQlAbstract
2023
{
2124
/**
@@ -68,7 +71,7 @@ public function testGetCustomerWithAddresses()
6871
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
6972
* @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
7073
* @expectedException Exception
71-
* @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.
74+
* @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily.
7275
*/
7376
public function testGetCustomerAddressIfAccountIsNotConfirmed()
7477
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public function __construct(CustomerRegistry $customerRegistry, CustomerAuthUpda
3636
}
3737

3838
/**
39+
* Lock customer by ID.
40+
*
3941
* @param int $customerId
42+
*
4043
* @return void
4144
*/
4245
public function execute(int $customerId): void

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

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,25 @@ private function assertCustomerAddressesFields(AddressInterface $address, $actua
164164
}
165165

166166
/**
167-
* Update address with invalid ID
167+
* Update address with missing ID input.
168168
*
169169
* @magentoApiDataFixture Magento/Customer/_files/customer.php
170170
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
171171
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
172-
* @dataProvider invalidIdDataProvider
173-
* @param string $addressId
174-
* @param $exceptionMessage
175172
*/
176-
public function testCreateCustomerAddressWithInvalidId($addressId, $exceptionMessage)
173+
public function testUpdateCustomerAddressWithMissingId()
177174
{
178175
$userName = 'customer@example.com';
179176
$password = 'password';
180177

181178
$updateAddress = $this->getAddressData();
182-
$defaultShippingText = $updateAddress['default_shipping'] ? "true": "false";
183-
$defaultBillingText = $updateAddress['default_billing'] ? "true": "false";
179+
$defaultShippingText = $updateAddress['default_shipping'] ? 'true' : 'false';
180+
$defaultBillingText = $updateAddress['default_billing'] ? 'true' : 'false';
184181

185182
$mutation
186183
= <<<MUTATION
187184
mutation {
188-
updateCustomerAddress($addressId, input: {
185+
updateCustomerAddress(, input: {
189186
region: {
190187
region: "{$updateAddress['region']['region']}"
191188
region_id: {$updateAddress['region']['region_id']}
@@ -212,17 +209,76 @@ public function testCreateCustomerAddressWithInvalidId($addressId, $exceptionMes
212209
}
213210
MUTATION;
214211

215-
self::expectException(Exception::class);
216-
self::expectExceptionMessage($exceptionMessage);
217-
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password)); }
212+
$this->expectException(Exception::class);
213+
$this->expectExceptionMessage(
214+
'GraphQL response contains errors: Field "updateCustomerAddress" argument "id" of type "Int!" is ' .
215+
'required but not provided.'
216+
);
217+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
218+
}
219+
220+
/**
221+
* Update address with invalid ID input.
222+
*
223+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
224+
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
225+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
226+
*/
227+
public function testUpdateCustomerAddressWithInvalidIdType()
228+
{
229+
$this->markTestSkipped(
230+
'Type validation returns wrong message https://github.com/magento/graphql-ce/issues/735'
231+
);
232+
$userName = 'customer@example.com';
233+
$password = 'password';
234+
235+
$updateAddress = $this->getAddressData();
236+
$defaultShippingText = $updateAddress['default_shipping'] ? 'true' : 'false';
237+
$defaultBillingText = $updateAddress['default_billing'] ? 'true' : 'false';
238+
239+
$mutation
240+
= <<<MUTATION
241+
mutation {
242+
updateCustomerAddress(id: "", input: {
243+
region: {
244+
region: "{$updateAddress['region']['region']}"
245+
region_id: {$updateAddress['region']['region_id']}
246+
region_code: "{$updateAddress['region']['region_code']}"
247+
}
248+
country_id: {$updateAddress['country_id']}
249+
street: ["{$updateAddress['street'][0]}","{$updateAddress['street'][1]}"]
250+
company: "{$updateAddress['company']}"
251+
telephone: "{$updateAddress['telephone']}"
252+
fax: "{$updateAddress['fax']}"
253+
postcode: "{$updateAddress['postcode']}"
254+
city: "{$updateAddress['city']}"
255+
firstname: "{$updateAddress['firstname']}"
256+
lastname: "{$updateAddress['lastname']}"
257+
middlename: "{$updateAddress['middlename']}"
258+
prefix: "{$updateAddress['prefix']}"
259+
suffix: "{$updateAddress['suffix']}"
260+
vat_id: "{$updateAddress['vat_id']}"
261+
default_shipping: {$defaultShippingText}
262+
default_billing: {$defaultBillingText}
263+
}) {
264+
id
265+
}
266+
}
267+
MUTATION;
268+
269+
$this->expectException(Exception::class);
270+
$this->expectExceptionMessage('Expected type Int!, found ""');
271+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
272+
}
218273

219274
/**
220275
* @return array
221276
*/
222277
public function invalidIdDataProvider()
223278
{
224279
return [
225-
['', 'GraphQL response contains errors: Field "updateCustomerAddress" argument "id" of type "Int!" is required but not provided.'],
280+
['', 'GraphQL response contains errors: Field "updateCustomerAddress" argument "id" of type "Int!" ' .
281+
'is required but not provided.'],
226282
//TODO: why here the internal server error being trowed?
227283
['id: ""', 'GraphQL response contains errors: Internal server error']
228284
];
@@ -235,9 +291,9 @@ public function invalidIdDataProvider()
235291
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
236292
* @dataProvider invalidInputDataProvider
237293
* @param string $input
238-
* @param $exceptionMessage
294+
* @param string $exceptionMessage
239295
*/
240-
public function testUpdateCustomerAddressWithInvalidInput($input, $exceptionMessage)
296+
public function testUpdateCustomerAddressWithInvalidInput(string $input, string $exceptionMessage)
241297
{
242298
$userName = 'customer@example.com';
243299
$password = 'password';
@@ -252,9 +308,10 @@ public function testUpdateCustomerAddressWithInvalidInput($input, $exceptionMess
252308
}
253309
MUTATION;
254310

255-
self::expectException(Exception::class);
256-
self::expectExceptionMessage($exceptionMessage);
257-
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password)); }
311+
$this->expectException(Exception::class);
312+
$this->expectExceptionMessage($exceptionMessage);
313+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
314+
}
258315

259316
/**
260317
* @return array
@@ -282,14 +339,14 @@ public function testUpdateNotExistingCustomerAddress()
282339

283340
$mutation = $this->getMutation($addressId);
284341

285-
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
342+
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
286343
}
287344

288345
/**
289346
* @magentoApiDataFixture Magento/Customer/_files/two_customers.php
290347
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
291348
* @expectedException Exception
292-
* @expectedExceptionMessage GraphQL response contains errors: Current customer does not have permission to address with ID "1"
349+
* @expectedExceptionMessage Current customer does not have permission to address with ID "1"
293350
*/
294351
public function testUpdateAnotherCustomerAddress()
295352
{
@@ -307,7 +364,7 @@ public function testUpdateAnotherCustomerAddress()
307364
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
308365
* @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
309366
* @expectedException Exception
310-
* @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later.
367+
* @expectedExceptionMessage The account sign-in was incorrect or your account is disabled temporarily.
311368
*/
312369
public function testUpdateCustomerAddressIfAccountIsNotConfirmed()
313370
{
@@ -324,7 +381,7 @@ public function testUpdateCustomerAddressIfAccountIsNotConfirmed()
324381
* @magentoApiDataFixture Magento/Customer/_files/customer.php
325382
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
326383
* @expectedException Exception
327-
* @expectedExceptionMessage GraphQL response contains errors: The account is locked.
384+
* @expectedExceptionMessage The account is locked.
328385
*/
329386
public function testUpdateCustomerAddressIfAccountIsLocked()
330387
{

0 commit comments

Comments
 (0)