Skip to content

Commit

Permalink
feature #14990 [API] Sorting user orders by order number (dawkaa)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.13 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.13                  |
| Bug fix?        | no                                                       |
| New feature?    | yes                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | no |
| Related tickets | part of #11250 |
| License         | MIT                                                          |

<!--
 - Bug fixes must be submitted against the 1.12 branch
 - Features and deprecations must be submitted against the 1.13 branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------

76d5102 [API] Sorting user orders by order number
7ac1948 Added tests to sorting user orders
4c0d93a Fixes for a conversation
  • Loading branch information
GSadee committed Jun 9, 2023
2 parents 0d8d558 + 4c0d93a commit 0fe3bcd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Feature: Sorting orders by their number
And the customer chose "Free" shipping method to "United States" with "Offline" payment
And I am logged in as an administrator

@ui
@ui @api
Scenario: Orders are sorted by descending numbers by default
When I browse orders
Then I should see an order with "#000000001" number
But the first order should have number "#000000003"

@ui
@ui @api
Scenario: Changing the number sorting order
Given I am browsing orders
When I switch the way orders are sorted by number
Expand Down
36 changes: 35 additions & 1 deletion src/Sylius/Behat/Context/Api/Admin/ManagingOrdersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
private ResponseCheckerInterface $responseChecker,
private IriConverterInterface $iriConverter,
private SecurityServiceInterface $adminSecurityService,
private SharedStorageInterface $sharedStorage,
private SharedStorageInterface $sharedStorage
) {
}

Expand All @@ -49,6 +49,7 @@ public function iSeeTheOrder(OrderInterface $order): void
}

/**
* @Given I am browsing orders
* @When I browse orders
*/
public function iBrowseOrders(): void
Expand Down Expand Up @@ -311,4 +312,37 @@ public function theAdministratorShouldSeeThatThisOrderHasBeenPlacedIn(

Assert::same($currencyCode, $currency);
}

/**
* @Then I should see an order with :orderNumber number
*/
public function iShouldSeeOrderWithNumber(string $orderNumber)
{
$response = $this->client->getLastResponse();

Assert::true(
$this->responseChecker->hasItemWithValue($response, 'number', $orderNumber),
sprintf('No order with number "%s" has been found.', $orderNumber),
);
}

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

/**
* @Then the first order should have number :number
*/
public function theFirstOrderShouldHaveNumber(string $number)
{
$items = $this->responseChecker->getValue($this->client->getLastResponse(), 'hydra:member');
$firstItem = $items[0];

Assert::same($firstItem['number'], str_replace('#', '', $number));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<collectionOperation name="admin_get">
<attribute name="method">GET</attribute>
<attribute name="path">admin/orders</attribute>
<attribute name="filters">
<attribute>sylius.api.order_number_filter</attribute>
</attribute>
<attribute name="order">
<attribute name="number">DESC</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:order:read</attribute>
</attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,12 @@
</argument>
<tag name="api_platform.filter" />
</service>

<service id="sylius.api.order_number_filter" parent="api_platform.doctrine.orm.order_filter" public="true">
<argument type="collection">
<argument key="number" />
</argument>
<tag name="api_platform.filter" />
</service>
</services>
</container>

0 comments on commit 0fe3bcd

Please sign in to comment.