[ApiBundle] Unify behat tests for customer management

This commit is contained in:
Wojdylak 2023-10-30 08:19:19 +01:00
parent 0ccbcf8943
commit 0cd1fa74d2
18 changed files with 104 additions and 108 deletions

View file

@ -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 @api
@api @ui
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 @api
@api @ui
Scenario: Adding a new customer with full details
When I want to create a new customer
And I specify their first name as "Luke"

View file

@ -7,7 +7,7 @@ Feature: Adding a new customer account
Background:
Given I am logged in as an administrator
@ui @javascript @api
@api @ui @javascript
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 @api
@api @ui @javascript
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

View file

@ -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 @api
@api @ui @javascript
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 @api
@api @ui @javascript
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 @api
@api @ui @javascript
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 @api
@api @ui @javascript
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

View file

@ -7,7 +7,7 @@ Feature: Create account option availability
Background:
And I am logged in as an administrator
@ui @api
@api @ui
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 @api
@ui @javascript @no-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

View file

@ -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 @api
@api @ui
Scenario: Browsing customers in store
When I want to see all customers in store
Then I should see 3 customers in the list

View file

@ -17,17 +17,17 @@ 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
@api @ui
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
Scenario: Browsing orders of a specific customer in the list
@api @ui
Scenario: Sorting orders of customer by channel
When I browse orders of a customer "logan@wolverine.com"
And I sort them by channel
And I sort the orders ascending by channel
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

View file

@ -9,7 +9,7 @@ Feature: Changing an email of an existing customer
And there is a customer "Frodo Baggins" with an email "f.baggins@example.com" and a password "ring"
And I am logged in as an administrator
@ui @api
@api @ui
Scenario: Changing an email of an existing customer
When I want to edit this customer
And I change their email to "strawberry@example.com"

View file

@ -14,14 +14,14 @@ Feature: Filtering customers by groups
And this customer belongs to group "Wholesale"
And I am logged in as an administrator
@ui @javascript @api
@api @ui @javascript
Scenario: Filtering customers by a group
When I want to see all customers in store
And I filter by group "Retail"
Then I should see a single customer on the list
And I should see the customer "g.bespoke@example.com" in the list
@ui @javascript @api
@api @ui @javascript
Scenario: Filtering customers by multiple groups
When I want to see all customers in store
And I filter by groups "Retail" and "Wholesale"

View file

@ -7,7 +7,7 @@ Feature: Customer uniqueness of email validation
Background:
Given I am logged in as an administrator
@ui @api
@api @ui
Scenario: Trying to add a new customer with taken email
Given the store has customer "f.baggins@example.com"
When I want to create a new customer

View file

@ -7,7 +7,7 @@ Feature: Customer validation
Background:
Given I am logged in as an administrator
@ui @api
@api @ui
Scenario: Trying to add a new customer without an email
When I want to create a new customer
And I specify their first name as "Luke"
@ -15,7 +15,7 @@ Feature: Customer validation
And I try to add them
Then I should be notified that email is required
@ui @api
@api @ui
Scenario: Trying to specify too short first name for an existing customer
Given the store has customer "l.skywalker@gmail.com"
When I want to edit this customer
@ -24,7 +24,7 @@ Feature: Customer validation
Then I should be notified that first name should be at least 2 characters long
And the customer "l.skywalker@gmail.com" should still have an empty first name
@ui @api
@api @ui
Scenario: Trying to specify too short last name for an existing customer
Given the store has customer "l.skywalker@gmail.com" with first name "Luke"
When I want to edit this customer
@ -33,7 +33,7 @@ Feature: Customer validation
Then I should be notified that last name should be at least 2 characters long
And the customer "l.skywalker@gmail.com" should still have an empty last name
@ui @api
@api @ui
Scenario: Trying to remove email from an existing customer
Given the store has customer "l.skywalker@gmail.com"
When I want to edit this customer
@ -42,7 +42,7 @@ Feature: Customer validation
Then I should be notified that email is required
And the customer "l.skywalker@gmail.com" should still have this email
@ui @api
@api @ui
Scenario: Trying to create customer with wrong email format
When I want to create a new customer
And I specify their email as "wrongemail"
@ -50,7 +50,7 @@ Feature: Customer validation
Then I should be notified that email is not valid
And the customer with email "wrongemail" should not appear in the store
@ui @api
@api @ui
Scenario: Trying to create customer with wrong email format in strict mode
When I want to create a new customer
And I specify their email as "wrongemail@example..com"

View file

@ -7,7 +7,7 @@ Feature: Editing a customer
Background:
Given I am logged in as an administrator
@ui @api
@api @ui
Scenario: Changing first and last name of an existing customer
Given the store has customer "Frodo Baggins" with email "f.baggins@example.com"
When I want to edit this customer
@ -17,7 +17,7 @@ Feature: Editing a customer
Then I should be notified that it has been successfully edited
And this customer with name "Jon Snow" should appear in the store
@ui @api
@api @ui
Scenario: Removing first and last name from an existing customer
Given the store has customer "Luke Skywalker" with email "l.skywalker@gmail.com"
When I want to edit this customer
@ -28,7 +28,7 @@ Feature: Editing a customer
And this customer should have an empty first name
And this customer should have an empty last name
@ui @api
@api @ui
Scenario: Making an existing customer subscribed to the newsletter
Given the store has customer "Mike Ross" with email "ross@teammike.com"
When I want to edit this customer
@ -37,7 +37,7 @@ Feature: Editing a customer
Then I should be notified that it has been successfully edited
And this customer should be subscribed to the newsletter
@ui @api
@api @ui
Scenario: Selecting a group for an existing customer
Given the store has a customer group "Retail"
And the store has customer "Mike Ross" with email "ross@teammike.com"

View file

@ -9,51 +9,44 @@ Feature: Seeing customer's details
And the store has a customer group Retail
And the store has customer "f.baggins@shire.me" with name "Frodo Baggins" and phone number "666777888" since "2011-01-10 21:00"
@ui @api
@api @ui
Scenario: Seeing customer's basic information
When I view details of the customer "f.baggins@shire.me"
Then his name should be "Frodo Baggins"
Then their name should be "Frodo Baggins"
And he should be registered since "2011-01-10 21:00:00"
And his email should be "f.baggins@shire.me"
And his phone number should be "666777888"
And their email should be "f.baggins@shire.me"
And their phone number should be "666777888"
@ui @no-api
@api @ui
Scenario: Seeing customer's default address
Given the store operates in "New Zealand"
And their default address is "Hobbiton", "Bag End", "1", "New Zealand" for "Frodo Baggins"
When I view details of the customer "f.baggins@shire.me"
Then his default address should be "Frodo Baggins, Bag End, Hobbiton, NEW ZEALAND 1"
Then their default address should be "Frodo" "Baggins", "Bag End", "1" "Hobbiton", "New Zealand"
@api @no-ui
Scenario: Seeing customer's default address
Given the store operates in "New Zealand"
And their default address is "Hobbiton", "Bag End", "1", "New Zealand" for "Frodo Baggins"
When I view details of the customer "f.baggins@shire.me"
Then his default address should be "Frodo" "Baggins", "Bag End", "1" "Hobbiton", "NZ"
@ui @api
@api @ui
Scenario: Seeing information about no existing account for a given customer
When I view details of the customer "f.baggins@shire.me"
Then I should see information about no existing account for this customer
@ui @api
@api @ui
Scenario: Seeing information about subscription to the newsletter
Given the customer subscribed to the newsletter
When I view details of the customer "f.baggins@shire.me"
Then I should see that this customer is subscribed to the newsletter
@ui @api
@api @ui
Scenario: Seeing information about customer groups
Given the customer belongs to group "Retail"
When I view details of the customer "f.baggins@shire.me"
Then this customer should have "Retail" as their group
@ui @api
@api @ui
Scenario: Not Seeing information about email verification for not registered customer
When I view details of the customer "f.baggins@shire.me"
Then I should not see information about email verification
@ui @api
@api @ui
Scenario: Seeing information about verified email for registered customer
Given there is a customer "Legolas Sindar" identified by an email "legolas@woodland.rm" and a password "takingTheHobbitsToIsengard"
And this customer verified their email

View file

@ -4,7 +4,7 @@ Feature: Seeing a province on customer's details
As an Administrator
I want to be able to see specific customer's page with provinces in the addresses
@ui @api
@api @ui
Scenario: Seeing customer's addresses
Given the store operates in "United Kingdom"
And the store has customer "f.baggins@shire.me" with name "Frodo Baggins" since "2011-01-10 21:00"

View file

@ -7,7 +7,7 @@ Feature: Toggling a customer account
Background:
Given I am logged in as an administrator
@ui @api
@api @ui
Scenario: Enabling a customer account
Given there is disabled customer account "f.baggins@example.com" with password "psw"
When I want to enable "f.baggins@example.com"
@ -16,7 +16,7 @@ Feature: Toggling a customer account
Then I should be notified that it has been successfully edited
And this customer should be enabled
@ui @api
@api @ui
Scenario: Disabling a customer account
Given there is enabled customer account "f.baggins@example.com" with password "psw"
When I want to disable "f.baggins@example.com"

View file

@ -7,7 +7,7 @@ Feature: Toggling a customer account
Background:
Given I am logged in as an administrator
@ui @api
@api @ui
Scenario: Verifying customer account
Given there is enabled customer account "f.baggins@example.com" with password "psw"
When I want to verify "f.baggins@example.com"

View file

@ -18,12 +18,15 @@ use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Context\Api\Resources;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Customer\Model\CustomerGroupInterface;
use Webmozart\Assert\Assert;
final class ManagingCustomersContext implements Context
{
public const SORT_TYPES = ['ascending' => 'asc', 'descending' => 'desc'];
public function __construct(
private ApiClientInterface $client,
private ResponseCheckerInterface $responseChecker,
@ -56,7 +59,9 @@ final class ManagingCustomersContext implements Context
*/
public function iBrowseOrdersOfACustomer(CustomerInterface $customer): void
{
$this->client->subResourceIndex(Resources::CUSTOMERS, 'orders', (string) $customer->getId());
$this->client->index(Resources::ORDERS);
$this->client->addFilter('customer.id', $customer->getId());
$this->client->filter();
}
/**
@ -169,7 +174,7 @@ final class ManagingCustomersContext implements Context
/**
* @When I want to see all customers in store
*/
public function iWantToSeeAllZonesInStore(): void
public function iWantToSeeAllCustomersInStore(): void
{
$this->client->index(Resources::CUSTOMERS);
}
@ -196,19 +201,21 @@ final class ManagingCustomersContext implements Context
}
/**
* @When I do not specify any information
* @When I sort the orders :sortType by channel
*/
public function iDoNotSpecifyAnyInformation(): void
public function iSortThemBy(string $sortType = 'ascending'): void
{
// Intentionally left empty
$this->client->sort([
'channel.code' => self::SORT_TYPES[$sortType],
]);
}
/**
* @When I do not specify any information
* @When I do not choose create account option
*/
public function iDoNotChooseCreateAccountOption()
public function intentionallyLeftEmpty(): void
{
// Intentionally left blank.
}
/**
@ -223,7 +230,7 @@ final class ManagingCustomersContext implements Context
}
/**
* @Then /^I should be notified that ([^"]+) is required$/
* @Then I should be notified that :element is required
*/
public function iShouldBeNotifiedThatIsRequired(string $element): void
{
@ -247,7 +254,7 @@ final class ManagingCustomersContext implements Context
/**
* @Then /^I should be notified that ([^"]+) should be ([^"]+)$/
*/
public function iShouldBeNotifiedThatTheElementShouldBe($elementName, $validationMessage): void
public function iShouldBeNotifiedThatTheElementShouldBe(string $elementName, string $validationMessage): void
{
Assert::contains(
$this->responseChecker->getError($this->client->getLastResponse()),
@ -319,9 +326,9 @@ final class ManagingCustomersContext implements Context
}
/**
* @Then his name should be :name
* @Then their name should be :name
*/
public function hisNameShouldBe(string $name): void
public function theirNameShouldBe(string $name): void
{
Assert::true($this->responseChecker->hasValue($this->client->getLastResponse(), 'fullName', $name));
}
@ -335,31 +342,31 @@ final class ManagingCustomersContext implements Context
}
/**
* @Then his email should be :email
* @Then their email should be :email
*/
public function hisEmailShouldBe(string $email): void
public function theirEmailShouldBe(string $email): void
{
Assert::true($this->responseChecker->hasValue($this->client->getLastResponse(), 'email', $email));
}
/**
* @Then his phone number should be :phoneNumber
* @Then their phone number should be :phoneNumber
*/
public function hisPhoneNumberShouldBe(string $phoneNumber): void
public function theirPhoneNumberShouldBe(string $phoneNumber): void
{
Assert::true($this->responseChecker->hasValue($this->client->getLastResponse(), 'phoneNumber', $phoneNumber));
}
/**
* @Then his default address should be :firstName :lastName, :street, :postcode :city, :countryCode
* @Then their default address should be :firstName :lastName, :street, :postcode :city, :country
*/
public function hisSDefaultAddressShouldBe(
public function theirSDefaultAddressShouldBe(
string $firstName,
string $lastName,
string $street,
string $postcode,
string $city,
string $countryCode,
CountryInterface $country,
): void {
$this->client->showByIri($this->responseChecker->getValue($this->client->getLastResponse(), 'defaultAddress'));
@ -368,7 +375,7 @@ final class ManagingCustomersContext implements Context
Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'street'), $street);
Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'postcode'), $postcode);
Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'city'), $city);
Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'countryCode'), $countryCode);
Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'countryCode'), $country->getCode());
}
/**
@ -401,7 +408,7 @@ final class ManagingCustomersContext implements Context
/**
* @Then I should see the order with number :orderNumber in the list
*/
public function iShouldSeeASingleOrderFromCustomer(string $orderNumber): void
public function iShouldSeeTheOrderWithNumberInTheList(string $orderNumber): void
{
Assert::true(
$this->responseChecker->hasItemWithValue(
@ -413,9 +420,9 @@ final class ManagingCustomersContext implements Context
}
/**
* @Then /^I should be notified that the password must be at least (\d+) characters long$/
* @Then I should be notified that the password must be at least :amountOfCharacters characters long
*/
public function iShouldBeNotifiedThatThePasswordMustBeAtLeastCharactersLong(string $amountOfCharacters): void
public function iShouldBeNotifiedThatThePasswordMustBeAtLeastCharactersLong(int $amountOfCharacters): void
{
Assert::contains(
$this->responseChecker->getError($this->client->getLastResponse()),
@ -518,7 +525,7 @@ final class ManagingCustomersContext implements Context
/**
* @Then /^(this customer) with name "([^"]*)" should appear in the store$/
*/
public function theCustomerWithNameShouldAppearInTheRegistry(CustomerInterface $customer, string $name): void
public function theCustomerWithNameShouldAppearInTheStore(CustomerInterface $customer, string $name): void
{
Assert::true(
$this->responseChecker->hasValue(
@ -556,35 +563,13 @@ final class ManagingCustomersContext implements Context
/**
* @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
public function intentionallyLeftBlank(): void
{
// Intentionally left empty
}
}

View file

@ -375,11 +375,11 @@ final class ManagingCustomersContext implements Context
}
/**
* @When I sort them by :sortBy
* @When I sort the orders :sortType by :field
*/
public function iSortThemByChannel(string $sortBy): void
public function iSortTheOrderByField(string $field): void
{
$this->ordersIndexPage->sort(ucfirst($sortBy));
$this->ordersIndexPage->sort(ucfirst($field));
}
/**
@ -404,9 +404,9 @@ final class ManagingCustomersContext implements Context
}
/**
* @Then his name should be :name
* @Then (his|their) name should be :name
*/
public function hisNameShouldBe($name)
public function hisNameShouldBe(string $name): void
{
Assert::same($this->showPage->getCustomerName(), $name);
}
@ -420,29 +420,46 @@ final class ManagingCustomersContext implements Context
}
/**
* @Then his email should be :email
* @Then (his|their) email should be :email
*/
public function hisEmailShouldBe($email)
public function hisEmailShouldBe(string $email): void
{
Assert::same($this->showPage->getCustomerEmail(), $email);
}
/**
* @Then his phone number should be :phoneNumber
* @Then (his|their) phone number should be :phoneNumber
*/
public function hisPhoneNumberShouldBe($phoneNumber)
public function hisPhoneNumberShouldBe(string $phoneNumber): void
{
Assert::same($this->showPage->getCustomerPhoneNumber(), $phoneNumber);
}
/**
* @Then his default address should be :defaultAddress
* @Then (his|their) default address should be :defaultAddress
*/
public function hisShippingAddressShouldBe($defaultAddress)
public function hisShippingAddressShouldBe(string $defaultAddress): void
{
Assert::same($this->showPage->getDefaultAddress(), str_replace(',', '', $defaultAddress));
}
/**
* @Then their default address should be :firstName :lastName, :street, :postcode :city, :country
*/
public function theirSDefaultAddressShouldBe(
string $firstName,
string $lastName,
string $street,
string $postcode,
string $city,
string $country,
): void {
Assert::same(
$this->showPage->getDefaultAddress(),
sprintf('%s %s %s %s %s %s', $firstName, $lastName, $street, $city, strtoupper($country), $postcode),
);
}
/**
* @Then I should see information about no existing account for this customer
*/

View file

@ -8,6 +8,7 @@ default:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.transform.address
- sylius.behat.context.transform.country
- sylius.behat.context.transform.customer
- sylius.behat.context.transform.customer_group
- sylius.behat.context.transform.payment