Skip to content

Commit

Permalink
ENGCOM-5911: graphQl-907: [Customer] Deprecate customer_id in Custome…
Browse files Browse the repository at this point in the history
…rAddress #935
  • Loading branch information
lenaorobei authored Sep 20, 2019
2 parents 062924b + 888886d commit ecfb17d
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public function execute(AddressInterface $address): array
}
$addressData = array_merge($addressData, $customAttributes);

$addressData['customer_id'] = null;

return $addressData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public function execute(CustomerInterface $customer): array
//Field is deprecated and should not be exposed on storefront.
$customerData['group_id'] = null;
$customerData['model'] = $customer;
$customerData['id'] = null;

return $customerData;
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/CustomerGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ type Customer @doc(description: "Customer defines the customer name and address
default_shipping: String @doc(description: "The ID assigned to the shipping address")
dob: String @doc(description: "The customer's date of birth")
taxvat: String @doc(description: "The customer's Tax/VAT number (for corporate customers)")
id: Int @doc(description: "The ID assigned to the customer")
id: Int @doc(description: "The ID assigned to the customer") @deprecated(reason: "id is not needed as part of Customer because on server side it can be identified based on customer token used for authentication. There is no need to know customer ID on the client side.")
is_subscribed: Boolean @doc(description: "Indicates whether the customer is subscribed to the company's newsletter") @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\IsSubscribed")
addresses: [CustomerAddress] @doc(description: "An array containing the customer's shipping and billing addresses") @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\CustomerAddresses")
gender: Int @doc(description: "The customer's gender(Male - 1, Female - 2)")
}

type CustomerAddress @doc(description: "CustomerAddress contains detailed information about a customer's billing and shipping addresses"){
id: Int @doc(description: "The ID assigned to the address object")
customer_id: Int @doc(description: "The customer ID")
customer_id: Int @doc(description: "The customer ID") @deprecated(reason: "customer_id is not needed as part of CustomerAddress, address ID (id) is unique identifier for the addresses.")
region: CustomerAddressRegion @doc(description: "An object containing the region name, region code, and region ID")
region_id: Int @doc(description: "A number that uniquely identifies the state, province, or other area")
country_id: String @doc(description: "The customer's country")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ protected function setUp()
*/
public function testCreateCustomerAddress()
{
$customerId = 1;
$newAddress = [
'region' => [
'region' => 'Arizona',
Expand Down Expand Up @@ -124,11 +123,12 @@ public function testCreateCustomerAddress()
$response = $this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
$this->assertArrayHasKey('createCustomerAddress', $response);
$this->assertArrayHasKey('customer_id', $response['createCustomerAddress']);
$this->assertEquals($customerId, $response['createCustomerAddress']['customer_id']);
$this->assertEquals(null, $response['createCustomerAddress']['customer_id']);
$this->assertArrayHasKey('id', $response['createCustomerAddress']);

$address = $this->addressRepository->getById($response['createCustomerAddress']['id']);
$this->assertEquals($address->getId(), $response['createCustomerAddress']['id']);
$address->setCustomerId(null);
$this->assertCustomerAddressesFields($address, $response['createCustomerAddress']);
$this->assertCustomerAddressesFields($address, $newAddress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function testCreateCustomerAccountWithPassword()
QUERY;
$response = $this->graphQlMutation($query);

$this->assertEquals(null, $response['createCustomer']['customer']['id']);
$this->assertEquals($newFirstname, $response['createCustomer']['customer']['firstname']);
$this->assertEquals($newLastname, $response['createCustomer']['customer']['lastname']);
$this->assertEquals($newEmail, $response['createCustomer']['customer']['email']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testGetCustomerWithAddresses()
is_array([$response['customer']['addresses']]),
" Addresses field must be of an array type."
);
self::assertEquals($customer->getId(), $response['customer']['id']);
self::assertEquals(null, $response['customer']['id']);
$this->assertCustomerAddressesFields($customer, $response);
}

Expand Down Expand Up @@ -105,15 +105,15 @@ public function testGetCustomerAddressIfUserIsNotAuthorized()
* @param CustomerInterface $customer
* @param array $actualResponse
*/
public function assertCustomerAddressesFields($customer, $actualResponse)
private function assertCustomerAddressesFields($customer, $actualResponse)
{
/** @var AddressInterface $addresses */
$addresses = $customer->getAddresses();
foreach ($addresses as $addressKey => $addressValue) {
$this->assertNotEmpty($addressValue);
$assertionMap = [
['response_field' => 'id', 'expected_value' => $addresses[$addressKey]->getId()],
['response_field' => 'customer_id', 'expected_value' => $addresses[$addressKey]->getCustomerId()],
['response_field' => 'customer_id', 'expected_value' => 0],
['response_field' => 'region_id', 'expected_value' => $addresses[$addressKey]->getRegionId()],
['response_field' => 'country_id', 'expected_value' => $addresses[$addressKey]->getCountryId()],
['response_field' => 'telephone', 'expected_value' => $addresses[$addressKey]->getTelephone()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function testGetCustomer()
$query = <<<QUERY
query {
customer {
id
firstname
lastname
email
Expand All @@ -58,6 +59,7 @@ public function testGetCustomer()
QUERY;
$response = $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));

$this->assertEquals(null, $response['customer']['id']);
$this->assertEquals('John', $response['customer']['firstname']);
$this->assertEquals('Smith', $response['customer']['lastname']);
$this->assertEquals($currentEmail, $response['customer']['email']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ public function testUpdateCustomerAddress()
{
$userName = 'customer@example.com';
$password = 'password';
$customerId = 1;
$addressId = 1;

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

$response = $this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
$this->assertArrayHasKey('updateCustomerAddress', $response);
$this->assertArrayHasKey('customer_id', $response['updateCustomerAddress']);
$this->assertEquals($customerId, $response['updateCustomerAddress']['customer_id']);
$this->assertEquals(null, $response['updateCustomerAddress']['customer_id']);
$this->assertArrayHasKey('id', $response['updateCustomerAddress']);

$address = $this->addressRepository->getById($addressId);
Expand Down

0 comments on commit ecfb17d

Please sign in to comment.