Skip to content

Commit c2c4ecf

Browse files
committed
MAGETWO-81532: Support for Registered customers
- added additional validations
1 parent 0875fa5 commit c2c4ecf

File tree

1 file changed

+81
-12
lines changed

1 file changed

+81
-12
lines changed

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

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
namespace Magento\GraphQl\Customer;
88

9+
use Magento\Customer\Api\AddressRepositoryInterface;
910
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Customer\Api\Data\AddressInterface;
1012
use Magento\Customer\Api\Data\CustomerInterface;
1113
use Magento\TestFramework\ObjectManager;
1214
use Magento\TestFramework\TestCase\GraphQlAbstract;
@@ -18,6 +20,7 @@ class CustomerAuthenticationTest extends GraphQlAbstract
1820
* Verify customers with valid credentials with a customer bearer token
1921
*
2022
* @magentoApiDataFixture Magento/Customer/_files/customer.php
23+
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
2124
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2225
*/
2326

@@ -28,12 +31,28 @@ public function testRegisteredCustomerWithValidCredentials()
2831
{
2932
customer
3033
{
31-
id
32-
website_id
33-
store_id
34+
created_at
35+
group_id
36+
prefix
37+
firstname
38+
middlename
3439
lastname
40+
suffix
41+
email
3542
default_billing
36-
default_shipping
43+
default_shipping
44+
id
45+
addresses{
46+
id
47+
customer_id
48+
region_id
49+
country_id
50+
telephone
51+
postcode
52+
city
53+
firstname
54+
lastname
55+
}
3756
}
3857
}
3958
QUERY;
@@ -49,9 +68,16 @@ public function testRegisteredCustomerWithValidCredentials()
4968
/** @var CustomerRepositoryInterface $customerRepository */
5069
$customerRepository = ObjectManager::getInstance()->get(CustomerRepositoryInterface::class);
5170
$customer = $customerRepository->get('[email protected]');
71+
5272
$response = $this->graphQlQuery($query);
5373
$this->assertArrayHasKey('customer', $response);
74+
$this->assertArrayHasKey('addresses', $response['customer']);
75+
$this->assertTrue(
76+
is_array([$response['customer']['addresses']]),
77+
" Addresses field must be of an array type."
78+
);
5479
$this->assertCustomerFields($customer, $response['customer']);
80+
$this->assertCustomerAddressesFields($customer, $response);
5581
}
5682

5783
/**
@@ -87,12 +113,17 @@ public function testCustomerWithValidCredentialsWithoutToken()
87113
{
88114
customer
89115
{
90-
id
91-
website_id
92-
store_id
116+
created_at
117+
group_id
118+
prefix
119+
firstname
120+
middlename
93121
lastname
122+
suffix
123+
email
94124
default_billing
95-
default_shipping
125+
default_shipping
126+
id
96127
}
97128
}
98129
QUERY;
@@ -115,16 +146,54 @@ public function assertCustomerFields($customer, $actualResponse)
115146
*/
116147
$assertionMap = [
117148
['response_field' => 'id', 'expected_value' => $customer->getId()],
118-
['response_field' => 'website_id', 'expected_value' => $customer->getWebsiteId()],
119-
['response_field' => 'store_id', 'expected_value' => $customer->getStoreId()],
149+
['response_field' => 'created_at', 'expected_value' => $customer->getCreatedAt()],
150+
['response_field' => 'group_id', 'expected_value' => $customer->getGroupId()],
151+
['response_field' => 'prefix', 'expected_value' => $customer->getPrefix()],
152+
['response_field' => 'firstname', 'expected_value' => $customer->getFirstname()],
153+
['response_field' => 'middlename', 'expected_value' => $customer->getMiddlename()],
120154
['response_field' => 'lastname', 'expected_value' => $customer->getLastname()],
121-
['response_field' => 'default_shipping', 'expected_value' => $customer->getDefaultShipping()],
122-
['response_field' => 'default_billing', 'expected_value' => $customer->getDefaultBilling()]
155+
['response_field' => 'suffix', 'expected_value' => $customer->getSuffix()],
156+
['response_field' => 'email', 'expected_value' => $customer->getEmail()],
157+
['response_field' => 'default_shipping', 'expected_value' => (bool)$customer->getDefaultShipping()],
158+
['response_field' => 'default_billing', 'expected_value' => (bool)$customer->getDefaultBilling()],
159+
['response_field' => 'id', 'expected_value' => $customer->getId()]
123160
];
124161

125162
$this->assertResponseFields($actualResponse, $assertionMap);
126163
}
127164

165+
/**
166+
* @param CustomerInterface $customer
167+
* @param array $actualResponse
168+
*/
169+
170+
public function assertCustomerAddressesFields($customer, $actualResponse)
171+
{
172+
/** @var AddressInterface $addresses */
173+
$addresses = $customer->getAddresses();
174+
175+
foreach( $addresses as $addressKey => $addressValue) {
176+
$this->assertNotEmpty($addressValue);
177+
$assertionMap = [
178+
['response_field' => 'id', 'expected_value' => $addresses[$addressKey]->getId()],
179+
['response_field' => 'customer_id', 'expected_value' => $addresses[$addressKey]->getCustomerId()],
180+
['response_field' => 'region_id', 'expected_value' => $addresses[$addressKey]->getRegionId()],
181+
['response_field' => 'country_id', 'expected_value' => $addresses[$addressKey]->getCountryId()],
182+
['response_field' => 'telephone', 'expected_value' => $addresses[$addressKey]->getTelephone()],
183+
['response_field' => 'postcode', 'expected_value' => $addresses[$addressKey]->getPostcode()],
184+
['response_field' => 'city', 'expected_value' => $addresses[$addressKey]->getCity()],
185+
['response_field' => 'firstname', 'expected_value' => $addresses[$addressKey]->getFirstname()],
186+
['response_field' => 'lastname', 'expected_value' => $addresses[$addressKey]->getLastname()]
187+
];
188+
$this->assertResponseFields($actualResponse['customer']['addresses'][$addressKey], $assertionMap);
189+
}
190+
191+
// $addressId = $actualResponse['customer']['addresses']['id'][0];
192+
// $addressRepository = ObjectManager::getInstance()->get(\Magento\Customer\Api\AddressRepositoryInterface::class);
193+
// $customerAddress = $addressRepository->getById(1);
194+
}
195+
196+
128197
/**
129198
* @param array $actualResponse
130199
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]

0 commit comments

Comments
 (0)