mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[API][ShippingMethod] Update mapping
This commit is contained in:
parent
7449739eef
commit
58ee7ec037
9 changed files with 330 additions and 11 deletions
|
|
@ -16,11 +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\Core\Model\ShippingMethod">
|
||||
<attribute name="id">
|
||||
<group>admin:shipping_method:read</group>
|
||||
<group>shop:shipping_method:read</group>
|
||||
</attribute>
|
||||
|
||||
<attribute name="translations">
|
||||
<group>admin:shipping_method:create</group>
|
||||
<group>admin:shipping_method:read</group>
|
||||
|
|
@ -34,7 +29,6 @@
|
|||
</attribute>
|
||||
|
||||
<attribute name="name">
|
||||
<group>admin:shipping_method:read</group>
|
||||
<group>shop:shipping_method:read</group>
|
||||
</attribute>
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
<class name="Sylius\Component\Shipping\Model\ShippingMethodTranslation">
|
||||
<attribute name="id">
|
||||
<group>admin:shipping_method:read</group>
|
||||
<group>shop:shipping_method:read</group>
|
||||
</attribute>
|
||||
|
||||
<attribute name="name">
|
||||
|
|
|
|||
147
tests/Api/Admin/ShippingMethodsTest.php
Normal file
147
tests/Api/Admin/ShippingMethodsTest.php
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
<?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\Core\Model\ShippingMethodInterface;
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Sylius\Tests\Api\Utils\AdminUserLoginTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class ShippingMethodsTest extends JsonApiTestCase
|
||||
{
|
||||
use AdminUserLoginTrait;
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_shipping_method(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
]);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
/** @var ShippingMethodInterface $shippingMethod */
|
||||
$shippingMethod = $fixtures['shipping_method_ups'];
|
||||
|
||||
$this->client->request(
|
||||
'GET',
|
||||
sprintf('/api/v2/admin/shipping-methods/%s', $shippingMethod->getCode()),
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/shipping_method/get_shipping_method_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_shipping_methods(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
]);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
$this->client->request('GET', '/api/v2/admin/shipping-methods', [], [], $header);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/shipping_method/get_shipping_methods_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_archives_a_shipping_methods(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
]);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
/** @var ShippingMethodInterface $shippingMethod */
|
||||
$shippingMethod = $fixtures['shipping_method_ups'];
|
||||
|
||||
$this->client->request(
|
||||
'PATCH',
|
||||
sprintf('/api/v2/admin/shipping-methods/%s/archive', $shippingMethod->getCode()),
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/shipping_method/archive_shipping_method_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_restores_a_shipping_methods(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
]);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
/** @var ShippingMethodInterface $shippingMethod */
|
||||
$shippingMethod = $fixtures['shipping_method_ups'];
|
||||
|
||||
$this->client->request(
|
||||
'PATCH',
|
||||
sprintf('/api/v2/admin/shipping-methods/%s/archive', $shippingMethod->getCode()),
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
);
|
||||
$this->client->request(
|
||||
'PATCH',
|
||||
sprintf('/api/v2/admin/shipping-methods/%s/restore', $shippingMethod->getCode()),
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/shipping_method/restore_shipping_method_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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ShippingMethod",
|
||||
"@id": "\/api\/v2\/admin\/shipping-methods\/UPS",
|
||||
"@type": "ShippingMethod",
|
||||
"code": "UPS",
|
||||
"position": 0,
|
||||
"calculator": "flat_rate",
|
||||
"enabled": true,
|
||||
"createdAt": @date@,
|
||||
"updatedAt": @date@,
|
||||
"archivedAt": @date@,
|
||||
"configuration": {
|
||||
"WEB": {
|
||||
"amount": 500
|
||||
}
|
||||
},
|
||||
"zone": "\/api\/v2\/admin\/zones\/WORLD",
|
||||
"channels": [
|
||||
"\/api\/v2\/admin\/channels\/WEB"
|
||||
],
|
||||
"translations": {
|
||||
"en_US": {
|
||||
"@id": "\/api\/v2\/admin\/shipping-method-translations\/@integer@",
|
||||
"@type": "ShippingMethodTranslation",
|
||||
"id": @integer@,
|
||||
"name": "UPS",
|
||||
"description": @string@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ShippingMethod",
|
||||
"@id": "\/api\/v2\/admin\/shipping-methods\/UPS",
|
||||
"@type": "ShippingMethod",
|
||||
"code": "UPS",
|
||||
"position": 0,
|
||||
"calculator": "flat_rate",
|
||||
"enabled": true,
|
||||
"createdAt": @date@,
|
||||
"updatedAt": @date@,
|
||||
"configuration": {
|
||||
"WEB": {
|
||||
"amount": 500
|
||||
}
|
||||
},
|
||||
"zone": "\/api\/v2\/admin\/zones\/WORLD",
|
||||
"channels": [
|
||||
"\/api\/v2\/admin\/channels\/WEB"
|
||||
],
|
||||
"translations": {
|
||||
"en_US": {
|
||||
"@id": "\/api\/v2\/admin\/shipping-method-translations\/@integer@",
|
||||
"@type": "ShippingMethodTranslation",
|
||||
"id": @integer@,
|
||||
"name": "UPS",
|
||||
"description": @string@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ShippingMethod",
|
||||
"@id": "\/api\/v2\/admin\/shipping-methods",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/shipping-methods\/UPS",
|
||||
"@type": "ShippingMethod",
|
||||
"code": "UPS",
|
||||
"position": 0,
|
||||
"calculator": "flat_rate",
|
||||
"enabled": true,
|
||||
"createdAt": @date@,
|
||||
"updatedAt": @date@,
|
||||
"configuration": {
|
||||
"WEB": {
|
||||
"amount": 500
|
||||
}
|
||||
},
|
||||
"zone": "\/api\/v2\/admin\/zones\/WORLD",
|
||||
"channels": [
|
||||
"\/api\/v2\/admin\/channels\/WEB"
|
||||
],
|
||||
"translations": {
|
||||
"en_US": {
|
||||
"@id": "\/api\/v2\/admin\/shipping-method-translations\/@integer@",
|
||||
"@type": "ShippingMethodTranslation",
|
||||
"id": @integer@,
|
||||
"name": "UPS",
|
||||
"description": @string@
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/shipping-methods\/DHL",
|
||||
"@type": "ShippingMethod",
|
||||
"code": "DHL",
|
||||
"position": 1,
|
||||
"calculator": "flat_rate",
|
||||
"enabled": true,
|
||||
"createdAt": @date@,
|
||||
"updatedAt": @date@,
|
||||
"configuration": {
|
||||
"WEB": {
|
||||
"amount": 1000
|
||||
}
|
||||
},
|
||||
"zone": "\/api\/v2\/admin\/zones\/WORLD",
|
||||
"channels": [
|
||||
"\/api\/v2\/admin\/channels\/WEB"
|
||||
],
|
||||
"translations": {
|
||||
"en_US": {
|
||||
"@id": "\/api\/v2\/admin\/shipping-method-translations\/@integer@",
|
||||
"@type": "ShippingMethodTranslation",
|
||||
"id": @integer@,
|
||||
"name": "DHL",
|
||||
"description": @string@
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"hydra:totalItems": 2,
|
||||
"hydra:search": {
|
||||
"@type": "hydra:IriTemplate",
|
||||
"hydra:template": "\/api\/v2\/admin\/shipping-methods{?exists[archivedAt],order[code],order[translation.name],localeCode for order[translation.name]}",
|
||||
"hydra:variableRepresentation": "BasicRepresentation",
|
||||
"hydra:mapping": [
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "exists[archivedAt]",
|
||||
"property": "archivedAt",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "order[code]",
|
||||
"property": "code",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "order[translation.name]",
|
||||
"property": "translation",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "localeCode for order[translation.name]",
|
||||
"property": "localeCode",
|
||||
"required": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ShippingMethod",
|
||||
"@id": "\/api\/v2\/admin\/shipping-methods\/UPS",
|
||||
"@type": "ShippingMethod",
|
||||
"code": "UPS",
|
||||
"position": 0,
|
||||
"calculator": "flat_rate",
|
||||
"enabled": true,
|
||||
"createdAt": @date@,
|
||||
"updatedAt": @date@,
|
||||
"configuration": {
|
||||
"WEB": {
|
||||
"amount": 500
|
||||
}
|
||||
},
|
||||
"zone": "\/api\/v2\/admin\/zones\/WORLD",
|
||||
"channels": [
|
||||
"\/api\/v2\/admin\/channels\/WEB"
|
||||
],
|
||||
"translations": {
|
||||
"en_US": {
|
||||
"@id": "\/api\/v2\/admin\/shipping-method-translations\/@integer@",
|
||||
"@type": "ShippingMethodTranslation",
|
||||
"id": @integer@,
|
||||
"name": "UPS",
|
||||
"description": @string@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@
|
|||
{
|
||||
"@id": "\/api\/v2\/shop\/shipping-methods\/UPS",
|
||||
"@type": "ShippingMethod",
|
||||
"id": "@integer@",
|
||||
"code": "UPS",
|
||||
"position": 0,
|
||||
"name": "UPS",
|
||||
|
|
@ -16,7 +15,6 @@
|
|||
{
|
||||
"@id": "\/api\/v2\/shop\/shipping-methods\/DHL",
|
||||
"@type": "ShippingMethod",
|
||||
"id": "@integer@",
|
||||
"code": "DHL",
|
||||
"position": 1,
|
||||
"name": "DHL",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
{
|
||||
"@id": "\/api\/v2\/shop\/shipping-methods\/UPS",
|
||||
"@type": "ShippingMethod",
|
||||
"id": "@integer@",
|
||||
"code": "UPS",
|
||||
"position": 0,
|
||||
"name": "UPS",
|
||||
|
|
@ -15,7 +14,6 @@
|
|||
{
|
||||
"@id": "\/api\/v2\/shop\/shipping-methods\/DHL",
|
||||
"@type": "ShippingMethod",
|
||||
"id": "@integer@",
|
||||
"code": "DHL",
|
||||
"position": 1,
|
||||
"name": "DHL",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue