Skip to content

Commit

Permalink
Merge pull request #149 from Setono/add-api-behat
Browse files Browse the repository at this point in the history
Add first Behat scenario for API
  • Loading branch information
Roshyo authored Sep 2, 2021
2 parents 443bc1a + a3b3fdb commit f85c6c5
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 56 deletions.
17 changes: 17 additions & 0 deletions features/admin/browse_gift_cards.feature
Original file line number Diff line number Diff line change
@@ -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"
42 changes: 42 additions & 0 deletions tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Api\Admin;

use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Webmozart\Assert\Assert;

final class ManagingGiftCardsContext implements Context
{
private ApiClientInterface $client;

private ResponseCheckerInterface $responseChecker;

public function __construct(ApiClientInterface $client, ResponseCheckerInterface $responseChecker)
{
$this->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);
}
}
8 changes: 8 additions & 0 deletions tests/Behat/Resources/api.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<imports>
<import resource="api/clients.xml" />
</imports>
</container>
12 changes: 12 additions & 0 deletions tests/Behat/Resources/api/clients.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="setono_sylius_gift_card.behat.api_platform_client.admin.gift_card"
class="Sylius\Behat\Client\ApiPlatformClient" parent="sylius.behat.api_platform_client">
<argument>gift-cards</argument>
<argument>admin</argument>
</service>
</services>
</container>
14 changes: 14 additions & 0 deletions tests/Behat/Resources/context/api.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true"/>

<service id="setono_sylius_gift_card.behat.context.api.admin.managing_gift_cards"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Api\Admin\ManagingGiftCardsContext">
<argument type="service" id="setono_sylius_gift_card.behat.api_platform_client.admin.gift_card" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
</service>
</services>
</container>
17 changes: 17 additions & 0 deletions tests/Behat/Resources/context/setup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true"/>

<service id="setono_sylius_gift_card.behat.context.setup.gift_card"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Setup\GiftCardContext">
<argument type="service" id="sylius.behat.shared_storage"/>
<argument type="service" id="setono_sylius_gift_card.repository.gift_card"/>
<argument type="service" id="setono_sylius_gift_card.factory.gift_card"/>
<argument type="service" id="setono_sylius_gift_card.manager.gift_card"/>
<argument type="service" id="sylius.manager.product"/>
</service>
</services>
</container>
13 changes: 13 additions & 0 deletions tests/Behat/Resources/context/transform.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true"/>

<service id="setono_sylius_gift_card.behat.context.transform.gift_card"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Transform\GiftCardContext">
<argument type="service" id="setono_sylius_gift_card.repository.gift_card"/>
</service>
</services>
</container>
33 changes: 33 additions & 0 deletions tests/Behat/Resources/context/ui.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true"/>

<service id="setono_sylius_gift_card.behat.context.ui.admin.managing_gift_cards"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Ui\Admin\ManagingGiftCardsContext">
<argument type="service" id="setono_sylius_gift_card.behat.page.admin.product.create"/>
</service>

<service id="setono_sylius_gift_card.behat.context.ui.shop.checkout"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Ui\Shop\CheckoutContext">
<argument type="service" id="sylius.behat.context.ui.shop.checkout.complete"/>
<argument type="service" id="sylius.behat.context.setup.order"/>
<argument type="service" id="sylius.repository.order"/>
<argument type="service" id="setono_sylius_gift_card.manager.gift_card"/>
</service>

<service id="setono_sylius_gift_card.behat.context.ui.shop.cart"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Ui\Shop\CartContext">
<argument type="service" id="setono_sylius_gift_card.behat.page.shop.cart.cart_summary"/>
</service>

<service id="setono_sylius_gift_card.behat.context.ui.email"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Ui\EmailContext">
<argument type="service" id="sylius.behat.email_checker"/>
<argument type="service" id="sylius.repository.order"/>
<argument type="service" id="setono_sylius_gift_card.repository.gift_card"/>
</service>
</services>
</container>
11 changes: 11 additions & 0 deletions tests/Behat/Resources/contexts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<imports>
<import resource="context/api.xml" />
<import resource="context/setup.xml" />
<import resource="context/transform.xml" />
<import resource="context/ui.xml" />
</imports>
</container>
12 changes: 12 additions & 0 deletions tests/Behat/Resources/page/admin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="setono_sylius_gift_card.behat.page.admin.product.create"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Page\Admin\Product\CreateSimpleProductPage"
parent="sylius.behat.page.admin.crud.create" public="false">
<argument type="string">setono_sylius_gift_card_admin_product_create_gift_card</argument>
</service>
</services>
</container>
10 changes: 10 additions & 0 deletions tests/Behat/Resources/page/shop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="setono_sylius_gift_card.behat.page.shop.cart.cart_summary"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Page\Shop\Cart\SummaryPage"
parent="sylius.behat.page.shop.cart_summary" public="false"/>
</services>
</container>
9 changes: 9 additions & 0 deletions tests/Behat/Resources/pages.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<imports>
<import resource="page/admin.xml" />
<import resource="page/shop.xml" />
</imports>
</container>
61 changes: 5 additions & 56 deletions tests/Behat/Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,9 @@

<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true"/>

<!-- Setup -->
<service id="setono_sylius_gift_card.behat.context.setup.gift_card"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Setup\GiftCardContext">
<argument type="service" id="sylius.behat.shared_storage"/>
<argument type="service" id="setono_sylius_gift_card.repository.gift_card"/>
<argument type="service" id="setono_sylius_gift_card.factory.gift_card"/>
<argument type="service" id="setono_sylius_gift_card.manager.gift_card"/>
<argument type="service" id="sylius.manager.product"/>
</service>

<!-- Transform -->
<service id="setono_sylius_gift_card.behat.context.transform.gift_card"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Transform\GiftCardContext">
<argument type="service" id="setono_sylius_gift_card.repository.gift_card"/>
</service>

<!-- UI -->
<service id="setono_sylius_gift_card.behat.context.ui.admin.managing_gift_cards"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Ui\Admin\ManagingGiftCardsContext">
<argument type="service" id="setono_sylius_gift_card.behat.page.admin.product.create"/>
</service>

<service id="setono_sylius_gift_card.behat.context.ui.shop.checkout"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Ui\Shop\CheckoutContext">
<argument type="service" id="sylius.behat.context.ui.shop.checkout.complete"/>
<argument type="service" id="sylius.behat.context.setup.order"/>
<argument type="service" id="sylius.repository.order"/>
<argument type="service" id="setono_sylius_gift_card.manager.gift_card"/>
</service>

<service id="setono_sylius_gift_card.behat.context.ui.shop.cart"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Ui\Shop\CartContext">
<argument type="service" id="setono_sylius_gift_card.behat.page.shop.cart.cart_summary"/>
</service>

<service id="setono_sylius_gift_card.behat.context.ui.email"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Context\Ui\EmailContext">
<argument type="service" id="sylius.behat.email_checker"/>
<argument type="service" id="sylius.repository.order"/>
<argument type="service" id="setono_sylius_gift_card.repository.gift_card"/>
</service>

<!-- Pages -->
<service id="setono_sylius_gift_card.behat.page.admin.product.create"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Page\Admin\Product\CreateSimpleProductPage"
parent="sylius.behat.page.admin.crud.create" public="false">
<argument type="string">setono_sylius_gift_card_admin_product_create_gift_card</argument>
</service>

<service id="setono_sylius_gift_card.behat.page.shop.cart.cart_summary"
class="Tests\Setono\SyliusGiftCardPlugin\Behat\Page\Shop\Cart\SummaryPage"
parent="sylius.behat.page.shop.cart_summary" public="false"/>
</services>
<imports>
<import resource="api.xml" />
<import resource="contexts.xml" />
<import resource="pages.xml" />
</imports>
</container>
2 changes: 2 additions & 0 deletions tests/Behat/Resources/suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions tests/Behat/Resources/suites/api/managing_gift_cards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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

- setono_sylius_gift_card.behat.context.api.admin.managing_gift_cards
filters:
tags: "@managing_gift_cards && @api"

0 comments on commit f85c6c5

Please sign in to comment.