diff --git a/features/removing_guest_wishlists.feature b/features/removing_guest_wishlists.feature new file mode 100644 index 00000000..84b313c9 --- /dev/null +++ b/features/removing_guest_wishlists.feature @@ -0,0 +1,32 @@ +@cli_wishlist +Feature: Removing guest wishlists + In order to clean guest wishlists + As a developer + I want to be able to delete wishlists created by anonymous customers by running a CLI command + + Background: + Given the store operates on a single channel in "United States" + And the store has a product "Jack Daniels Gentleman" priced at "$10.00" + And all store products appear under a main taxonomy + And I add this product to wishlist + And there are 1 wishlists in the database + + @cli + Scenario: Removing all guest wishlists + Given there is a user "test@example.com" + And user "test@example.com" "sylius" is authenticated + And there are 2 wishlists in the database + When I run delete guest wishlists command + Then the command should succeed + And there are 1 wishlists in the database + +# @cli +# Scenario: Removing guest wishlists with date +# When I run delete guests wishlists command with date "01-01-2024" +# Then the command should succeed +# +# @cli +# Scenario: Removing guest wishlists with invalid date +# When I run delete guests wishlists command with date "invalid" +# Then the command should fail +# And there are 1 wishlists in the database diff --git a/tests/Behat/Context/Cli/WishlistContext.php b/tests/Behat/Context/Cli/WishlistContext.php new file mode 100644 index 00000000..ae11ad4a --- /dev/null +++ b/tests/Behat/Context/Cli/WishlistContext.php @@ -0,0 +1,70 @@ +application = new Application($kernel); + } + + /** + * @When I run delete guest wishlists command + */ + public function runRemoveGuestWishlistsCommand(): void + { + $command = $this->application->find(self::REMOVE_GUEST_WISHLISTS_COMMAND); + + $this->commandTester = new CommandTester($command); + $this->commandTester->execute([]); + } + + /** + * @When I run delete guests wishlists command with date :date + */ + public function runRemoveGuestWishlistsCommandWithInvalidDate(string $date): void + { + $command = $this->application->find(self::REMOVE_GUEST_WISHLISTS_COMMAND); + $this->commandTester = new CommandTester($command); + $this->commandTester->execute(['--date' => $date]); + } + + /** + * @When the command should succeed + */ + public function theCommandShouldSucceed(): void + { + Assert::same($this->commandTester->getStatusCode(), 0); + } + + /** + * @When the command should fail + */ + public function theCommandShouldFail(): void + { + Assert::same($this->commandTester->getStatusCode(), 1); + } +} diff --git a/tests/Behat/Context/Common/WishlistContext.php b/tests/Behat/Context/Common/WishlistContext.php new file mode 100644 index 00000000..dd412723 --- /dev/null +++ b/tests/Behat/Context/Common/WishlistContext.php @@ -0,0 +1,31 @@ +wishlistRepository->findAll()), $count); + } +} diff --git a/tests/Behat/Resources/services.yml b/tests/Behat/Resources/services.yml index 9693b96a..b47032b2 100644 --- a/tests/Behat/Resources/services.yml +++ b/tests/Behat/Resources/services.yml @@ -37,6 +37,16 @@ services: - "@bitbag_wishlist_plugin.behat.page.wishlist.index_page" - "@bitbag_wishlist_plugin.behat.page.wishlist.chosen_show_page" + bitbag_wishlist_plugin.behat.context.cli.wishlist: + class: Tests\BitBag\SyliusWishlistPlugin\Behat\Context\Cli\WishlistContext + arguments: + - '@kernel' + + bitbag_wishlist_plugin.behat.context.common.wishlist: + class: Tests\BitBag\SyliusWishlistPlugin\Behat\Context\Common\WishlistContext + arguments: + - '@bitbag_sylius_wishlist_plugin.repository.wishlist' + bitbag_sylius_cms_plugin.behat.page.shop.wishlist: class: Tests\BitBag\SyliusWishlistPlugin\Behat\Page\Shop\WishlistPage parent: sylius.behat.symfony_page diff --git a/tests/Behat/Resources/suites.yml b/tests/Behat/Resources/suites.yml index 242f6711..f5ab2ac7 100644 --- a/tests/Behat/Resources/suites.yml +++ b/tests/Behat/Resources/suites.yml @@ -1,3 +1,4 @@ imports: - suites/ui/ui_wishlist.yml - suites/api/api_wishlist.yml + - suites/cli/cli_wishlist.yml diff --git a/tests/Behat/Resources/suites/cli/cli_wishlist.yml b/tests/Behat/Resources/suites/cli/cli_wishlist.yml new file mode 100644 index 00000000..085324fd --- /dev/null +++ b/tests/Behat/Resources/suites/cli/cli_wishlist.yml @@ -0,0 +1,22 @@ +default: + suites: + cli_wishlist: + contexts: + - sylius.behat.context.hook.doctrine_orm + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.product + - sylius.behat.context.setup.user + - sylius.behat.context.transform.lexical + - sylius.behat.context.transform.product + - sylius.behat.context.transform.product_variant + - sylius.behat.context.transform.channel + - sylius.behat.context.api.shop.channel + + - bitbag_wishlist_plugin.behat.context.api.wishlist + - bitbag_wishlist_plugin.behat.context.cli.wishlist + - bitbag_wishlist_plugin.behat.context.common.wishlist + - bitbag_sylius_cms_plugin.behat.context.ui.wishlist + - bitbag_sylius_cms_plugin.behat.context.setup.wishlist + + filters: + tags: "@cli_wishlist&&@cli"