From 3e03eec3c0e831c9536be75248b5c5503f481514 Mon Sep 17 00:00:00 2001 From: RomanKis <roman.kis.y@gmail.com> Date: Mon, 16 Sep 2019 16:49:04 +0300 Subject: [PATCH] graphQl-907: [Customer] Deprecate customer_id in CustomerAddress --- .../Model/Customer/Address/ExtractCustomerAddressData.php | 2 ++ .../CustomerGraphQl/Model/Customer/ExtractCustomerData.php | 2 ++ app/code/Magento/CustomerGraphQl/etc/schema.graphqls | 4 ++-- .../Magento/GraphQl/Customer/CreateCustomerAddressTest.php | 4 ++-- .../Magento/GraphQl/Customer/CreateCustomerTest.php | 1 + .../testsuite/Magento/GraphQl/Customer/GetAddressesTest.php | 6 +++--- .../testsuite/Magento/GraphQl/Customer/GetCustomerTest.php | 2 ++ .../Magento/GraphQl/Customer/UpdateCustomerAddressTest.php | 3 +-- 8 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/CustomerGraphQl/Model/Customer/Address/ExtractCustomerAddressData.php b/app/code/Magento/CustomerGraphQl/Model/Customer/Address/ExtractCustomerAddressData.php index a4649bccc02e8..8741bff7aa88d 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Customer/Address/ExtractCustomerAddressData.php +++ b/app/code/Magento/CustomerGraphQl/Model/Customer/Address/ExtractCustomerAddressData.php @@ -125,6 +125,8 @@ public function execute(AddressInterface $address): array } $addressData = array_merge($addressData, $customAttributes); + $addressData['customer_id'] = null; + return $addressData; } } diff --git a/app/code/Magento/CustomerGraphQl/Model/Customer/ExtractCustomerData.php b/app/code/Magento/CustomerGraphQl/Model/Customer/ExtractCustomerData.php index de37482aca056..34359cf9a9e66 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Customer/ExtractCustomerData.php +++ b/app/code/Magento/CustomerGraphQl/Model/Customer/ExtractCustomerData.php @@ -103,6 +103,8 @@ public function execute(CustomerInterface $customer): array $customerData = array_merge($customerData, $customAttributes); $customerData['model'] = $customer; + $customerData['id'] = null; + return $customerData; } } diff --git a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls index d27debdc39c64..4fd7ed7a80349 100644 --- a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls @@ -89,7 +89,7 @@ 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)") @@ -97,7 +97,7 @@ type Customer @doc(description: "Customer defines the customer name and address 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") diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerAddressTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerAddressTest.php index 203e9b5cb42e5..04fb304305250 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerAddressTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerAddressTest.php @@ -43,7 +43,6 @@ protected function setUp() */ public function testCreateCustomerAddress() { - $customerId = 1; $newAddress = [ 'region' => [ 'region' => 'Arizona', @@ -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); } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php index c5714012f38c9..5b3ff041d481b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php @@ -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']); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetAddressesTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetAddressesTest.php index e0c6841b2ea2b..c1573d7dbd8af 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetAddressesTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetAddressesTest.php @@ -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); } @@ -105,7 +105,7 @@ 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(); @@ -113,7 +113,7 @@ public function assertCustomerAddressesFields($customer, $actualResponse) $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()], diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php index 928a263e8531b..b15a799ae7521 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/GetCustomerTest.php @@ -50,6 +50,7 @@ public function testGetCustomer() $query = <<<QUERY query { customer { + id firstname lastname email @@ -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']); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerAddressTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerAddressTest.php index 9840236dc9896..625d027f58d24 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerAddressTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerAddressTest.php @@ -59,7 +59,6 @@ public function testUpdateCustomerAddress() { $userName = 'customer@example.com'; $password = 'password'; - $customerId = 1; $addressId = 1; $mutation = $this->getMutation($addressId); @@ -67,7 +66,7 @@ public function testUpdateCustomerAddress() $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);