mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
[API][ExchangeRate] Update mapping
This commit is contained in:
parent
b83611673e
commit
5a06ac44bb
7 changed files with 217 additions and 1 deletions
|
|
@ -44,6 +44,9 @@
|
|||
<attribute name="denormalization_context">
|
||||
<attribute name="groups">admin:exchange_rate:create</attribute>
|
||||
</attribute>
|
||||
<attribute name="normalization_context">
|
||||
<attribute name="groups">admin:exchange_rate:read</attribute>
|
||||
</attribute>
|
||||
</collectionOperation>
|
||||
</collectionOperations>
|
||||
|
||||
|
|
@ -70,6 +73,9 @@
|
|||
<attribute name="denormalization_context">
|
||||
<attribute name="groups">admin:exchange_rate:update</attribute>
|
||||
</attribute>
|
||||
<attribute name="normalization_context">
|
||||
<attribute name="groups">admin:exchange_rate:read</attribute>
|
||||
</attribute>
|
||||
</itemOperation>
|
||||
|
||||
<itemOperation name="admin_delete">
|
||||
|
|
|
|||
131
tests/Api/Admin/ExchangeRatesTest.php
Normal file
131
tests/Api/Admin/ExchangeRatesTest.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\Currency\Model\ExchangeRateInterface;
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Sylius\Tests\Api\Utils\AdminUserLoginTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class ExchangeRatesTest extends JsonApiTestCase
|
||||
{
|
||||
use AdminUserLoginTrait;
|
||||
|
||||
/** @test */
|
||||
public function it_gets_an_exchange_rate(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'exchange_rate.yaml',
|
||||
]);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var ExchangeRateInterface $exchangeRate */
|
||||
$exchangeRate = $fixtures['exchange_rate_CNYUSD'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: sprintf('/api/v2/admin/exchange-rates/%s', $exchangeRate->getId()),
|
||||
server: $header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/exchange_rate/get_exchange_rate_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_exchange_rates(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'exchange_rate.yaml',
|
||||
]);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: '/api/v2/admin/exchange-rates',
|
||||
server: $header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/exchange_rate/get_exchange_rates_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_an_exchange_rate(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'exchange_rate.yaml',
|
||||
]);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
$this->client->request(
|
||||
method: 'POST',
|
||||
uri: '/api/v2/admin/exchange-rates',
|
||||
server: $header,
|
||||
content: json_encode([
|
||||
'ratio' => '3.2',
|
||||
"sourceCurrency" => "/api/v2/admin/currencies/CNY",
|
||||
"targetCurrency" => "/api/v2/admin/currencies/PLN",
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/exchange_rate/post_exchange_rate_response',
|
||||
Response::HTTP_CREATED,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_an_existing_exchange_rate(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'exchange_rate.yaml',
|
||||
]);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var ExchangeRateInterface $exchangeRate */
|
||||
$exchangeRate = $fixtures['exchange_rate_CNYUSD'];
|
||||
|
||||
|
||||
$this->client->request(
|
||||
method: 'PUT',
|
||||
uri: '/api/v2/admin/exchange-rates/' . $exchangeRate->getId(),
|
||||
server: $header,
|
||||
content: json_encode([
|
||||
'ratio' => '0.25',
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/exchange_rate/put_exchange_rate_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@ Sylius\Component\Currency\Model\ExchangeRate:
|
|||
targetCurrency: '@currency_btn'
|
||||
ratio: 2.37
|
||||
|
||||
|
||||
Sylius\Component\Currency\Model\Currency:
|
||||
currency_pln:
|
||||
code: 'PLN'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ExchangeRate",
|
||||
"@id": "\/api\/v2\/admin\/exchange-rates\/@integer@",
|
||||
"@type": "ExchangeRate",
|
||||
"id": @integer@,
|
||||
"ratio": 0.15,
|
||||
"sourceCurrency": "\/api\/v2\/admin\/currencies\/CNY",
|
||||
"targetCurrency": "\/api\/v2\/admin\/currencies\/USD"
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ExchangeRate",
|
||||
"@id": "\/api\/v2\/admin\/exchange-rates",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/exchange-rates\/@integer@",
|
||||
"@type": "ExchangeRate",
|
||||
"id": @integer@,
|
||||
"ratio": 4.44,
|
||||
"sourceCurrency": "\/api\/v2\/admin\/currencies\/USD",
|
||||
"targetCurrency": "\/api\/v2\/admin\/currencies\/PLN"
|
||||
},
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/exchange-rates\/@integer@",
|
||||
"@type": "ExchangeRate",
|
||||
"id": @integer@,
|
||||
"ratio": 0.7,
|
||||
"sourceCurrency": "\/api\/v2\/admin\/currencies\/USD",
|
||||
"targetCurrency": "\/api\/v2\/admin\/currencies\/GBP"
|
||||
},
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/exchange-rates\/@integer@",
|
||||
"@type": "ExchangeRate",
|
||||
"id": @integer@,
|
||||
"ratio": 0.15,
|
||||
"sourceCurrency": "\/api\/v2\/admin\/currencies\/CNY",
|
||||
"targetCurrency": "\/api\/v2\/admin\/currencies\/USD"
|
||||
},
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/exchange-rates\/@integer@",
|
||||
"@type": "ExchangeRate",
|
||||
"id": @integer@,
|
||||
"ratio": 2.37,
|
||||
"sourceCurrency": "\/api\/v2\/admin\/currencies\/GBP",
|
||||
"targetCurrency": "\/api\/v2\/admin\/currencies\/BTN"
|
||||
}
|
||||
],
|
||||
"hydra:totalItems": 4,
|
||||
"hydra:search": {
|
||||
"@type": "hydra:IriTemplate",
|
||||
"hydra:template": "\/api\/v2\/admin\/exchange-rates{?currencyCode}",
|
||||
"hydra:variableRepresentation": "BasicRepresentation",
|
||||
"hydra:mapping": [
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "currencyCode",
|
||||
"property": "currencyCode",
|
||||
"required": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ExchangeRate",
|
||||
"@id": "\/api\/v2\/admin\/exchange-rates\/@integer@",
|
||||
"@type": "ExchangeRate",
|
||||
"id": @integer@,
|
||||
"ratio": 3.2,
|
||||
"sourceCurrency": "\/api\/v2\/admin\/currencies\/CNY",
|
||||
"targetCurrency": "\/api\/v2\/admin\/currencies\/PLN"
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ExchangeRate",
|
||||
"@id": "\/api\/v2\/admin\/exchange-rates\/@integer@",
|
||||
"@type": "ExchangeRate",
|
||||
"id": @integer@,
|
||||
"ratio": 0.25,
|
||||
"sourceCurrency": "\/api\/v2\/admin\/currencies\/CNY",
|
||||
"targetCurrency": "\/api\/v2\/admin\/currencies\/USD"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue