Skip to content

Commit

Permalink
Fix tests after add new SearchFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomanhez committed Mar 5, 2020
1 parent 70a53de commit f39f7ce
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Feature: Filtering exchange rates by a currency
When I browse exchange rates of the store
And I choose "Euro" as a currency filter
And I filter
Then I should see 2 filtered exchange rates on the list
Then I should see 2 exchange rates on the list
And I should see an exchange rate between "Euro" and "British Pound" on the list
And I should also see an exchange rate between "Polish Zloty" and "Euro" on the list
9 changes: 8 additions & 1 deletion src/Sylius/Behat/Client/ApiClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public function buildCreateRequest(string $resource): void;

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

public function buildFilter(
string $resource,
?string $fieldType = null,
?string $fieldValue = null,
?string $previewFilters = null
): string;

public function addRequestData(string $key, string $value): void;

public function addCompoundRequestData(array $data): void;
Expand All @@ -37,7 +44,7 @@ public function update(): void;

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

public function filter(string $resource, string $fieldType, string $fieldValue): void;
public function filter(string $filters): void;

public function countCollectionItems(): int;

Expand Down
23 changes: 16 additions & 7 deletions src/Sylius/Behat/Client/ApiPlatformClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ public function buildUpdateRequest(string $resource, string $id): void
$this->request['body'] = json_decode($this->client->getResponse()->getContent(), true);
}

public function buildFilter(
string $resource,
?string $fieldType = null,
?string $fieldValue = null,
?string $previewFilters = null
): string {
if ($previewFilters === null) {
return sprintf('/new-api/%s?%s=%s', $resource, $fieldType, $fieldValue);
}

return sprintf('%s&%s=%s', $previewFilters, $fieldType, $fieldValue);
}

public function addRequestData(string $key, string $value): void
{
$this->request['body'][$key] = $value;
Expand Down Expand Up @@ -94,15 +107,11 @@ public function delete(string $resource, string $id): void
$this->request('DELETE', sprintf('/new-api/%s/%s', $resource, $id), []);
}

public function filter(string $resource, string $fieldType, string $fieldValue): void
public function filter(string $filters): void
{
$this->client->request(
'GET', sprintf(
'/new-api/%s?%s=%s',
$resource,
$fieldType,
$fieldValue
),
'GET',
$filters,
[],
[],
['HTTP_ACCEPT' => 'application/ld+json']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,18 @@ public function iDeleteTheExchangeRateBetweenAnd(CurrencyInterface $sourceCurren
*/
public function iChooseCurrencyAsACurrencyFilter(CurrencyInterface $currency): void
{
$exchangeRates = [];
$this->client->filter('exchange_rates', 'sourceCurrency.code', $currency->getCode());
$exchangeRates = array_merge($exchangeRates, $this->client->getCollection());
$this->client->filter('exchange_rates', 'targetCurrency.code', $currency->getCode());
$exchangeRates = array_merge($exchangeRates, $this->client->getCollection());
$filters = $this->client->buildFilter('exchange_rates', 'sourceCurrency.code', $currency->getCode());
$filters = $this->client->buildFilter('exchange_rates', 'targetCurrency.code', $currency->getCode(), $filters);

$this->sharedStorage->set('filtered_exchange_rates', $exchangeRates);
$this->sharedStorage->set('filters', $filters);
}

/**
* @When I filter
*/
public function iFilter(): void
{
//Intentionally left blank to fulfill context expectation
}

/**
* @Then I should see :count filtered exchange rates on the list
*/
public function iShouldSeeFilteredExchangeRatesOnTheList(int $count = 0): void
{
Assert::same(count($this->sharedStorage->get('filtered_exchange_rates')), $count);
$this->client->filter($this->sharedStorage->get('filters'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public function iDeleteThem(): void

/**
* @Then I should see :count exchange rates on the list
* @Then I should see :count filtered exchange rates on the list
*/
public function iShouldSeeExchangeRatesOnTheList($count = 0)
{
Expand Down

0 comments on commit f39f7ce

Please sign in to comment.