Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover 'order filtration' scenarios in API #15566

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: Filtering orders by a channel
And this customer has also placed an order "#00000003" on a channel "Web-US"
And I am logged in as an administrator

@ui
@ui @api
Scenario: Filtering orders by a chosen channel
When I browse orders
And I choose "Web-EU" as a channel filter
Expand All @@ -23,7 +23,7 @@ Feature: Filtering orders by a channel
And I should see an order with "#00000002" number
But I should not see an order with "#00000003" number

@ui
@ui @api
Scenario: Filtering orders by an another channel
When I browse orders
And I choose "Web-US" as a channel filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: Filtering orders
And this customer has also placed an order "#00000003" at "2016-12-06 10:00"
And I am logged in as an administrator

@ui
@ui @api
Scenario: Filtering orders by date from
When I browse orders
And I specify filter date from as "2016-12-05 08:30"
Expand All @@ -22,7 +22,7 @@ Feature: Filtering orders
And I should see an order with "#00000003" number
But I should not see an order with "#00000001" number

@ui
@ui @api
Scenario: Filtering orders by date to
When I browse orders
And I specify filter date to as "2016-12-05 09:30"
Expand All @@ -32,7 +32,7 @@ Feature: Filtering orders
And I should see an order with "#00000002" number
But I should not see an order with "#00000003" number

@ui
@ui @api
Scenario: Filtering orders by date from to
When I browse orders
And I specify filter date from as "2016-12-05 08:30"
Expand All @@ -43,25 +43,25 @@ Feature: Filtering orders
But I should not see an order with "#00000001" number
And I should not see an order with "#00000003" number

@ui
@ui @api
Scenario: Filtering orders by date from without time
When I browse orders
And I specify filter date from as "2016-12-05"
And I specify filter date to as "2016-12-06"
And I specify filter date to as "2016-12-07"
And I filter
Then I should see 2 orders in the list
And I should see an order with "#00000002" number
And I should see an order with "#00000003" number
But I should not see an order with "#00000001" number

@ui
@ui @api
Scenario: Filtering orders placed at midnight or just before midnight
Given this customer has placed an order "#00000004" at "2016-12-10 00:00"
And this customer has also placed an order "#00000005" at "2016-12-11 23:59"
And this customer has also placed an order "#00000006" at "2016-12-12 00:00"
When I browse orders
And I specify filter date from as "2016-12-10"
And I specify filter date to as "2016-12-11"
And I specify filter date to as "2016-12-11 23:59"
And I filter
Then I should see 2 orders in the list
And I should see an order with "#00000004" number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Feature: Filtering orders by products
And the customer chose "Free" shipping method to "United States" with "Offline" payment
And I am logged in as an administrator

@ui @javascript
@ui @api @javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we establish a convention? In the system, we have three variations: @api @ui @javascript, @ui @api @javascript, and @ui @javascript @api. I know it's not a problem of this PR.

Scenario: Filtering orders by product
When I browse orders
And I filter by product "Galaxy T-Shirt"
Then I should see 2 orders in the list
And I should see an order with "#0000001" number
And I should see an order with "#0000003" number

@ui @javascript
@ui @api @javascript
Scenario: Filtering orders by multiple products
When I browse orders
And I filter by products "Galaxy T-Shirt" and "Space Dress"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Feature: Filtering orders by a shipping method
And the customer chose "DHL" shipping method to "United States" with "Offline" payment
And I am logged in as an administrator

@ui
@ui @api
Scenario: Filtering orders by DHL shipping method
When I browse orders
And I choose "DHL" as a shipping method filter
Expand All @@ -32,7 +32,7 @@ Feature: Filtering orders by a shipping method
And I should see an order with "#000001338" number
And I should not see an order with "#000001337" number

@ui
@ui @api
Scenario: Filtering orders by an another shipping method
When I browse orders
And I choose "Free" as a shipping method filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ Feature: Filtering orders by total in different currencies
And I am logged in as an administrator
And I am browsing orders

@ui
@ui @api
Scenario: Filtering orders by currency alone
When I choose "British Pound" as the filter currency
And I filter
Then I should see 3 orders in the list
But I should not see any orders with currency "USD"

@ui
@ui @api
Scenario: Filtering orders with total greater than specified amount
When I choose "US Dollar" as the filter currency
And I specify filter total being greater than 100
Expand All @@ -36,7 +36,7 @@ Feature: Filtering orders by total in different currencies
But I should not see an order with "#00000001" number
And I should not see any orders with currency "GBP"

@ui
@ui @api
Scenario: Filtering orders with total less than specified amount
When I choose "US Dollar" as the filter currency
And I specify filter total being less than 200
Expand All @@ -47,7 +47,7 @@ Feature: Filtering orders by total in different currencies
But I should not see an order with "#00000002" number
And I should not see any orders with currency "GBP"

@ui
@ui @api
Scenario: Filtering order with total from a specified range
When I choose "British Pound" as the filter currency
And I specify filter total being greater than 150.50
Expand All @@ -59,7 +59,7 @@ Feature: Filtering orders by total in different currencies
And I should not see an order with "#00000006" number
And I should not see any orders with currency "USD"

@ui
@ui @api
Scenario: Filtering orders by total in given range but with no currency provided
When I specify filter total being greater than 150
And I specify filter total being less than 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ Feature: Filtering orders by variants
And the customer chose "Free" shipping method to "United States" with "Offline" payment
And I am logged in as an administrator

@ui @javascript
@ui @api @javascript
Scenario: Filtering orders by variant
When I browse orders
And I filter by variant "Sundress"
Then I should see 2 orders in the list
And I should see an order with "#0000002" number
And I should see an order with "#0000003" number

@ui @javascript
@ui @api @javascript
Scenario: Filtering orders by multiple variants of the same product
When I browse orders
And I filter by variants "Nebula Top" and "Neutron Sleeveless"
Then I should see 2 orders in the list
And I should see an order with "#0000001" number
And I should see an order with "#0000002" number

@ui @javascript
@ui @api @javascript
Scenario: Filtering orders by multiple variants of different products
When I browse orders
And I filter by variants "Neutron Sleeveless" and "Sundress"
Expand Down
150 changes: 139 additions & 11 deletions src/Sylius/Behat/Context/Api/Admin/ManagingOrdersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
use Sylius\Behat\Service\SharedSecurityServiceInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\AdminUserInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Order\OrderTransitions;
use Sylius\Component\Payment\PaymentTransitions;
use Sylius\Component\Shipping\ShipmentTransitions;
Expand Down Expand Up @@ -62,6 +65,113 @@ public function iBrowseOrders(): void
$this->client->index(Resources::ORDERS);
}

/**
* @When I filter
*/
public function iFilter(): void
{
$this->client->filter();
}

/**
* @When I choose :channel as a channel filter
*/
public function iChooseChannelAsAChannelFilter(ChannelInterface $channel): void
{
$this->client->addFilter('channel.code', $channel->getCode());
}

/**
* @When I specify filter date from as :dateTime
*/
public function iSpecifyFilterDateFromAs(string $dateTime): void
{
$this->client->addFilter('checkoutCompletedAt[after]', $dateTime);
}

/**
* @When I specify filter date to as :dateTime
*/
public function iSpecifyFilterDateToAs(string $dateTime): void
{
$this->client->addFilter('checkoutCompletedAt[before]', $dateTime);
}


/**
* @When I filter by product :productName
* @When I filter by products :firstProduct and :secondProduct
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @When I filter by products :firstProduct and :secondProduct
* @When I filter by products :firstProductName and :secondProductName

*/
public function iFilterByProduct(string ...$productNames): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function iFilterByProduct(string ...$productNames): void
public function iFilterByProduct(string ...$productsNames): void

{
foreach ($productNames as $productName) {
$this->client->addFilter('items.productName[]', $productName);
}

$this->client->filter();
}

/**
* @When I choose :shippingMethod as a shipping method filter
*/
public function iChooseAsAShippingMethodFilter(ShippingMethodInterface $shippingMethod): void
{
$this->client->addFilter('shipments.method.code', $shippingMethod->getCode());
}

/**
* @When I choose :currency as the filter currency
*/
public function iChooseCurrencyAsTheFilterCurrency(CurrencyInterface $currency): void
{
$this->client->addFilter('currencyCode', $currency->getCode());
}

/**
* @When I specify filter total being greater than :total
*/
public function iSpecifyFilterTotalBeingGreaterThan(string $total): void
{
if (str_contains($total, '.')) {
$total = str_replace('.', '', $total);
$this->client->addFilter('total[gt]', $total);

return;
}
Comment on lines +135 to +140
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest creating a private method that either removes . or adds 00. This method could be used here and method below.


$this->client->addFilter('total[gt]', $total . '00');
}

/**
* @When I specify filter total being less than :total
*/
public function iSpecifyFilterTotalBeingLessThan(string $total): void
{
$this->client->addFilter('total[lt]', $total. '00');
}

/**
* @When I filter by variant :variantName
* @When I filter by variants :firstVariant and :secondVariant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @When I filter by variants :firstVariant and :secondVariant
* @When I filter by variants :firstVariantName and :secondVariantName

*/
public function iFilterByVariant(string ...$variantsNames): void
{
foreach ($variantsNames as $variantName) {
$this->client->addFilter('items.variant.translations.name[]', $variantName);
}

$this->client->filter();
}

/**
* @When I switch the way orders are sorted by :fieldName
*/
public function iSwitchSortingBy(string $fieldName): void
{
$this->client->addFilter('order[number]', 'asc');
$this->client->filter();
}

/**
* @When /^I cancel (this order)$/
*/
Expand Down Expand Up @@ -107,15 +217,6 @@ public function iLimitNumberOfItemsTo(int $limit): void
$this->client->filter();
}

/**
* @When I switch the way orders are sorted by :fieldName
*/
public function iSwitchSortingBy(string $fieldName): void
{
$this->client->addFilter(sprintf('order[%s]', $fieldName), 'asc');
$this->client->filter();
}

/**
* @Then I should see a single order from customer :customer
*/
Expand All @@ -133,10 +234,11 @@ public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer):

/**
* @Then I should see a single order in the list
* @Then I should see :number orders in the list
*/
public function iShouldSeeASingleOrderInTheList(): void
public function iShouldSeeASingleOrderInTheList(int $number = 1): void
{
Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), 1);
Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), $number);
}

/**
Expand Down Expand Up @@ -344,6 +446,32 @@ public function iShouldSeeOrderWithNumber(string $orderNumber): void
);
}

/**
* @Then I should not see an order with :orderNumber number
*/
public function iShouldNotSeeOrderWithNumber(string $orderNumber)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function iShouldNotSeeOrderWithNumber(string $orderNumber)
public function iShouldNotSeeOrderWithNumber(string $orderNumber): void

{
$response = $this->client->getLastResponse();

Assert::false(
$this->responseChecker->hasItemWithValue($response, 'number', $orderNumber),
sprintf('The order with number "%s" has been found, but should not.', $orderNumber),
);
}

/**
* @Then I should not see any orders with currency :currencyCode
*/
public function iShouldNotSeeAnyOrderWithCurrency(string $currencyCode): void
{
$response = $this->client->getLastResponse();

Assert::false(
$this->responseChecker->hasItemWithValue($response, 'currencyCode', $currencyCode),
sprintf('The order with currency code "%s" has been found, but should not.', $currencyCode),
);
}

/**
* @Then the first order should have number :number
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
<attribute name="method">GET</attribute>
<attribute name="path">/admin/orders</attribute>
<attribute name="filters">
<attribute>sylius.api.order_number_filter</attribute>
<attribute>sylius.api.order_channel_filter</attribute>
<attribute>sylius.api.order_currency_filter</attribute>
<attribute>sylius.api.order_customer_filter</attribute>
<attribute>sylius.api.order_channel_order_filter</attribute>
<attribute>sylius.api.order_date_filter</attribute>
<attribute>sylius.api.order_number_filter</attribute>
<attribute>sylius.api.order_product_filter</attribute>
<attribute>sylius.api.order_shipping_method_filter</attribute>
<attribute>sylius.api.order_total_filter</attribute>
<attribute>sylius.api.order_variants_filter</attribute>
</attribute>
<attribute name="order">
<attribute name="number">DESC</attribute>
Expand Down