From 4f57ca615a2c8f1682da8dbb1454499c8ad0ed1e Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 23 Feb 2024 11:06:51 +0100 Subject: [PATCH] [API][Shop] Add missing contract test for getting only locales from current channel --- .../ORM/channel_without_locales.yaml | 16 +++++++++++++++ .../get_locales_from_channel_response.json | 20 +++++++++++++++++++ .../shop/locale/get_locales_response.json | 8 +++++++- tests/Api/Shop/LocalesTest.php | 15 ++++++++++++-- 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 tests/Api/DataFixtures/ORM/channel_without_locales.yaml create mode 100644 tests/Api/Responses/shop/locale/get_locales_from_channel_response.json diff --git a/tests/Api/DataFixtures/ORM/channel_without_locales.yaml b/tests/Api/DataFixtures/ORM/channel_without_locales.yaml new file mode 100644 index 0000000000..0e2e2d22ad --- /dev/null +++ b/tests/Api/DataFixtures/ORM/channel_without_locales.yaml @@ -0,0 +1,16 @@ +Sylius\Component\Core\Model\Channel: + channel_web: + code: 'WEB' + name: 'Web Channel' + hostname: 'localhost' + contactEmail: 'web@sylius.com' + description: 'Lorem ipsum' + baseCurrency: '@currency_usd' + defaultLocale: '@locale_en' + color: 'black' + enabled: true + taxCalculationStrategy: 'order_items_based' + +Sylius\Component\Currency\Model\Currency: + currency_usd: + code: 'USD' diff --git a/tests/Api/Responses/shop/locale/get_locales_from_channel_response.json b/tests/Api/Responses/shop/locale/get_locales_from_channel_response.json new file mode 100644 index 0000000000..6d666b78fc --- /dev/null +++ b/tests/Api/Responses/shop/locale/get_locales_from_channel_response.json @@ -0,0 +1,20 @@ +{ + "@context": "\/api\/v2\/contexts\/Locale", + "@id": "\/api\/v2\/shop\/locales", + "@type": "hydra:Collection", + "hydra:member": [ + { + "@id": "\/api\/v2\/shop\/locales\/en_US", + "@type": "Locale", + "code": "en_US", + "name": "English (United States)" + }, + { + "@id": "\/api\/v2\/shop\/locales\/pl_PL", + "@type": "Locale", + "code": "pl_PL", + "name": "Polish (Poland)" + } + ], + "hydra:totalItems": 2 +} diff --git a/tests/Api/Responses/shop/locale/get_locales_response.json b/tests/Api/Responses/shop/locale/get_locales_response.json index 6d666b78fc..59e877edae 100644 --- a/tests/Api/Responses/shop/locale/get_locales_response.json +++ b/tests/Api/Responses/shop/locale/get_locales_response.json @@ -14,7 +14,13 @@ "@type": "Locale", "code": "pl_PL", "name": "Polish (Poland)" + }, + { + "@id": "\/api\/v2\/shop\/locales\/ga_IE", + "@type": "Locale", + "code": "ga_IE", + "name": "Irish (Ireland)" } ], - "hydra:totalItems": 2 + "hydra:totalItems": 3 } diff --git a/tests/Api/Shop/LocalesTest.php b/tests/Api/Shop/LocalesTest.php index ddb671f785..8a313fafdf 100644 --- a/tests/Api/Shop/LocalesTest.php +++ b/tests/Api/Shop/LocalesTest.php @@ -21,7 +21,7 @@ final class LocalesTest extends JsonApiTestCase /** @test */ public function it_gets_locales(): void { - $this->loadFixturesFromFiles(['channel.yaml', 'cart.yaml']); + $this->loadFixturesFromFiles(['channel_without_locales.yaml', 'locale.yaml']); $this->client->request(method: 'GET', uri: '/api/v2/shop/locales', server: self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse(); @@ -29,10 +29,21 @@ final class LocalesTest extends JsonApiTestCase $this->assertResponse($response, 'shop/locale/get_locales_response', Response::HTTP_OK); } + /** @test */ + public function it_gets_only_locales_from_current_channel(): void + { + $this->loadFixturesFromFiles(['locale.yaml', 'channel.yaml']); + + $this->client->request(method: 'GET', uri: '/api/v2/shop/locales', server: self::CONTENT_TYPE_HEADER); + $response = $this->client->getResponse(); + + $this->assertResponse($response, 'shop/locale/get_locales_from_channel_response', Response::HTTP_OK); + } + /** @test */ public function it_gets_locale(): void { - $this->loadFixturesFromFiles(['channel.yaml', 'cart.yaml']); + $this->loadFixturesFromFiles(['channel.yaml']); $this->client->request(method: 'GET', uri: '/api/v2/shop/locales/en_US', server: self::CONTENT_TYPE_HEADER); $response = $this->client->getResponse();