[API] reduce customer update serialization

This commit is contained in:
SirDomin 2021-08-03 12:46:07 +02:00
parent 5bdf62260c
commit 985e4b8661
No known key found for this signature in database
GPG key ID: D74943926397267A
3 changed files with 80 additions and 0 deletions

View file

@ -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>

View file

@ -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"
}

View 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);
}
}