From 648fde23f8e3ef2bb74da5cba46879664ad0a9ad Mon Sep 17 00:00:00 2001 From: Roshyo Date: Wed, 1 Sep 2021 13:56:51 +0200 Subject: [PATCH 1/3] Add first Behat scenario for API --- features/admin/browse_gift_cards.feature | 17 ++++++ .../Api/Admin/ManagingGiftCardsContext.php | 42 +++++++++++++ tests/Behat/Resources/api.xml | 8 +++ tests/Behat/Resources/api/clients.xml | 14 +++++ tests/Behat/Resources/context/api.xml | 14 +++++ tests/Behat/Resources/context/setup.xml | 17 ++++++ tests/Behat/Resources/context/transform.xml | 13 ++++ tests/Behat/Resources/context/ui.xml | 33 ++++++++++ tests/Behat/Resources/contexts.xml | 11 ++++ tests/Behat/Resources/page/admin.xml | 14 +++++ tests/Behat/Resources/page/shop.xml | 12 ++++ tests/Behat/Resources/pages.xml | 9 +++ tests/Behat/Resources/services.xml | 61 ++----------------- tests/Behat/Resources/suites.yml | 2 + .../suites/api/managing_gift_cards.yml | 21 +++++++ 15 files changed, 232 insertions(+), 56 deletions(-) create mode 100644 features/admin/browse_gift_cards.feature create mode 100644 tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php create mode 100644 tests/Behat/Resources/api.xml create mode 100644 tests/Behat/Resources/api/clients.xml create mode 100644 tests/Behat/Resources/context/api.xml create mode 100644 tests/Behat/Resources/context/setup.xml create mode 100644 tests/Behat/Resources/context/transform.xml create mode 100644 tests/Behat/Resources/context/ui.xml create mode 100644 tests/Behat/Resources/contexts.xml create mode 100644 tests/Behat/Resources/page/admin.xml create mode 100644 tests/Behat/Resources/page/shop.xml create mode 100644 tests/Behat/Resources/pages.xml create mode 100644 tests/Behat/Resources/suites/api/managing_gift_cards.yml diff --git a/features/admin/browse_gift_cards.feature b/features/admin/browse_gift_cards.feature new file mode 100644 index 00000000..cfa02498 --- /dev/null +++ b/features/admin/browse_gift_cards.feature @@ -0,0 +1,17 @@ +@managing_gift_cards +Feature: Browsing existing gift cards + In order to manage the existing gift cards + As an Administrator + I want to browse existing gift cards + + Background: + Given the store operates on a single channel in "United States" + And I am logged in as an administrator + And the store has a gift card with code "GIFT-CARD-100" valued at "$100" + And the store has a gift card with code "GIFT-CARD-200" valued at "$200" + + @api + Scenario: Browsing gift cards + When I browse gift cards + Then I should see a gift card with code "GIFT-CARD-100" valued at "$100" + And I should see a gift card with code "GIFT-CARD-200" valued at "$200" diff --git a/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php b/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php new file mode 100644 index 00000000..e56b6126 --- /dev/null +++ b/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php @@ -0,0 +1,42 @@ +client = $client; + $this->responseChecker = $responseChecker; + } + + /** + * @When I browse gift cards + */ + public function iBrowseGiftCards(): void + { + $this->client->index(); + } + + /** + * @Then /^I should see a gift card with code "([^"]+)" valued at ("[^"]+")$/ + */ + public function iShouldSeeGiftCardPricedAt(string $code, int $price): void + { + $response = $this->client->show($code); + + $giftCardPrice = $this->responseChecker->getValue($response, 'amount'); + Assert::same($price, $giftCardPrice); + } +} diff --git a/tests/Behat/Resources/api.xml b/tests/Behat/Resources/api.xml new file mode 100644 index 00000000..1a7616ae --- /dev/null +++ b/tests/Behat/Resources/api.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/tests/Behat/Resources/api/clients.xml b/tests/Behat/Resources/api/clients.xml new file mode 100644 index 00000000..cd9bc476 --- /dev/null +++ b/tests/Behat/Resources/api/clients.xml @@ -0,0 +1,14 @@ + + + + + + + + gift-cards + admin + + + diff --git a/tests/Behat/Resources/context/api.xml b/tests/Behat/Resources/context/api.xml new file mode 100644 index 00000000..f791677c --- /dev/null +++ b/tests/Behat/Resources/context/api.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/tests/Behat/Resources/context/setup.xml b/tests/Behat/Resources/context/setup.xml new file mode 100644 index 00000000..fba33cfe --- /dev/null +++ b/tests/Behat/Resources/context/setup.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + diff --git a/tests/Behat/Resources/context/transform.xml b/tests/Behat/Resources/context/transform.xml new file mode 100644 index 00000000..400b444c --- /dev/null +++ b/tests/Behat/Resources/context/transform.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/tests/Behat/Resources/context/ui.xml b/tests/Behat/Resources/context/ui.xml new file mode 100644 index 00000000..da1267d0 --- /dev/null +++ b/tests/Behat/Resources/context/ui.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Behat/Resources/contexts.xml b/tests/Behat/Resources/contexts.xml new file mode 100644 index 00000000..08adb3d6 --- /dev/null +++ b/tests/Behat/Resources/contexts.xml @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/tests/Behat/Resources/page/admin.xml b/tests/Behat/Resources/page/admin.xml new file mode 100644 index 00000000..8b01929f --- /dev/null +++ b/tests/Behat/Resources/page/admin.xml @@ -0,0 +1,14 @@ + + + + + + + + setono_sylius_gift_card_admin_product_create_gift_card + + + diff --git a/tests/Behat/Resources/page/shop.xml b/tests/Behat/Resources/page/shop.xml new file mode 100644 index 00000000..91f2afe5 --- /dev/null +++ b/tests/Behat/Resources/page/shop.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/tests/Behat/Resources/pages.xml b/tests/Behat/Resources/pages.xml new file mode 100644 index 00000000..f4cc16bb --- /dev/null +++ b/tests/Behat/Resources/pages.xml @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/tests/Behat/Resources/services.xml b/tests/Behat/Resources/services.xml index fc539701..4ada45d2 100644 --- a/tests/Behat/Resources/services.xml +++ b/tests/Behat/Resources/services.xml @@ -2,60 +2,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - setono_sylius_gift_card_admin_product_create_gift_card - - - - + + + + + diff --git a/tests/Behat/Resources/suites.yml b/tests/Behat/Resources/suites.yml index b1ad8e87..bde4e732 100644 --- a/tests/Behat/Resources/suites.yml +++ b/tests/Behat/Resources/suites.yml @@ -2,3 +2,5 @@ imports: - suites/ui/managing_gift_cards.yml - suites/ui/buying_gift_card.yml - suites/ui/applying_gift_card.yml + + - suites/api/managing_gift_cards.yml diff --git a/tests/Behat/Resources/suites/api/managing_gift_cards.yml b/tests/Behat/Resources/suites/api/managing_gift_cards.yml new file mode 100644 index 00000000..22d68096 --- /dev/null +++ b/tests/Behat/Resources/suites/api/managing_gift_cards.yml @@ -0,0 +1,21 @@ +default: + suites: + api_managing_gift_cards: + contexts: + - sylius.behat.context.hook.doctrine_orm + + - sylius.behat.context.transform.lexical + - sylius.behat.context.transform.shared_storage + + - sylius.behat.context.setup.admin_api_security + - sylius.behat.context.setup.channel + + - setono_sylius_gift_card.behat.context.setup.gift_card + - setono_sylius_gift_card.behat.context.transform.gift_card + + - sylius.behat.context.ui.admin.notification + + - sylius.behat.context.ui.admin.managing_products + - setono_sylius_gift_card.behat.context.api.admin.managing_gift_cards + filters: + tags: "@managing_gift_cards && @api" From 8116351a6ee5e5c14457dfc34ebf984ebb7f75d8 Mon Sep 17 00:00:00 2001 From: Roshyo Date: Wed, 1 Sep 2021 13:59:03 +0200 Subject: [PATCH 2/3] Remove un-necessary contexts --- tests/Behat/Resources/suites/api/managing_gift_cards.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Behat/Resources/suites/api/managing_gift_cards.yml b/tests/Behat/Resources/suites/api/managing_gift_cards.yml index 22d68096..b9aaab4b 100644 --- a/tests/Behat/Resources/suites/api/managing_gift_cards.yml +++ b/tests/Behat/Resources/suites/api/managing_gift_cards.yml @@ -13,9 +13,6 @@ default: - setono_sylius_gift_card.behat.context.setup.gift_card - setono_sylius_gift_card.behat.context.transform.gift_card - - sylius.behat.context.ui.admin.notification - - - sylius.behat.context.ui.admin.managing_products - setono_sylius_gift_card.behat.context.api.admin.managing_gift_cards filters: tags: "@managing_gift_cards && @api" From a3b3fdbc33ec916ac39d075040913faeb183c255 Mon Sep 17 00:00:00 2001 From: Roshyo Date: Wed, 1 Sep 2021 16:36:56 +0200 Subject: [PATCH 3/3] Remove public where not needed --- tests/Behat/Resources/api/clients.xml | 2 -- tests/Behat/Resources/page/admin.xml | 2 -- tests/Behat/Resources/page/shop.xml | 2 -- 3 files changed, 6 deletions(-) diff --git a/tests/Behat/Resources/api/clients.xml b/tests/Behat/Resources/api/clients.xml index cd9bc476..b82bddfd 100644 --- a/tests/Behat/Resources/api/clients.xml +++ b/tests/Behat/Resources/api/clients.xml @@ -3,8 +3,6 @@ - - gift-cards diff --git a/tests/Behat/Resources/page/admin.xml b/tests/Behat/Resources/page/admin.xml index 8b01929f..929c5a10 100644 --- a/tests/Behat/Resources/page/admin.xml +++ b/tests/Behat/Resources/page/admin.xml @@ -3,8 +3,6 @@ - - diff --git a/tests/Behat/Resources/page/shop.xml b/tests/Behat/Resources/page/shop.xml index 91f2afe5..1d09354b 100644 --- a/tests/Behat/Resources/page/shop.xml +++ b/tests/Behat/Resources/page/shop.xml @@ -3,8 +3,6 @@ - -