mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
[API][CustomerGroup] Update mapping
This commit is contained in:
parent
c5c8d65900
commit
b83611673e
8 changed files with 168 additions and 3 deletions
|
|
@ -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">
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
114
tests/Api/Admin/CustomerGroupsTest.php
Normal file
114
tests/Api/Admin/CustomerGroupsTest.php
Normal 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
7
tests/Api/DataFixtures/ORM/customer_group.yaml
Normal file
7
tests/Api/DataFixtures/ORM/customer_group.yaml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Sylius\Component\Customer\Model\CustomerGroup:
|
||||
group_premium:
|
||||
code: 'premium'
|
||||
name: 'Premium'
|
||||
group_vip:
|
||||
code: 'vip'
|
||||
name: 'VIP'
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/CustomerGroup",
|
||||
"@id": "\/api\/v2\/admin\/customer-groups\/vip",
|
||||
"@type": "CustomerGroup",
|
||||
"code": "vip",
|
||||
"name": "VIP"
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/CustomerGroup",
|
||||
"@id": "\/api\/v2\/admin\/customer-groups\/special",
|
||||
"@type": "CustomerGroup",
|
||||
"code": "special",
|
||||
"name": "Special"
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/CustomerGroup",
|
||||
"@id": "\/api\/v2\/admin\/customer-groups\/vip",
|
||||
"@type": "CustomerGroup",
|
||||
"code": "vip",
|
||||
"name": "Very Important People"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue