From 59c279888324c7453193d74427459881cb288c47 Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Wed, 13 Dec 2023 13:37:26 +0100 Subject: [PATCH] [ApiBundle][CatalogPromotion] Add order filters --- .../sorting_catalog_promotions.feature | 20 +++++------ .../ManagingCatalogPromotionsContext.php | 30 ++++++++++++++++ .../config/api_resources/CatalogPromotion.xml | 5 +++ .../Resources/config/services/filters.xml | 36 +++++++++++++++++++ 4 files changed, 81 insertions(+), 10 deletions(-) diff --git a/features/promotion/managing_catalog_promotions/sorting_catalog_promotions.feature b/features/promotion/managing_catalog_promotions/sorting_catalog_promotions.feature index 8a2c6d5e21..1d37a02957 100644 --- a/features/promotion/managing_catalog_promotions/sorting_catalog_promotions.feature +++ b/features/promotion/managing_catalog_promotions/sorting_catalog_promotions.feature @@ -16,69 +16,69 @@ Feature: Sorting listed catalog promotion And its priority is 2 And I am logged in as an administrator - @ui + @api @ui Scenario: Catalog promotions are sorted by ascending code by default When I browse catalog promotions Then I should see 3 catalog promotions on the list And the first catalog promotion should have code "a" - @ui + @api @ui Scenario: Changing the code sorting order to descending When I browse catalog promotions And I sort catalog promotions by descending code Then I should see 3 catalog promotions on the list And the first catalog promotion should have code "not-b" - @ui + @api @ui Scenario: Sorting catalog promotions by name in ascending order When I browse catalog promotions And I sort catalog promotions by ascending name Then I should see 3 catalog promotions on the list And the first catalog promotion should have code "a" - @ui + @api @ui Scenario: Sorting catalog promotion by name in descending order When I browse catalog promotions And I sort catalog promotions by descending name Then I should see 3 catalog promotions on the list And the first catalog promotion should have code "c" - @ui @no-postgres + @api @ui @no-postgres Scenario: Sorting catalog promotion by start date in ascending order When I browse catalog promotions And I sort catalog promotions by ascending "start date" Then I should see 3 catalog promotions on the list And the first catalog promotion should have code "not-b" - @ui @no-postgres + @api @ui @no-postgres Scenario: Sorting catalog promotion by start date in descending order When I browse catalog promotions And I sort catalog promotions by descending "start date" Then I should see 3 catalog promotions on the list And the first catalog promotion should have code "a" - @ui @no-postgres + @api @ui @no-postgres Scenario: Sorting catalog promotion by end date in ascending order When I browse catalog promotions And I sort catalog promotions by ascending "end date" Then I should see 3 catalog promotions on the list And the first catalog promotion should have code "a" - @ui @no-postgres + @api @ui @no-postgres Scenario: Sorting catalog promotion by end date in descending order When I browse catalog promotions And I sort catalog promotions by descending "end date" Then I should see 3 catalog promotions on the list And the first catalog promotion should have code "c" - @ui + @api @ui Scenario: Sorting catalog promotion by priority in ascending order When I browse catalog promotions And I sort catalog promotions by ascending priority Then I should see 3 catalog promotions on the list And the first catalog promotion should have code "not-b" - @ui + @api @ui Scenario: Sorting catalog promotion by priority in descending order When I browse catalog promotions And I sort catalog promotions by descending priority diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php index 3c0f48402b..3a24e3240f 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php @@ -888,6 +888,18 @@ final class ManagingCatalogPromotionsContext implements Context $this->client->filter(); } + /** + * @When I sort catalog promotions by :order :field + */ + public function iSortCatalogPromotionByOrderField(string $order, string $field): void + { + $this->client->addFilter( + sprintf('order[%s]', lcfirst(str_replace(' ', '', ucwords($field)))), + $order === 'descending' ? 'desc' : 'asc', + ); + $this->client->filter(); + } + /** * @When I request the removal of :catalogPromotion catalog promotion */ @@ -1554,6 +1566,24 @@ final class ManagingCatalogPromotionsContext implements Context ); } + /** + * @Then I should see :count catalog promotions on the list + */ + public function iShouldSeeCountCatalogPromotionsOnTheList(int $count): void + { + Assert::count($this->responseChecker->getCollection($this->client->getLastResponse()), $count); + } + + /** + * @Then the first catalog promotion should have code :code + */ + public function theFirstCatalogPromotionShouldHaveCode(string $code): void + { + $catalogPromotions = $this->responseChecker->getCollection($this->client->getLastResponse()); + + Assert::same(reset($catalogPromotions)['code'], $code); + } + private function catalogPromotionAppliesOnVariants(ProductVariantInterface ...$productVariants): bool { $response = $this->responseChecker->getResponseContent($this->client->getLastResponse()); diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/CatalogPromotion.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/CatalogPromotion.xml index 7b2f99a93a..6ad0399562 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/CatalogPromotion.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/CatalogPromotion.xml @@ -29,6 +29,11 @@ sylius.api.catalog_promotion_start_date_filter sylius.api.catalog_promotion_end_date_filter Sylius\Bundle\ApiBundle\Filter\Doctrine\CatalogPromotionChannelFilter + sylius.api.order_filter.code + sylius.api.order_filter.name + sylius.api.order_filter.start_date + sylius.api.order_filter.end_date + sylius.api.order_filter.priority admin:catalog_promotion:read diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml index 2799f697ba..30b875f742 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml @@ -353,5 +353,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +