mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
[API][Province] Update mapping
This commit is contained in:
parent
71186cfb72
commit
5a281b1b5e
7 changed files with 121 additions and 23 deletions
|
|
@ -28,14 +28,16 @@
|
|||
<attribute name="normalization_context">
|
||||
<attribute name="groups">admin:province:read</attribute>
|
||||
</attribute>
|
||||
|
||||
<attribute name="denormalization_context">
|
||||
<attribute name="groups">admin:province:update</attribute>
|
||||
</attribute>
|
||||
</itemOperation>
|
||||
|
||||
<itemOperation name="admin_put">
|
||||
<attribute name="method">PUT</attribute>
|
||||
<attribute name="normalization_context">
|
||||
<attribute name="groups">admin:province:read</attribute>
|
||||
</attribute>
|
||||
<attribute name="denormalization_context">
|
||||
<attribute name="groups">admin:province:update</attribute>
|
||||
</attribute>
|
||||
</itemOperation>
|
||||
</itemOperations>
|
||||
|
||||
|
|
@ -43,7 +45,5 @@
|
|||
<property name="code" identifier="true" required="true" />
|
||||
<property name="name" required="true" />
|
||||
<property name="abbreviation" writable="true" />
|
||||
<property name="createdAt" writable="false" />
|
||||
<property name="updatedAt" writable="false" />
|
||||
</resource>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -16,15 +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\Addressing\Model\Province">
|
||||
<attribute name="id">
|
||||
<group>admin:province:read</group>
|
||||
</attribute>
|
||||
<attribute name="createdAt">
|
||||
<group>admin:province:read</group>
|
||||
</attribute>
|
||||
<attribute name="updatedAt">
|
||||
<group>admin:province:read</group>
|
||||
</attribute>
|
||||
<attribute name="code">
|
||||
<group>admin:country:create</group>
|
||||
<group>admin:country:update</group>
|
||||
|
|
|
|||
85
tests/Api/Admin/ProvincesTest.php
Normal file
85
tests/Api/Admin/ProvincesTest.php
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?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\Addressing\Model\ProvinceInterface;
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Sylius\Tests\Api\Utils\AdminUserLoginTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class ProvincesTest extends JsonApiTestCase
|
||||
{
|
||||
use AdminUserLoginTrait;
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_country(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'country.yaml']);
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
/** @var ProvinceInterface $province */
|
||||
$province = $fixtures['province_US_WY'];
|
||||
|
||||
$this->client->request(
|
||||
'GET',
|
||||
sprintf('/api/v2/admin/provinces/%s', $province->getCode()),
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/province/get_province_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_an_existing_province(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'country.yaml']);
|
||||
|
||||
/** @var ProvinceInterface $province */
|
||||
$province = $fixtures['province_US_MI'];
|
||||
|
||||
$header = $this->getLoggedHeader();
|
||||
|
||||
$this->client->request(
|
||||
'PUT',
|
||||
'/api/v2/admin/provinces/' . $province->getCode(),
|
||||
[],
|
||||
[],
|
||||
$header,
|
||||
json_encode([
|
||||
'abbreviation' => 'Minn.',
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/province/put_province_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,8 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/Province",
|
||||
"@id": "\/api\/v2\/admin\/provinces\/US-WY",
|
||||
"@type": "Province",
|
||||
"code": "US-WY",
|
||||
"name": "Wyoming",
|
||||
"abbreviation": null
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/Province",
|
||||
"@id": "\/api\/v2\/admin\/provinces\/US-MI",
|
||||
"@type": "Province",
|
||||
"code": "US-MI",
|
||||
"name": "Minnesota",
|
||||
"abbreviation": "Minn."
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
"phoneNumber": "666111333",
|
||||
"company": "Potato Corp.",
|
||||
"countryCode": "US",
|
||||
"provinceCode": "US-MI",
|
||||
"street": "Top secret",
|
||||
"city": "Nebraska",
|
||||
"postcode": "12343"
|
||||
|
|
@ -23,6 +24,7 @@
|
|||
"phoneNumber": "666111333",
|
||||
"company": "Potato Corp.",
|
||||
"countryCode": "US",
|
||||
"provinceCode": "US-MI",
|
||||
"street": "Top secret",
|
||||
"city": "Nebraska",
|
||||
"postcode": "12343"
|
||||
|
|
|
|||
|
|
@ -299,9 +299,15 @@ final class OrdersTest extends JsonApiTestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function it_allows_to_patch_orders_address(): void
|
||||
public function it_allows_to_replace_orders_address(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['channel.yaml', 'cart.yaml', 'country.yaml', 'shipping_method.yaml', 'payment_method.yaml']);
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'channel.yaml',
|
||||
'cart.yaml',
|
||||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
]);
|
||||
|
||||
$tokenValue = 'nAWw2jewpA';
|
||||
|
||||
|
|
@ -324,22 +330,20 @@ final class OrdersTest extends JsonApiTestCase
|
|||
'phoneNumber'=> '666111333',
|
||||
'company'=> 'Potato Corp.',
|
||||
'countryCode'=> $country->getCode(),
|
||||
'provinceCode' => 'US-MI',
|
||||
'street'=> 'Top secret',
|
||||
'city'=> 'Nebraska',
|
||||
'postcode'=> '12343'
|
||||
'postcode'=> '12343',
|
||||
];
|
||||
|
||||
$this->client->request(
|
||||
method: 'PUT',
|
||||
uri: '/api/v2/shop/orders/nAWw2jewpA',
|
||||
server: [
|
||||
'CONTENT_TYPE' => 'application/ld+json',
|
||||
'HTTP_ACCEPT' => 'application/ld+json',
|
||||
],
|
||||
server: self::CONTENT_TYPE_HEADER,
|
||||
content: json_encode([
|
||||
'email' => 'oliver@doe.com',
|
||||
'billingAddress' => $billingAddress,
|
||||
])
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue