mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-15 01:20:59 +00:00
[API][Currency] Update mapping
This commit is contained in:
parent
3ec9e1de98
commit
86b16e2c0b
7 changed files with 154 additions and 4 deletions
|
|
@ -30,6 +30,12 @@
|
|||
<collectionOperation name="admin_post">
|
||||
<attribute name="method">POST</attribute>
|
||||
<attribute name="path">/admin/currencies</attribute>
|
||||
<attribute name="denormalization_context">
|
||||
<attribute name="groups">admin:currency:create</attribute>
|
||||
</attribute>
|
||||
<attribute name="normalization_context">
|
||||
<attribute name="groups">admin:currency:read</attribute>
|
||||
</attribute>
|
||||
</collectionOperation>
|
||||
|
||||
<collectionOperation name="shop_get">
|
||||
|
|
@ -65,5 +71,6 @@
|
|||
<property name="code" identifier="true" required="true" />
|
||||
<property name="createdAt" writable="false" />
|
||||
<property name="updatedAt" writable="false" />
|
||||
<property name="name" writable="false" />
|
||||
</resource>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -16,12 +16,9 @@
|
|||
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\Currency\Model\Currency">
|
||||
<attribute name="id">
|
||||
<group>admin:currency:read</group>
|
||||
<group>shop:currency:read</group>
|
||||
</attribute>
|
||||
<attribute name="code">
|
||||
<group>admin:currency:read</group>
|
||||
<group>admin:currency:create</group>
|
||||
<group>shop:currency:read</group>
|
||||
</attribute>
|
||||
<attribute name="name">
|
||||
|
|
|
|||
102
tests/Api/Admin/CurrenciesTest.php
Normal file
102
tests/Api/Admin/CurrenciesTest.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?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\Currency\Model\CurrencyInterface;
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Sylius\Tests\Api\Utils\AdminUserLoginTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class CurrenciesTest extends JsonApiTestCase
|
||||
{
|
||||
use AdminUserLoginTrait;
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_country(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'currency.yaml']);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
/** @var CurrencyInterface $currency */
|
||||
$currency = $fixtures['currency_gbp'];
|
||||
|
||||
$this->client->request(
|
||||
'GET',
|
||||
sprintf('/api/v2/admin/currencies/%s', $currency->getCode()),
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/currency/get_currency_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_currencies(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'currency.yaml']);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
$this->client->request(
|
||||
'GET',
|
||||
'/api/v2/admin/currencies',
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/currency/get_currencies_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_a_currency(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml']);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
$this->client->request(
|
||||
'POST',
|
||||
'/api/v2/admin/currencies',
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
json_encode([
|
||||
'code' => 'KRW',
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/currency/post_currency_response',
|
||||
Response::HTTP_CREATED,
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
Sylius\Component\Currency\Model\Currency:
|
||||
currency_usd:
|
||||
code: 'USD'
|
||||
currency_gbp:
|
||||
code: 'GBP'
|
||||
currency_eur:
|
||||
code: 'EUR'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/Currency",
|
||||
"@id": "\/api\/v2\/admin\/currencies",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/currencies\/USD",
|
||||
"@type": "Currency",
|
||||
"code": "USD",
|
||||
"name": "US Dollar"
|
||||
},
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/currencies\/GBP",
|
||||
"@type": "Currency",
|
||||
"code": "GBP",
|
||||
"name": "British Pound"
|
||||
},
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/currencies\/EUR",
|
||||
"@type": "Currency",
|
||||
"code": "EUR",
|
||||
"name": "Euro"
|
||||
}
|
||||
],
|
||||
"hydra:totalItems": 3
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/Currency",
|
||||
"@id": "\/api\/v2\/admin\/currencies\/GBP",
|
||||
"@type": "Currency",
|
||||
"code": "GBP",
|
||||
"name": "British Pound"
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/Currency",
|
||||
"@id": "\/api\/v2\/admin\/currencies\/KRW",
|
||||
"@type": "Currency",
|
||||
"code": "KRW",
|
||||
"name": "South Korean Won"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue