mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-13 08:31:32 +00:00
[API][ShippingCategory] Update mapping
This commit is contained in:
parent
5a281b1b5e
commit
06127039c9
8 changed files with 201 additions and 3 deletions
|
|
@ -33,6 +33,9 @@
|
|||
<attribute name="denormalization_context">
|
||||
<attribute name="groups">admin:shipping_category:create</attribute>
|
||||
</attribute>
|
||||
<attribute name="normalization_context">
|
||||
<attribute name="groups">admin:shipping_category:read</attribute>
|
||||
</attribute>
|
||||
</collectionOperation>
|
||||
</collectionOperations>
|
||||
|
||||
|
|
@ -49,6 +52,9 @@
|
|||
<attribute name="denormalization_context">
|
||||
<attribute name="groups">admin:shipping_category:update</attribute>
|
||||
</attribute>
|
||||
<attribute name="normalization_context">
|
||||
<attribute name="groups">admin:shipping_category: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\Shipping\Model\ShippingCategory">
|
||||
<attribute name="id">
|
||||
<group>admin:shipping_category:read</group>
|
||||
</attribute>
|
||||
<attribute name="code">
|
||||
<group>admin:shipping_category:read</group>
|
||||
<group>admin:shipping_category:create</group>
|
||||
|
|
|
|||
131
tests/Api/Admin/ShippingCategoriesTest.php
Normal file
131
tests/Api/Admin/ShippingCategoriesTest.php
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
<?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\Shipping\Model\ShippingCategoryInterface;
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Sylius\Tests\Api\Utils\AdminUserLoginTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class ShippingCategoriesTest extends JsonApiTestCase
|
||||
{
|
||||
use AdminUserLoginTrait;
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_shipping_category(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'shipping_category.yaml']);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
/** @var ShippingCategoryInterface $shippingCategory */
|
||||
$shippingCategory = $fixtures['shipping_category_special'];
|
||||
|
||||
$this->client->request(
|
||||
'GET',
|
||||
sprintf('/api/v2/admin/shipping-categories/%s', $shippingCategory->getCode()),
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/shipping_category/get_shipping_category_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_shipping_categories(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'shipping_category.yaml']);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
$this->client->request(
|
||||
'GET',
|
||||
'/api/v2/admin/shipping-categories',
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/shipping_category/get_shipping_categories_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_a_shipping_category(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml']);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
$this->client->request(
|
||||
'POST',
|
||||
'/api/v2/admin/shipping-categories',
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
json_encode([
|
||||
'code' => 'ultra',
|
||||
'name' => 'Ultra',
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/shipping_category/post_shipping_category_response',
|
||||
Response::HTTP_CREATED,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_an_existing_shipping_category(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'shipping_category.yaml']);
|
||||
|
||||
/** @var ShippingCategoryInterface $shippingCategory */
|
||||
$shippingCategory = $fixtures['shipping_category_default'];
|
||||
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
$this->client->request(
|
||||
'PUT',
|
||||
'/api/v2/admin/shipping-categories/' . $shippingCategory->getCode(),
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
json_encode([
|
||||
'name' => 'Not so default',
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/shipping_category/put_shipping_category_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
private function getLoggedHeader(): array
|
||||
{
|
||||
$token = $this->logInAdminUser('api@example.com');
|
||||
$authorizationHeader = self::$kernel->getContainer()->getParameter('sylius.api.authorization_header');
|
||||
$header['HTTP_' . $authorizationHeader] = 'Bearer ' . $token;
|
||||
|
||||
return array_merge($header, self::CONTENT_TYPE_HEADER);
|
||||
}
|
||||
}
|
||||
8
tests/Api/DataFixtures/ORM/shipping_category.yaml
Normal file
8
tests/Api/DataFixtures/ORM/shipping_category.yaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Sylius\Component\Shipping\Model\ShippingCategory:
|
||||
shipping_category_default:
|
||||
code: 'default'
|
||||
name: 'Default'
|
||||
shipping_category_special:
|
||||
code: 'special'
|
||||
name: 'Special'
|
||||
description: 'For special care'
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ShippingCategory",
|
||||
"@id": "\/api\/v2\/admin\/shipping-categories",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/shipping-categories\/default",
|
||||
"@type": "ShippingCategory",
|
||||
"code": "default",
|
||||
"name": "Default",
|
||||
"description": null,
|
||||
"createdAt": @date@,
|
||||
"updatedAt": @date@
|
||||
},
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/shipping-categories\/special",
|
||||
"@type": "ShippingCategory",
|
||||
"code": "special",
|
||||
"name": "Special",
|
||||
"description": "For special care",
|
||||
"createdAt": @date@,
|
||||
"updatedAt": @date@
|
||||
}
|
||||
],
|
||||
"hydra:totalItems": 2
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ShippingCategory",
|
||||
"@id": "\/api\/v2\/admin\/shipping-categories\/special",
|
||||
"@type": "ShippingCategory",
|
||||
"code": "special",
|
||||
"name": "Special",
|
||||
"description": "For special care",
|
||||
"createdAt": @date@,
|
||||
"updatedAt": @date@
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ShippingCategory",
|
||||
"@id": "\/api\/v2\/admin\/shipping-categories\/ultra",
|
||||
"@type": "ShippingCategory",
|
||||
"code": "ultra",
|
||||
"name": "Ultra",
|
||||
"description": null,
|
||||
"createdAt": @date@,
|
||||
"updatedAt": @date@
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ShippingCategory",
|
||||
"@id": "\/api\/v2\/admin\/shipping-categories\/default",
|
||||
"@type": "ShippingCategory",
|
||||
"code": "default",
|
||||
"name": "Not so default",
|
||||
"description": null,
|
||||
"createdAt": @date@,
|
||||
"updatedAt": @date@
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue