[API][CustomerGroup] Update mapping

This commit is contained in:
Jan Goralski 2022-12-05 13:03:54 +01:00
parent c5c8d65900
commit b83611673e
No known key found for this signature in database
GPG key ID: 95D91BA380F31EDD
8 changed files with 168 additions and 3 deletions

View file

@ -32,6 +32,9 @@
<attribute name="denormalization_context">
<attribute name="groups">admin:customer_group:create</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:customer_group:read</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
@ -48,6 +51,9 @@
<attribute name="denormalization_context">
<attribute name="groups">admin:customer_group:update</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:customer_group:read</attribute>
</attribute>
</itemOperation>
<itemOperation name="admin_delete">

View file

@ -16,9 +16,6 @@
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="Sylius\Component\Customer\Model\CustomerGroup">
<attribute name="id">
<group>admin:customer_group:read</group>
</attribute>
<attribute name="code">
<group>admin:customer_group:read</group>
<group>admin:customer_group:create</group>

View file

@ -0,0 +1,114 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Tests\Api\Admin;
use Sylius\Component\Customer\Model\CustomerGroupInterface;
use Sylius\Tests\Api\JsonApiTestCase;
use Sylius\Tests\Api\Utils\AdminUserLoginTrait;
use Symfony\Component\HttpFoundation\Response;
final class CustomerGroupsTest extends JsonApiTestCase
{
use AdminUserLoginTrait;
/** @test */
public function it_gets_a_customer_group(): void
{
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'customer_group.yaml']);
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
/** @var CustomerGroupInterface $group */
$group = $fixtures['group_vip'];
$this->client->request(
method: 'GET',
uri: sprintf('/api/v2/admin/customer-groups/%s', $group->getCode()),
server: $header,
);
$this->assertResponse(
$this->client->getResponse(),
'admin/customer_group/get_customer_group_response',
Response::HTTP_OK,
);
}
/** @test */
public function it_gets_customer_groups(): void
{
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'customer_group.yaml']);
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
$this->client->request(
method: 'GET',
uri: '/api/v2/admin/customer-groups',
server: $header,
);
$this->assertResponse(
$this->client->getResponse(),
'admin/customer_group/get_customer_groups_response',
Response::HTTP_OK,
);
}
/** @test */
public function it_creates_a_customer_group(): void
{
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml']);
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
$this->client->request(
method: 'POST',
uri: '/api/v2/admin/customer-groups',
server: $header,
content: json_encode([
'name' => 'Special',
'code' => 'special',
], JSON_THROW_ON_ERROR),
);
$this->assertResponse(
$this->client->getResponse(),
'admin/customer_group/post_customer_group_response',
Response::HTTP_CREATED,
);
}
/** @test */
public function it_updates_an_existing_customer_group(): void
{
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'customer_group.yaml']);
/** @var CustomerGroupInterface $group */
$group = $fixtures['group_vip'];
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
$this->client->request(
method: 'PUT',
uri: '/api/v2/admin/customer-groups/' . $group->getCode(),
server: $header,
content: json_encode([
'name' => 'Very Important People',
], JSON_THROW_ON_ERROR),
);
$this->assertResponse(
$this->client->getResponse(),
'admin/customer_group/put_customer_group_response',
Response::HTTP_OK,
);
}
}

View file

@ -0,0 +1,7 @@
Sylius\Component\Customer\Model\CustomerGroup:
group_premium:
code: 'premium'
name: 'Premium'
group_vip:
code: 'vip'
name: 'VIP'

View file

@ -0,0 +1,7 @@
{
"@context": "\/api\/v2\/contexts\/CustomerGroup",
"@id": "\/api\/v2\/admin\/customer-groups\/vip",
"@type": "CustomerGroup",
"code": "vip",
"name": "VIP"
}

View file

@ -0,0 +1,20 @@
{
"@context": "\/api\/v2\/contexts\/CustomerGroup",
"@id": "\/api\/v2\/admin\/customer-groups",
"@type": "hydra:Collection",
"hydra:member": [
{
"@id": "\/api\/v2\/admin\/customer-groups\/premium",
"@type": "CustomerGroup",
"code": "premium",
"name": "Premium"
},
{
"@id": "\/api\/v2\/admin\/customer-groups\/vip",
"@type": "CustomerGroup",
"code": "vip",
"name": "VIP"
}
],
"hydra:totalItems": 2
}

View file

@ -0,0 +1,7 @@
{
"@context": "\/api\/v2\/contexts\/CustomerGroup",
"@id": "\/api\/v2\/admin\/customer-groups\/special",
"@type": "CustomerGroup",
"code": "special",
"name": "Special"
}

View file

@ -0,0 +1,7 @@
{
"@context": "\/api\/v2\/contexts\/CustomerGroup",
"@id": "\/api\/v2\/admin\/customer-groups\/vip",
"@type": "CustomerGroup",
"code": "vip",
"name": "Very Important People"
}