Skip to content

Commit

Permalink
Add test for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomanhez committed Mar 11, 2020
1 parent 291852a commit c60cf88
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Filtering exchange rates by a currency
And the exchange rate of "Polish Zloty" to "Euro" is 0.22
And I am logged in as an administrator

@ui
@ui @api
Scenario: Filtering exchange rates by a chosen currency
When I browse exchange rates of the store
And I choose "Euro" as a currency filter
Expand Down
6 changes: 5 additions & 1 deletion src/Sylius/Behat/Client/ApiClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function buildCreateRequest(string $resource): void;

public function buildUpdateRequest(string $resource, string $id): void;

/** @param string|int $value */
public function buildFilter(array $filters): void;

/** @param string|int */
public function addRequestData(string $key, $value): void;

public function addCompoundRequestData(array $data): void;
Expand All @@ -42,6 +44,8 @@ public function update(): void;

public function delete(string $resource, string $id): void;

public function filter(string $resource): void;

public function applyTransition(string $resource, string $id, string $transition): void;

public function countCollectionItems(): int;
Expand Down
18 changes: 17 additions & 1 deletion src/Sylius/Behat/Client/ApiPlatformClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ final class ApiPlatformClient implements ApiClientInterface
/** @var array */
private $request = ['url' => null, 'body' => []];

/** @var array */
private $filters;

public function __construct(AbstractBrowser $client, SharedStorageInterface $sharedStorage)
{
$this->client = $client;
Expand Down Expand Up @@ -73,7 +76,12 @@ public function buildUpdateRequest(string $resource, string $id): void
$this->request['body'] = json_decode($this->client->getResponse()->getContent(), true);
}

/** @param string|int $value */
public function buildFilter(array $filters): void
{
$this->filters = $filters;
}

/** @param string|int */
public function addRequestData(string $key, $value): void
{
$this->request['body'][$key] = $value;
Expand Down Expand Up @@ -108,6 +116,14 @@ public function delete(string $resource, string $id): void
$this->request('DELETE', sprintf('/new-api/%s/%s', $resource, $id), []);
}

public function filter(string $resource): void
{
$query = http_build_query($this->filters, '', '&', PHP_QUERY_RFC3986);
$path = sprintf('/new-api/%s?%s', $resource, $query);

$this->request('GET', $path, ['HTTP_ACCEPT' => 'application/ld+json']);
}

public function applyTransition(string $resource, string $id, string $transition): void
{
$this->request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ public function iDeleteTheExchangeRateBetweenAnd(CurrencyInterface $sourceCurren
$this->client->delete('exchange_rates', $exchangeRate->getId());
}

/**
* @When I choose :currency as a currency filter
*/
public function iChooseCurrencyAsACurrencyFilter(CurrencyInterface $currency): void
{
$this->client->buildFilter(['currencyCode' => $currency->getCode()]);
}

/**
* @When I filter
*/
public function iFilter(): void
{
$this->client->filter('exchange_rates');
}

/**
* @Then I should see :count exchange rates on the list
*/
Expand Down

0 comments on commit c60cf88

Please sign in to comment.