diff --git a/features/user/managing_customers/adding_customer.feature b/features/user/managing_customers/adding_customer.feature index 5a7408c08a..69f0835853 100644 --- a/features/user/managing_customers/adding_customer.feature +++ b/features/user/managing_customers/adding_customer.feature @@ -8,7 +8,7 @@ Feature: Adding a new customer Given the store has a customer group "Retail" And I am logged in as an administrator - @ui + @ui @api Scenario: Adding a new customer When I want to create a new customer And I specify their email as "l.skywalker@gmail.com" @@ -16,7 +16,7 @@ Feature: Adding a new customer Then I should be notified that it has been successfully created And the customer "l.skywalker@gmail.com" should appear in the store - @ui + @ui @api Scenario: Adding a new customer with full details When I want to create a new customer And I specify their first name as "Luke" diff --git a/features/user/managing_customers/adding_customer_account.feature b/features/user/managing_customers/adding_customer_account.feature index 1756707d3a..d6ac0c378b 100644 --- a/features/user/managing_customers/adding_customer_account.feature +++ b/features/user/managing_customers/adding_customer_account.feature @@ -7,7 +7,7 @@ Feature: Adding a new customer account Background: Given I am logged in as an administrator - @ui @javascript + @ui @javascript @api Scenario: Adding a new customer with an account When I want to create a new customer account And I specify their email as "l.skywalker@gmail.com" @@ -18,7 +18,7 @@ Feature: Adding a new customer account And the customer "l.skywalker@gmail.com" should appear in the store And the customer "l.skywalker@gmail.com" should have an account created - @ui @javascript + @ui @javascript @api Scenario: Creating an account for existing customer Given the store has customer "Frodo Baggins" with email "f.baggins@example.com" When I want to edit this customer @@ -28,4 +28,4 @@ Feature: Adding a new customer account Then I should be notified that it has been successfully edited And I should not see create account option And the customer "f.baggins@example.com" should appear in the store - And this customer should have an account created + And the customer "f.baggins@example.com" should have an account created diff --git a/features/user/managing_customers/adding_customer_account_after_failed_creation_action.feature b/features/user/managing_customers/adding_customer_account_after_failed_creation_action.feature index d372b2e94c..90b47c63b1 100644 --- a/features/user/managing_customers/adding_customer_account_after_failed_creation_action.feature +++ b/features/user/managing_customers/adding_customer_account_after_failed_creation_action.feature @@ -7,7 +7,7 @@ Feature: Adding a new customer account after failed creation action Background: Given I am logged in as an administrator - @ui @javascript + @ui @javascript @api Scenario: Trying to add new customer with an account without required information When I want to create a new customer account And I choose create account option @@ -19,7 +19,7 @@ Feature: Adding a new customer account after failed creation action And I should be notified that email is required And I should be notified that password is required - @ui @javascript + @ui @javascript @api Scenario: Trying to add new customer with an account without email When I want to create a new customer account And I choose create account option @@ -31,7 +31,7 @@ Feature: Adding a new customer account after failed creation action And I should not be able to select create account option And I should be notified that email is required - @ui @javascript + @ui @javascript @api Scenario: Trying to add new customer without an account without email When I want to create a new customer account And I do not choose create account option @@ -42,7 +42,7 @@ Feature: Adding a new customer account after failed creation action And I should be able to select create account option And I should be notified that email is required - @ui @javascript + @ui @javascript @api Scenario: Trying to add new customer with an account without required information When I want to create a new customer account And I choose create account option diff --git a/features/user/managing_customers/being_able_to_create_account_for_existing_customer.feature b/features/user/managing_customers/being_able_to_create_account_for_existing_customer.feature index 06a5bb101a..8467d289e4 100644 --- a/features/user/managing_customers/being_able_to_create_account_for_existing_customer.feature +++ b/features/user/managing_customers/being_able_to_create_account_for_existing_customer.feature @@ -7,7 +7,7 @@ Feature: Create account option availability Background: And I am logged in as an administrator - @ui + @ui @api Scenario: Being able to create an account for created customer When I want to create a new customer And I do not choose create account option @@ -17,7 +17,7 @@ Feature: Create account option availability And I should not be able to specify their password And I should be able to select create account option - @ui @javascript + @ui @javascript @api Scenario: Not seeing create account option after adding customer with account When I want to create a new customer account And I choose create account option diff --git a/features/user/managing_customers/browsing_customers.feature b/features/user/managing_customers/browsing_customers.feature index 78601a1559..0fe3f0229a 100644 --- a/features/user/managing_customers/browsing_customers.feature +++ b/features/user/managing_customers/browsing_customers.feature @@ -10,7 +10,7 @@ Feature: Browsing customers And the store has customer "l.skywalker@example.com" And I am logged in as an administrator - @ui + @ui @api Scenario: Browsing customers in store When I want to see all customers in store Then I should see 3 customers in the list diff --git a/features/user/managing_customers/browsing_orders_of_customer.feature b/features/user/managing_customers/browsing_orders_of_customer.feature index 3d31fc6368..c788c81a48 100644 --- a/features/user/managing_customers/browsing_orders_of_customer.feature +++ b/features/user/managing_customers/browsing_orders_of_customer.feature @@ -17,14 +17,14 @@ Feature: Browsing orders of a customer And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment And I am logged in as an administrator - @ui + @api Scenario: Browsing orders of a specific customer in the list When I browse orders of a customer "logan@wolverine.com" Then I should see a single order in the list And I should see the order with number "#00000007" in the list And I should not see the order with number "#00000008" in the list - @ui + @api Scenario: Browsing orders of a specific customer in the list When I browse orders of a customer "logan@wolverine.com" And I sort them by channel diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingCustomersContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingCustomersContext.php new file mode 100644 index 0000000000..c80b3ea42e --- /dev/null +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingCustomersContext.php @@ -0,0 +1,251 @@ +client->buildCreateRequest(Resources::CUSTOMERS); + } + + /** + * @When /^I want to edit (this customer)$/ + */ + public function iWantToEditThisCustomer(CustomerInterface $customer): void + { + $this->client->buildUpdateRequest(Resources::CUSTOMERS, (string) $customer->getId()); + } + + /** + * @When I specify their email as :name + * @When I do not specify their email + */ + public function iSpecifyItsEmailAs(?string $email = null): void + { + if (null !== $email) { + $this->client->addRequestData('email', $email); + } + } + + /** + * @When I specify their first name as :name + */ + public function iSpecifyTheirFirstNameAs(string $name): void + { + $this->client->addRequestData('firstName', $name); + } + + /** + * @When I specify their last name as :name + */ + public function iSpecifyTheirLastNameAs(string $name): void + { + $this->client->addRequestData('lastName', $name); + } + + /** + * @When I specify its birthday as :birthday + */ + public function iSpecifyItsBirthdayAs(string $birthday): void + { + $this->client->addRequestData('birthday', $birthday); + } + + /** + * @When I select :gender as its gender + */ + public function iSelectGender(string $gender): void + { + $this->client->addRequestData('gender', strtolower(substr($gender, 0, 1))); + } + + /** + * @When I select :customerGroup as their group + */ + public function iSelectGroup(CustomerGroupInterface $customerGroup): void + { + $this->client->addRequestData('group', $this->iriConverter->getIriFromItem($customerGroup)); + } + + /** + * @When I choose create account option + */ + public function iChooseCreateAccountOption(): void + { + $this->client->addRequestData('user', []); + } + + /** + * @When I specify their password as :password + */ + public function iSpecifyItsPasswordAs(string $password): void + { + $this->client->addRequestData('user', [ + 'plainPassword' => $password, + ]); + } + + /** + * @When I (try to) add them + */ + public function iAddIt(): void + { + $this->client->create(); + } + + /** + * @When I want to see all customers in store + */ + public function iWantToSeeAllZonesInStore(): void + { + $this->client->index(Resources::CUSTOMERS); + } + + /** + * @When I do not specify any information + */ + public function iDoNotSpecifyAnyInformation(): void + { + // Intentionally left empty + } + + /** + * @When I do not choose create account option + */ + public function iDoNotChooseCreateAccountOption() + { + // Intentionally left blank. + } + + /** + * @Then I should be notified that it has been successfully created + */ + public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void + { + Assert::true( + $this->responseChecker->isCreationSuccessful($this->client->getLastResponse()), + 'Customer could not be created', + ); + } + + /** + * @Then the customer :customer should appear in the store + * @Then the customer :customer should still have this email + */ + public function theCustomerShouldAppearInTheStore(CustomerInterface $customer): void + { + Assert::true( + $this->responseChecker->hasItemWithValue($this->client->index(Resources::CUSTOMERS), 'email', $customer->getEmail()), + sprintf('Customer with email %s does not exist', $customer->getEmail()), + ); + } + + /** + * @Then the customer :customer should have an account created + * @Then /^(this customer) should have an account created$/ + */ + public function theyShouldHaveAnAccountCreated(CustomerInterface $customer): void + { + Assert::notNull( + $customer->getUser()->getPassword(), + 'Customer should have an account, but they do not.', + ); + } + + /** + * @Then I should see :count customers in the list + * @Then I should see a single customer on the list + */ + public function iShouldSeeZonesInTheList(int $count = 1): void + { + Assert::same($this->responseChecker->countCollectionItems($this->client->index(Resources::CUSTOMERS)), $count); + } + + /** + * @Then I should see the customer :email in the list + */ + public function iShouldSeeTheCustomerInTheList(string $email): void + { + Assert::true( + $this->responseChecker->hasItemWithValue($this->client->index(Resources::CUSTOMERS), 'email', $email), + sprintf('There is no customer with email "%s"', $email), + ); + } + + /** + * @Then /^I should be notified that ([^"]+) is required$/ + */ + public function iShouldBeNotifiedThatIsRequired(string $element): void + { + Assert::contains( + $this->responseChecker->getError($this->client->getLastResponse()), + sprintf('Please enter your %s.', $element), + ); + } + + /** + * @Then I should not see create account option + */ + public function iShouldNotSeeCreateAccountOption(): void + { + // Intentionally left empty + } + + /** + * @Then I should still be on the customer creation page + */ + public function iShouldStillBeOnTheCustomerCreationPage(): void + { + // Intentionally left empty + } + + /** + * @Then I should be able to specify their password + * @Then I should not be able to specify their password + */ + public function iShouldBeAbleToSpecifyTheirPassword(): void + { + // Intentionally left empty + } + + /** + * @Then I should be able to select create account option + * @Then I should not be able to select create account option + */ + public function iShouldBeAbleToSelectCreateAccountOption(): void + { + // Intentionally left empty + } +} diff --git a/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml b/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml index 66484e80ed..b60a4180af 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml @@ -236,5 +236,11 @@ + + + + + + diff --git a/src/Sylius/Behat/Resources/config/suites.yml b/src/Sylius/Behat/Resources/config/suites.yml index ff1ba17391..cb1b1f00bc 100644 --- a/src/Sylius/Behat/Resources/config/suites.yml +++ b/src/Sylius/Behat/Resources/config/suites.yml @@ -61,6 +61,7 @@ imports: - suites/api/taxon/managing_taxons_ajax.yml - suites/api/user/managing_administrators.yml - suites/api/user/managing_customer_groups.yml + - suites/api/user/managing_customers.yml - suites/cli/canceling_unpaid_orders.yml - suites/cli/installer.yml diff --git a/src/Sylius/Behat/Resources/config/suites/api/user/managing_customers.yml b/src/Sylius/Behat/Resources/config/suites/api/user/managing_customers.yml new file mode 100644 index 0000000000..8d6e4fb3b5 --- /dev/null +++ b/src/Sylius/Behat/Resources/config/suites/api/user/managing_customers.yml @@ -0,0 +1,24 @@ +# This file is part of the Sylius package. +# (c) Sylius Sp. z o.o. + +default: + suites: + api_managing_customers: + contexts: + - sylius.behat.context.hook.doctrine_orm + + - sylius.behat.context.transform.customer + - sylius.behat.context.transform.customer_group + - sylius.behat.context.transform.shared_storage + + - sylius.behat.context.setup.admin_api_security + - sylius.behat.context.setup.customer + - sylius.behat.context.setup.customer_group + + - sylius.behat.context.api.admin.managing_customers + - sylius.behat.context.api.admin.response + - sylius.behat.context.api.admin.save + + filters: + tags: "@managing_customers&&@api" + javascript: false