From 2df7a2e451b2250e2bd36a7dff2ca7a803d89988 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 23 Feb 2024 10:47:29 +0100 Subject: [PATCH] [API][Shop] Add missing contract test for getting only countries from current channel --- .../ORM/channel_with_countries.yaml | 26 ++++++++++++++ .../get_countries_from_channel_response.json | 35 +++++++++++++++++++ tests/Api/Shop/CountriesTest.php | 11 ++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/Api/DataFixtures/ORM/channel_with_countries.yaml create mode 100644 tests/Api/Responses/shop/country/get_countries_from_channel_response.json diff --git a/tests/Api/DataFixtures/ORM/channel_with_countries.yaml b/tests/Api/DataFixtures/ORM/channel_with_countries.yaml new file mode 100644 index 0000000000..c5b459fa97 --- /dev/null +++ b/tests/Api/DataFixtures/ORM/channel_with_countries.yaml @@ -0,0 +1,26 @@ +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' + locales: ['@locale_en', '@locale_pl'] + color: 'black' + enabled: true + taxCalculationStrategy: 'order_items_based' + countries: ['@country_US', '@country_FR'] + +Sylius\Component\Currency\Model\Currency: + currency_usd: + code: 'USD' + +Sylius\Component\Locale\Model\Locale: + locale_en: + code: 'en_US' + locale_pl: + code: 'pl_PL' + locale_de: + code: 'de_DE' diff --git a/tests/Api/Responses/shop/country/get_countries_from_channel_response.json b/tests/Api/Responses/shop/country/get_countries_from_channel_response.json new file mode 100644 index 0000000000..c27184e470 --- /dev/null +++ b/tests/Api/Responses/shop/country/get_countries_from_channel_response.json @@ -0,0 +1,35 @@ +{ + "@context": "\/api\/v2\/contexts\/Country", + "@id": "\/api\/v2\/shop\/countries", + "@type": "hydra:Collection", + "hydra:member": [ + { + "@id": "\/api\/v2\/shop\/countries\/US", + "@type": "Country", + "code": "US", + "name": "United States", + "provinces": [ + { + "@id": "\/api\/v2\/shop\/provinces\/US-MI", + "@type": "Province", + "code": "US-MI", + "name": "Minnesota" + }, + { + "@id": "\/api\/v2\/shop\/provinces\/US-WY", + "@type": "Province", + "code": "US-WY", + "name": "Wyoming" + } + ] + }, + { + "@id": "\/api\/v2\/shop\/countries\/FR", + "@type": "Country", + "code": "FR", + "name": "France", + "provinces": [] + } + ], + "hydra:totalItems": 2 +} diff --git a/tests/Api/Shop/CountriesTest.php b/tests/Api/Shop/CountriesTest.php index 3ee66eec4a..e367da159e 100644 --- a/tests/Api/Shop/CountriesTest.php +++ b/tests/Api/Shop/CountriesTest.php @@ -29,6 +29,17 @@ final class CountriesTest extends JsonApiTestCase $this->assertResponse($response, 'shop/country/get_countries_response', Response::HTTP_OK); } + /** @test */ + public function it_gets_only_countries_from_current_channel(): void + { + $this->loadFixturesFromFiles(['channel_with_countries.yaml', 'country.yaml']); + + $this->client->request(method: 'GET', uri: '/api/v2/shop/countries', server: self::CONTENT_TYPE_HEADER); + $response = $this->client->getResponse(); + + $this->assertResponse($response, 'shop/country/get_countries_from_channel_response', Response::HTTP_OK); + } + /** @test */ public function it_gets_a_country(): void {