|
9 | 9 | use Commercetools\Core\ApiTestCase; |
10 | 10 | use Commercetools\Core\Model\Common\Address; |
11 | 11 | use Commercetools\Core\Model\Common\AddressCollection; |
| 12 | +use Commercetools\Core\Model\Customer\Customer; |
12 | 13 | use Commercetools\Core\Model\Customer\CustomerDraft; |
13 | 14 | use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft; |
14 | 15 | use Commercetools\Core\Model\CustomField\FieldContainer; |
|
28 | 29 | use Commercetools\Core\Request\Customers\Command\CustomerSetDefaultShippingAddressAction; |
29 | 30 | use Commercetools\Core\Request\Customers\Command\CustomerSetExternalIdAction; |
30 | 31 | use Commercetools\Core\Request\Customers\Command\CustomerSetFirstNameAction; |
| 32 | +use Commercetools\Core\Request\Customers\Command\CustomerSetKeyAction; |
31 | 33 | use Commercetools\Core\Request\Customers\Command\CustomerSetLastNameAction; |
32 | 34 | use Commercetools\Core\Request\Customers\Command\CustomerSetLocaleAction; |
33 | 35 | use Commercetools\Core\Request\Customers\Command\CustomerSetMiddleNameAction; |
|
36 | 38 | use Commercetools\Core\Request\Customers\Command\CustomerSetVatIdAction; |
37 | 39 | use Commercetools\Core\Request\Customers\CustomerCreateRequest; |
38 | 40 | use Commercetools\Core\Request\Customers\CustomerDeleteRequest; |
| 41 | +use Commercetools\Core\Request\Customers\CustomerUpdateByKeyRequest; |
39 | 42 | use Commercetools\Core\Request\Customers\CustomerUpdateRequest; |
40 | 43 | use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction; |
41 | 44 | use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction; |
| 45 | +use function GuzzleHttp\Psr7\str; |
42 | 46 |
|
43 | 47 | class CustomerUpdateRequestTest extends ApiTestCase |
44 | 48 | { |
@@ -70,6 +74,46 @@ protected function createCustomer(CustomerDraft $draft) |
70 | 74 | return $result->getCustomer(); |
71 | 75 | } |
72 | 76 |
|
| 77 | + public function testUpdateByKey() |
| 78 | + { |
| 79 | + $draft = $this->getDraft('update-by-key'); |
| 80 | + $draft->setKey('test-'. $this->getTestRun()); |
| 81 | + $customer = $this->createCustomer($draft); |
| 82 | + |
| 83 | + $firstName = 'test-' . $this->getTestRun() . '-new firstName'; |
| 84 | + $request = CustomerUpdateByKeyRequest::ofKeyAndVersion($customer->getKey(), $customer->getVersion()) |
| 85 | + ->addAction( |
| 86 | + CustomerSetFirstNameAction::of()->setFirstName($firstName) |
| 87 | + ) |
| 88 | + ; |
| 89 | + $response = $request->executeWithClient($this->getClient()); |
| 90 | + $result = $request->mapResponse($response); |
| 91 | + $this->deleteRequest->setVersion($result->getVersion()); |
| 92 | + |
| 93 | + $this->assertInstanceOf(Customer::class, $result); |
| 94 | + $this->assertSame($firstName, $result->getFirstName()); |
| 95 | + } |
| 96 | + |
| 97 | + public function testSetKey() |
| 98 | + { |
| 99 | + $draft = $this->getDraft('set-key'); |
| 100 | + $customer = $this->createCustomer($draft); |
| 101 | + |
| 102 | + $key = 'new-' . $this->getTestRun(); |
| 103 | + $request = CustomerUpdateRequest::ofIdAndVersion($customer->getId(), $customer->getVersion()) |
| 104 | + ->addAction( |
| 105 | + CustomerSetKeyAction::of()->setKey($key) |
| 106 | + ) |
| 107 | + ; |
| 108 | + $response = $request->executeWithClient($this->getClient()); |
| 109 | + $result = $request->mapResponse($response); |
| 110 | + $this->deleteRequest->setVersion($result->getVersion()); |
| 111 | + |
| 112 | + $this->assertInstanceOf(Customer::class, $result); |
| 113 | + $this->assertSame($key, $result->getKey()); |
| 114 | + $this->assertNotSame($customer->getVersion(), $result->getVersion()); |
| 115 | + } |
| 116 | + |
73 | 117 | public function testCustomerEmail() |
74 | 118 | { |
75 | 119 | $draft = $this->getDraft('email'); |
|
0 commit comments