[API][Channel] Update mapping

This commit is contained in:
Jan Goralski 2022-11-28 11:04:50 +01:00
parent a47cf38bf4
commit d7d23046df
No known key found for this signature in database
GPG key ID: 95D91BA380F31EDD
7 changed files with 181 additions and 19 deletions

View file

@ -39,6 +39,9 @@
<attribute name="denormalization_context">
<attribute name="groups">admin:channel:create</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:channel:read</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
@ -71,6 +74,9 @@
<attribute name="denormalization_context">
<attribute name="groups">admin:channel:update</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:channel:read</attribute>
</attribute>
</itemOperation>
</itemOperations>
@ -78,12 +84,16 @@
<subresourceOperation name="shop_billing_data_get_subresource">
<attribute name="method">GET</attribute>
<attribute name="path">/admin/channels/{code}/shop-billing-data</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:shop_billing_data:read</attribute>
</attribute>
</subresourceOperation>
</subresourceOperations>
<property name="id" identifier="false" writable="false" />
<property name="code" identifier="true" required="true" />
<property name="name" writable="true" readable="true" />
<property name="enabled" writable="true" readable="true" />
<property name="description" writable="true" readable="true" />
<property name="hostname" writable="true" readable="true" />
<property name="color" writable="true" readable="true" />

View file

@ -26,6 +26,10 @@
<group>admin:channel:create</group>
<group>shop:channel:read</group>
</attribute>
<attribute name="enabled">
<group>admin:channel:read</group>
<group>admin:channel:create</group>
</attribute>
<attribute name="description">
<group>admin:channel:read</group>
<group>admin:channel:create</group>

View file

@ -22,6 +22,51 @@ final class ChannelsTest extends JsonApiTestCase
{
use AdminUserLoginTrait;
/** @test */
public function it_gets_a_channel(): void
{
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml']);
$header = $this->getLoggedHeader();
/** @var ChannelInterface $channel */
$channel = $fixtures['channel_web'];
$this->client->request(
'GET',
sprintf('/api/v2/admin/channels/%s', $channel->getCode()),
[],
[],
$header,
);
$this->assertResponse(
$this->client->getResponse(),
'admin/channel/get_channel_response',
Response::HTTP_OK,
);
}
/** @test */
public function it_gets_channels(): void
{
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml']);
$header = $this->getLoggedHeader();
$this->client->request(
'GET',
'/api/v2/admin/channels',
[],
[],
$header,
);
$this->assertResponse(
$this->client->getResponse(),
'admin/channel/get_channels_response',
Response::HTTP_OK,
);
}
/** @test */
public function it_creates_a_channel(): void
{
@ -37,18 +82,31 @@ final class ChannelsTest extends JsonApiTestCase
json_encode([
'name' => 'Web Store',
'code' => 'WEB',
'description' => 'Lorem ipsum',
'hostname' => 'test.com',
'color' => 'blue',
'enabled' => true,
'baseCurrency' => '/api/v2/admin/currencies/USD',
'defaultLocale' => '/api/v2/admin/locales/en_US',
'taxCalculationStrategy' => 'order_items_based',
'shippingAddressInCheckoutRequired' => true,
'currencies' => [],
'locales' => [],
'themeName' => 'garish',
'contactEmail' => 'contact@test.com',
'contactPhoneNumber' => '1-800-00-00-00',
'skippingShippingStepAllowed' => false,
'skippingPaymentStepAllowed' => true,
'accountVerificationRequired' => true,
'shippingAddressInCheckoutRequired' => false,
'menuTaxon' => null,
], JSON_THROW_ON_ERROR)
);
$this->assertResponse(
$this->client->getResponse(),
'admin/post_channel_response',
Response::HTTP_CREATED
'admin/channel/post_channel_response',
Response::HTTP_CREATED,
);
}
@ -75,7 +133,7 @@ final class ChannelsTest extends JsonApiTestCase
$this->assertResponse(
$this->client->getResponse(),
'admin/put_channel_response',
'admin/channel/put_channel_response',
Response::HTTP_OK
);
}

View file

@ -2,29 +2,29 @@
"@context": "\/api\/v2\/contexts\/Channel",
"@id": "\/api\/v2\/admin\/channels\/WEB",
"@type": "Channel",
"id":"@integer@",
"code": "WEB",
"name": "Web Store",
"name": "Web Channel",
"enabled": true,
"description": "Lorem ipsum",
"hostname": "localhost",
"color": "black",
"baseCurrency": "\/api\/v2\/admin\/currencies\/USD",
"defaultLocale": "\/api\/v2\/admin\/locales\/en_US",
"defaultTaxZone": null,
"taxCalculationStrategy": "order_items_based",
"currencies": [],
"locales": [],
"locales": [
"\/api\/v2\/admin\/locales\/en_US",
"\/api\/v2\/admin\/locales\/pl_PL"
],
"countries": [],
"themeName": null,
"contactEmail": null,
"contactEmail": "web@sylius.com",
"contactPhoneNumber": null,
"skippingShippingStepAllowed": false,
"skippingPaymentStepAllowed": false,
"accountVerificationRequired": true,
"shippingAddressInCheckoutRequired": true,
"shippingAddressInCheckoutRequired": false,
"shopBillingData": null,
"menuTaxon": null,
"description": null,
"hostname": null,
"color": null,
"createdAt": @string@,
"updatedAt": @string@
"menuTaxon": null
}

View file

@ -0,0 +1,66 @@
{
"@context": "\/api\/v2\/contexts\/Channel",
"@id": "\/api\/v2\/admin\/channels",
"@type": "hydra:Collection",
"hydra:member": [
{
"@id": "\/api\/v2\/admin\/channels\/WEB",
"@type": "Channel",
"code": "WEB",
"name": "Web Channel",
"enabled": true,
"description": "Lorem ipsum",
"hostname": "localhost",
"color": "black",
"baseCurrency": "\/api\/v2\/admin\/currencies\/USD",
"defaultLocale": "\/api\/v2\/admin\/locales\/en_US",
"defaultTaxZone": null,
"taxCalculationStrategy": "order_items_based",
"currencies": [],
"locales": [
"\/api\/v2\/admin\/locales\/en_US",
"\/api\/v2\/admin\/locales\/pl_PL"
],
"countries": [],
"themeName": null,
"contactEmail": "web@sylius.com",
"contactPhoneNumber": null,
"skippingShippingStepAllowed": false,
"skippingPaymentStepAllowed": false,
"accountVerificationRequired": true,
"shippingAddressInCheckoutRequired": false,
"shopBillingData": null,
"menuTaxon": null
},
{
"@id": "\/api\/v2\/admin\/channels\/MOBILE",
"@type": "Channel",
"code": "MOBILE",
"name": "Mobile Channel",
"enabled": true,
"description": "Lorem ipsum",
"hostname": "localhost",
"color": "black",
"baseCurrency": "\/api\/v2\/admin\/currencies\/USD",
"defaultLocale": "\/api\/v2\/admin\/locales\/en_US",
"defaultTaxZone": null,
"taxCalculationStrategy": "order_items_based",
"currencies": [],
"locales": [
"\/api\/v2\/admin\/locales\/en_US",
"\/api\/v2\/admin\/locales\/pl_PL"
],
"countries": [],
"themeName": null,
"contactEmail": "mobile@sylius.com",
"contactPhoneNumber": null,
"skippingShippingStepAllowed": false,
"skippingPaymentStepAllowed": false,
"accountVerificationRequired": true,
"shippingAddressInCheckoutRequired": false,
"shopBillingData": null,
"menuTaxon": null
}
],
"hydra:totalItems": 2
}

View file

@ -0,0 +1,27 @@
{
"@context": "\/api\/v2\/contexts\/Channel",
"@id": "\/api\/v2\/admin\/channels\/@string@",
"@type": "Channel",
"code": "WEB",
"name": "Web Store",
"enabled": true,
"description": "Lorem ipsum",
"hostname": "test.com",
"color": "blue",
"baseCurrency": "\/api\/v2\/admin\/currencies\/USD",
"defaultLocale": "\/api\/v2\/admin\/locales\/en_US",
"defaultTaxZone": null,
"taxCalculationStrategy": "order_items_based",
"currencies": [],
"locales": [],
"countries": [],
"themeName": "garish",
"contactEmail": "contact@test.com",
"contactPhoneNumber": "1-800-00-00-00",
"skippingShippingStepAllowed": false,
"skippingPaymentStepAllowed": true,
"accountVerificationRequired": true,
"shippingAddressInCheckoutRequired": false,
"shopBillingData": null,
"menuTaxon": null
}

View file

@ -2,7 +2,6 @@
"@context": "\/api\/v2\/contexts\/Channel",
"@id": "\/api\/v2\/admin\/channels\/WEB",
"@type": "Channel",
"id":"@integer@",
"code": "WEB",
"name": "Web Channel",
"enabled": true,
@ -27,7 +26,5 @@
"menuTaxon": null,
"description": "Lorem ipsum",
"hostname": "localhost",
"color": "black",
"createdAt": @string@,
"updatedAt": @string@
"color": "black"
}