mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[API] Implement filtering payments by state feature
This commit is contained in:
parent
0d25d47ee7
commit
559744a9b1
10 changed files with 68 additions and 19 deletions
|
|
@ -17,7 +17,7 @@ Feature: Filtering payments by state
|
|||
And there is a "Failed" "#00000006" order with "Apple" product
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Filtering payments in state "New"
|
||||
When I browse payments
|
||||
And I choose "New" as a payment state
|
||||
|
|
@ -26,49 +26,49 @@ Feature: Filtering payments by state
|
|||
And I should see the payment of the "#00000001" order
|
||||
And I should see also the payment of the "#00000005" order
|
||||
And I should see also the payment of the "#00000006" order
|
||||
But I should not see a payment of order "#00000002"
|
||||
But I should not see the payment of the "#00000002" order
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Filtering payments in state "Completed"
|
||||
When I browse payments
|
||||
And I choose "Completed" as a payment state
|
||||
And I filter
|
||||
Then I should see a single payment in the list
|
||||
And I should see the payment of the "#00000002" order
|
||||
But I should not see a payment of order "#00000003"
|
||||
But I should not see the payment of the "#00000003" order
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Filtering payments in state "Processing"
|
||||
When I browse payments
|
||||
And I choose "Processing" as a payment state
|
||||
And I filter
|
||||
Then I should see a single payment in the list
|
||||
And I should see the payment of the "#00000003" order
|
||||
But I should not see a payment of order "#00000004"
|
||||
But I should not see the payment of the "#00000004" order
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Filtering payments in state "Refunded"
|
||||
When I browse payments
|
||||
And I choose "Refunded" as a payment state
|
||||
And I filter
|
||||
Then I should see a single payment in the list
|
||||
And I should see the payment of the "#00000004" order
|
||||
But I should not see a payment of order "#00000005"
|
||||
But I should not see the payment of the "#00000005" order
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Filtering payments in state "Cancelled"
|
||||
When I browse payments
|
||||
And I choose "Cancelled" as a payment state
|
||||
And I filter
|
||||
Then I should see a single payment in the list
|
||||
And I should see the payment of the "#00000005" order
|
||||
But I should not see a payment of order "#00000006"
|
||||
But I should not see the payment of the "#00000006" order
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Filtering payments in state "Failed"
|
||||
When I browse payments
|
||||
And I choose "Failed" as a payment state
|
||||
And I filter
|
||||
Then I should see a single payment in the list
|
||||
And I should see the payment of the "#00000006" order
|
||||
But I should not see a payment of order "#00000001"
|
||||
But I should not see the payment of the "#00000001" order
|
||||
|
|
|
|||
|
|
@ -13,9 +13,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Behat\Context\Api\Admin;
|
||||
|
||||
use ApiPlatform\Core\Api\IriConverterInterface;
|
||||
use Behat\Behat\Context\Context;
|
||||
use Sylius\Behat\Client\ApiClientInterface;
|
||||
use Sylius\Component\Core\Formatter\StringInflector;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Model\CustomerInterface;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Payment\PaymentTransitions;
|
||||
|
|
@ -26,9 +28,13 @@ final class ManagingPaymentsContext implements Context
|
|||
/** @var ApiClientInterface */
|
||||
private $client;
|
||||
|
||||
public function __construct(ApiClientInterface $client)
|
||||
/** @var IriConverterInterface */
|
||||
private $iriConverter;
|
||||
|
||||
public function __construct(ApiClientInterface $client, IriConverterInterface $iriConverter)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->iriConverter = $iriConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -55,6 +61,22 @@ final class ManagingPaymentsContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I choose :state as a payment state
|
||||
*/
|
||||
public function iChooseAsAPaymentState(string $state): void
|
||||
{
|
||||
$this->client->buildFilter(['state' => $state]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I filter
|
||||
*/
|
||||
public function iFilter(): void
|
||||
{
|
||||
$this->client->filter('payments');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see a single payment in the list
|
||||
* @Then I should see :count payments in the list
|
||||
|
|
@ -114,4 +136,20 @@ final class ManagingPaymentsContext implements Context
|
|||
$this->client->show('payments', (string) $payment->getId());
|
||||
Assert::true($this->client->responseHasValue('state', StringInflector::nameToLowercaseCode($paymentState)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see (also) the payment of the :order order
|
||||
*/
|
||||
public function iShouldSeeThePaymentOfTheOrder(OrderInterface $order): void
|
||||
{
|
||||
Assert::true($this->client->hasItemWithValue('order', $this->iriConverter->getIriFromItem($order)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should not see the payment of the :order order
|
||||
*/
|
||||
public function iShouldNotSeeThePaymentOfTheOrder(OrderInterface $order): void
|
||||
{
|
||||
Assert::false($this->client->hasItemWithValue('order', $this->iriConverter->getIriFromItem($order)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -433,7 +433,7 @@ final class OrderContext implements Context
|
|||
* @Given there is an :orderNumber order with :product product
|
||||
* @Given there is an :orderNumber order with :product product in this channel
|
||||
* @Given there is an :orderNumber order with :product product in :channel channel
|
||||
* @Given there is a :state :orderName order with :product product
|
||||
* @Given there is a :state :orderNumber order with :product product
|
||||
*/
|
||||
public function thereIsAOrderWithProduct(
|
||||
string $orderNumber,
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ declare(strict_types=1);
|
|||
namespace Sylius\Behat\Context\Transform;
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
|
||||
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
|
@ -37,7 +38,7 @@ final class OrderContext implements Context
|
|||
/**
|
||||
* @Transform :order
|
||||
*/
|
||||
public function getOrderByNumber($orderNumber)
|
||||
public function getOrderByNumber(string $orderNumber): OrderInterface
|
||||
{
|
||||
$orderNumber = $this->getOrderNumber($orderNumber);
|
||||
$order = $this->orderRepository->findOneBy(['number' => $orderNumber]);
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ final class ManagingPaymentsContext implements Context
|
|||
|
||||
/**
|
||||
* @Then I should not see a payment of order :orderNumber
|
||||
* @Then I should not see the payment of the :orderNumber order
|
||||
*/
|
||||
public function iShouldNotSeeAPaymentOfOrder(string $orderNumber): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@
|
|||
|
||||
<service id="sylius.behat.context.api.admin.managing_payments" class="Sylius\Behat\Context\Api\Admin\ManagingPaymentsContext">
|
||||
<argument type="service" id="Sylius\Behat\Client\ApiClientInterface" />
|
||||
<argument type="service" id="api_platform.iri_converter" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ default:
|
|||
|
||||
- sylius.behat.context.transform.channel
|
||||
- sylius.behat.context.transform.customer
|
||||
- sylius.behat.context.transform.lexical
|
||||
- sylius.behat.context.transform.order
|
||||
- sylius.behat.context.transform.product
|
||||
- sylius.behat.context.transform.shared_storage
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
<collectionOperations>
|
||||
<collectionOperation name="get">
|
||||
<attribute name="order">
|
||||
<attribute name="position">ASC</attribute>
|
||||
<attribute name="filters">
|
||||
<attribute>sylius.api.search_payment_filter</attribute>
|
||||
</attribute>
|
||||
</collectionOperation>
|
||||
</collectionOperations>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<imports>
|
||||
<import resource="filters.xml"/>
|
||||
<import resource="services/filters.xml"/>
|
||||
</imports>
|
||||
|
||||
<services>
|
||||
|
|
|
|||
|
|
@ -9,9 +9,16 @@
|
|||
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="sylius.api.search_payment_filter" parent="api_platform.doctrine.orm.search_filter">
|
||||
<argument type="collection">
|
||||
<argument key="state">exact</argument>
|
||||
</argument>
|
||||
<tag name="api_platform.filter" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.api.filter.exchange_rate" class="Sylius\Bundle\ApiBundle\Filters\ExchangeRateFilter">
|
||||
<tag name="api_platform.filter" id="exchange_rate_filter" />
|
||||
<argument type="service" id="doctrine" />
|
||||
<tag name="api_platform.filter" id="exchange_rate_filter" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
Loading…
Add table
Reference in a new issue