[API] Add tests for overwrite endpoints with YAML configurations

This commit is contained in:
Grzegorz Sadowski 2024-10-07 10:36:53 +02:00
parent b657e63891
commit dfcdee2844
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
3 changed files with 38 additions and 3 deletions

View file

@ -19,7 +19,7 @@
<resource class="%sylius.model.channel.class%">
<operations>
<operation
name="test_channels_new_path_xml"
name="test_channel_new_path_xml"
class="ApiPlatform\Metadata\GetCollection"
uriTemplate="/shop/channels-new-path-xml"
>
@ -34,7 +34,7 @@
</normalizationContext>
</operation>
<operation name="sylius_api_shop_channel_get" class="ApiPlatform\Metadata\Get" uriTemplate="/shop/channels/new/{code}">
<operation name="sylius_api_shop_channel_get" class="ApiPlatform\Metadata\Get" uriTemplate="/shop/channels/new-xml/{code}">
<normalizationContext>
<values>
<value name="groups">

View file

@ -0,0 +1,14 @@
resources:
'%sylius.model.currency.class%':
operations:
ApiPlatform\Metadata\GetCollection:
name: test_currency_new_path_yaml
uriTemplate: '/shop/currencies-new-path-yaml'
normalizationContext:
groups: ['sylius:shop:currency:index']
ApiPlatform\Metadata\Get:
name: sylius_api_shop_currency_get
uriTemplate: '/shop/currencies/new-yaml/{code}'
normalizationContext:
groups: ['sylius:shop:currency:show']

View file

@ -35,6 +35,15 @@ final class MergingConfigsTest extends ApiTestCase
self::assertJsonContains(['@type' => 'hydra:Collection']);
}
/** @test */
public function it_allows_to_add_a_new_operation_with_yaml(): void
{
static::createClient()->request('GET', '/api/v2/shop/currencies-new-path-yaml');
self::assertResponseIsSuccessful();
self::assertJsonContains(['@type' => 'hydra:Collection']);
}
/** @test */
public function it_allows_to_overwrite_an_existing_endpoint_with_xml(): void
{
@ -42,7 +51,19 @@ final class MergingConfigsTest extends ApiTestCase
self::assertResponseStatusCodeSame(404);
static::createClient()->request('GET', '/api/v2/shop/channels/new/WEB');
static::createClient()->request('GET', '/api/v2/shop/channels/new-xml/WEB');
self::assertResponseIsSuccessful();
}
/** @test */
public function it_allows_to_overwrite_an_existing_endpoint_with_yaml(): void
{
static::createClient()->request('GET', '/api/v2/shop/currencies/USD');
self::assertResponseStatusCodeSame(404);
static::createClient()->request('GET', '/api/v2/shop/currencies/new-yaml/USD');
self::assertResponseIsSuccessful();
}