-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LYNX-120: Add custom_attributes to createCustomerV2 mutation (#99)
* LYNX-120: Initial commit * LYNX-120: Create custom attributes in createCustomerV2 mutation + test * LYNX-120: fix test * LYNX-120: fix test * LYNX-120: Final implementation + tests * LYNX-120: Refactoring * LYNX-120: Refactoring * LYNX-120: Refactoring * LYNX-120: Refactoring * LYNX-120: Refactoring; CR changes * LYNX-120: Refactoring; CR changes * LYNX-120: Refactoring; CR changes * LYNX-120: Refactoring; CR changes * LYNX-120: CR changes * LYNX-120: CR changes * LYNX-120: CR changes * LYNX-120: CR changes * LYNX-120: Fix broken tests
- Loading branch information
Showing
5 changed files
with
231 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
...unctional/testsuite/Magento/GraphQl/Customer/CreateCustomerV2WithCustomAttributesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Customer; | ||
|
||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\Customer\Api\CustomerMetadataInterface; | ||
use Magento\TestFramework\Fixture\DataFixture; | ||
use Magento\Customer\Test\Fixture\CustomerAttribute; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
use Magento\Framework\Registry; | ||
|
||
/** | ||
* Tests for create customer (V2) | ||
*/ | ||
class CreateCustomerV2WithCustomAttributesTest extends GraphQlAbstract | ||
{ | ||
/** | ||
* @var Registry | ||
*/ | ||
private $registry; | ||
|
||
/** | ||
* @var CustomerRepositoryInterface | ||
*/ | ||
private $customerRepository; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->registry = Bootstrap::getObjectManager()->get(Registry::class); | ||
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
#[ | ||
DataFixture( | ||
CustomerAttribute::class, | ||
[ | ||
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, | ||
'sort_order' => 1, | ||
'attribute_code' => 'custom_attribute_one', | ||
'attribute_set_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, | ||
'attribute_group_id' => 1 | ||
], | ||
'attribute1' | ||
), | ||
DataFixture( | ||
CustomerAttribute::class, | ||
[ | ||
'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, | ||
'sort_order' => 2, | ||
'attribute_code' => 'custom_attribute_two', | ||
'attribute_set_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, | ||
'attribute_group_id' => 1 | ||
], | ||
'attribute2' | ||
) | ||
] | ||
public function testCreateCustomerAccountWithCustomAttributes() | ||
{ | ||
$query = <<<QUERY | ||
mutation { | ||
createCustomerV2( | ||
input: { | ||
firstname: "Adam" | ||
lastname: "Smith" | ||
email: "[email protected]" | ||
password: "test123#" | ||
custom_attributes: [ | ||
{ | ||
attribute_code: "custom_attribute_one", | ||
value: "value_one" | ||
}, | ||
{ | ||
attribute_code: "custom_attribute_two", | ||
value: "value_two" | ||
} | ||
] | ||
} | ||
) { | ||
customer { | ||
firstname | ||
lastname | ||
custom_attributes { | ||
uid | ||
code | ||
... on AttributeValue { | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
$response = $this->graphQlMutation($query); | ||
$this->assertEquals( | ||
[ | ||
'createCustomerV2' => | ||
[ | ||
'customer' => | ||
[ | ||
'firstname' => 'Adam', | ||
'lastname' => 'Smith', | ||
'email' => '[email protected]', | ||
'custom_attributes' => | ||
[ | ||
0 => | ||
[ | ||
'uid' => 'Y3VzdG9tZXIvY3VzdG9tX2F0dHJpYnV0ZV9vbmU=', | ||
'code' => 'custom_attribute_one', | ||
'value' => 'value_one', | ||
], | ||
1 => | ||
[ | ||
'uid' => 'Y3VzdG9tZXIvY3VzdG9tX2F0dHJpYnV0ZV90d28=', | ||
'code' => 'custom_attribute_two', | ||
'value' => 'value_two', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
$response | ||
); | ||
} | ||
|
||
public function testCreateCustomerAccountWithNonExistingCustomAttribute() | ||
{ | ||
$query = <<<QUERY | ||
mutation { | ||
createCustomerV2( | ||
input: { | ||
firstname: "John" | ||
lastname: "Doe" | ||
email: "[email protected]" | ||
password: "test123#" | ||
custom_attributes: [ | ||
{ | ||
attribute_code: "non_existing_custom_attribute", | ||
value: "void" | ||
} | ||
] | ||
} | ||
) { | ||
customer { | ||
firstname | ||
lastname | ||
custom_attributes { | ||
uid | ||
code | ||
... on AttributeValue { | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
$response = $this->graphQlMutation($query); | ||
$this->assertEquals( | ||
[ | ||
'createCustomerV2' => | ||
[ | ||
'customer' => | ||
[ | ||
'firstname' => 'John', | ||
'lastname' => 'Doe', | ||
'email' => '[email protected]', | ||
'custom_attributes' => [] | ||
], | ||
], | ||
], | ||
$response | ||
); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
$email1 = '[email protected]'; | ||
$email2 = '[email protected]'; | ||
try { | ||
$customer1 = $this->customerRepository->get($email1); | ||
$customer2 = $this->customerRepository->get($email2); | ||
} catch (\Exception $exception) { | ||
return; | ||
} | ||
|
||
$this->registry->unregister('isSecureArea'); | ||
$this->registry->register('isSecureArea', true); | ||
$this->customerRepository->delete($customer1); | ||
$this->customerRepository->delete($customer2); | ||
$this->registry->unregister('isSecureArea'); | ||
$this->registry->register('isSecureArea', false); | ||
parent::tearDown(); | ||
} | ||
} |