mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-15 01:20:59 +00:00
[API] reduce customer update serialization
This commit is contained in:
parent
5bdf62260c
commit
985e4b8661
3 changed files with 80 additions and 0 deletions
|
|
@ -71,6 +71,9 @@
|
|||
<itemOperation name="shop_put">
|
||||
<attribute name="method">PUT</attribute>
|
||||
<attribute name="path">/shop/customers/{id}</attribute>
|
||||
<attribute name="normalization_context">
|
||||
<attribute name="groups">shop:customer:read</attribute>
|
||||
</attribute>
|
||||
<attribute name="denormalization_context">
|
||||
<attribute name="groups">shop:customer:update</attribute>
|
||||
</attribute>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"@context": "/api/v2/contexts/Customer",
|
||||
"@id": @string@,
|
||||
"@type": "Customer",
|
||||
"defaultAddress": null,
|
||||
"user": {
|
||||
"@id": @string@,
|
||||
"@type": @string@,
|
||||
"verified": false
|
||||
},
|
||||
"email": "oliver@doe.com",
|
||||
"firstName": "John",
|
||||
"lastName": "Doe",
|
||||
"subscribedToNewsletter": false,
|
||||
"fullName": "John Doe"
|
||||
}
|
||||
61
tests/Api/Shop/CustomerUpdateTest.php
Normal file
61
tests/Api/Shop/CustomerUpdateTest.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Tests\Api\Shop;
|
||||
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CustomerUpdateTest extends JsonApiTestCase
|
||||
{
|
||||
/** @test */
|
||||
public function it_returns_small_amount_of_data_on_customer_update(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['authentication/customer.yaml']);
|
||||
$loginData = $this->loginAsCustomer();
|
||||
|
||||
$this->client->request(
|
||||
'PUT',
|
||||
$loginData['customer'],
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'CONTENT_TYPE' => 'application/ld+json',
|
||||
'HTTP_ACCEPT' => 'application/ld+json',
|
||||
'HTTP_Authorization' => sprintf('Bearer %s', $loginData['token'])
|
||||
],
|
||||
json_encode([
|
||||
'firstName' => 'John'
|
||||
])
|
||||
);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'shop/update_customer_response', Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function loginAsCustomer(): array
|
||||
{
|
||||
$this->client->request(
|
||||
'POST',
|
||||
'/api/v2/shop/authentication-token',
|
||||
[],
|
||||
[],
|
||||
self::CONTENT_TYPE_HEADER,
|
||||
json_encode([
|
||||
'email' => 'oliver@doe.com',
|
||||
'password' => 'sylius'
|
||||
])
|
||||
);
|
||||
|
||||
return json_decode($this->client->getResponse()->getContent(), true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue