Skip to content

Commit

Permalink
Fix test for ExchangeRate
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomanhez committed Mar 6, 2020
1 parent dc981b8 commit a9ed475
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Deleting multiple exchange rates
And the exchange rate of "Polish Zloty" to "Euro" is 0.22
And I am logged in as an administrator

@ui @api
@ui
Scenario: Deleting multiple exchange rates at once
When I browse exchange rates
And I check the exchange rate between "Euro" and "British Pound"
Expand Down
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 @api
@ui
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
92 changes: 24 additions & 68 deletions src/Sylius/Behat/Context/Api/Admin/ManagingExchangeRatesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function iWantToAddNewExchangeRate(): void
*/
public function iWantToEditThisExchangeRate(ExchangeRateInterface $exchangeRate): void
{
$this->sharedStorage->set('exchangeRateId', $exchangeRate->getId());
$this->sharedStorage->set('exchange_rate_id', $exchangeRate->getId());
}

/**
Expand All @@ -65,7 +65,7 @@ public function iAmEditingThisExchangeRate(ExchangeRateInterface $exchangeRate):
}

/**
* @Given I am browsing exchange rates of the store
* @When I am browsing exchange rates of the store
* @When I browse exchange rates
* @When I browse exchange rates of the store
*/
Expand All @@ -80,7 +80,7 @@ public function iBrowseExchangeRatesOfTheStore(): void
*/
public function iSpecifyItsRatioAs(?float $ratio = null): void
{
if($ratio !== null) {
if ($ratio !== null) {
$this->client->addRequestData('ratio', $ratio);
}
}
Expand All @@ -90,15 +90,15 @@ public function iSpecifyItsRatioAs(?float $ratio = null): void
*/
public function iChooseAsTheSourceCurrency(string $currencyCode): void
{
$this->client->addRequestData('sourceCurrency', '/new-api/currencies/'.$currencyCode);
$this->client->addRequestData('sourceCurrency', '/new-api/currencies/' . $currencyCode);
}

/**
* @When I choose :currencyCode as the target currency
*/
public function iChooseAsTheTargetCurrency(string $currencyCode): void
{
$this->client->addRequestData('targetCurrency', '/new-api/currencies/'.$currencyCode);
$this->client->addRequestData('targetCurrency', '/new-api/currencies/' . $currencyCode);
}

/**
Expand All @@ -114,7 +114,7 @@ public function iAddIt(): void
*/
public function iChangeRatioTo(string $ratio): void
{
$this->client->addRequestData('ratio', $ratio);
$this->client->updateRequestData(['ratio' => $ratio]);
}

/**
Expand All @@ -136,38 +136,6 @@ public function iDeleteTheExchangeRateBetweenAnd(CurrencyInterface $sourceCurren
$this->client->delete('exchange_rates', $exchangeRate->getId());
}

/**
* @When I choose :name as a currency filter
*/
public function iChooseCurrencyAsACurrencyFilter(string $name): void
{
$this->client->buildUpdateRequest('rating', $name);//TODO
}

/**
* @When I filter
*/
public function iFilter(): void
{
//TODO
}

/**
* @When I check (also) the exchange rate between :sourceCurrencyName and :targetCurrencyName
*/
public function iCheckTheExchangeRateBetweenAnd(string $sourceCurrencyName, string $targetCurrencyName): void
{
// Intentionally left blank to fulfill after handling bulk delete
}

/**
* @When I delete them
*/
public function iDeleteThem(): void
{
// Intentionally left blank to fulfill after handling bulk delete
}

/**
* @Then I should see :count exchange rates on the list
*/
Expand All @@ -180,10 +148,10 @@ public function iShouldSeeExchangeRatesOnTheList(int $count = 0): void
* @Then I should see a single exchange rate in the list
* @Then I should( still) see one exchange rate on the list
*/
public function iShouldSeeOneExchangeRateOnTheList(): void
public function iShouldSeeASingleExchangeRateInTheList(): void
{
$this->client->index('exchange_rates');
Assert::same(count($this->client->getCollection()), 1);
Assert::same($this->client->countCollectionItems(), 1);
}

/**
Expand Down Expand Up @@ -219,7 +187,7 @@ public function iShouldSeeTheExchangeRateBetweenAndInTheList(
/**
* @Then it should have a ratio of :ratio
*/
public function itShouldHaveRatioOf(float $ratio): void
public function itShouldHaveARatioOf(float $ratio): void
{
$this->client->index('exchange_rates');

Expand Down Expand Up @@ -279,33 +247,15 @@ public function thisExchangeRateShouldHaveARatioOf(ExchangeRateInterface $exchan
*/
public function iShouldNotBeAbleToEditItsSourceCurrency(): void
{
$this->client->buildUpdateRequest('exchange_rates', $this->sharedStorage->get('exchangeRateId'));

$this->client->addRequestData('sourceCurrency', '/new-api/currencies/EUR');
$this->client->update();

$this->client->index('exchange_rates');
Assert::false(
$this->client->hasItemOnPositionWithValue(0,'sourceCurrency', '/new-api/currencies/EUR'),
'The sourceCurrency field with value \'/new-api/currencies/EUR\' exists'
);
$this->assertIfNotBeAbleToEditItCurrency('sourceCurrency');
}

/**
* @Then I should not be able to edit its target currency
*/
public function iShouldNotBeAbleToEditItsTargetCurrency(): void
{
$this->client->buildUpdateRequest('exchange_rates', $this->sharedStorage->get('exchangeRateId'));

$this->client->addRequestData('targetCurrency', '/new-api/currencies/EUR');
$this->client->update();

$this->client->index('exchange_rates');
Assert::false(
$this->client->hasItemOnPositionWithValue(0, 'targetCurrency', '/new-api/currencies/EUR'),
'The targetCurrency field with value \'/new-api/currencies/EUR\' exists'
);
$this->assertIfNotBeAbleToEditItCurrency('targetCurrency');
}

/**
Expand Down Expand Up @@ -340,12 +290,18 @@ public function iShouldBeNotifiedThatTheCurrencyPairMustBeUnique(): void
Assert::contains($this->client->getError(), 'The currency pair must be unique.');
}

/**
* @Then I should be notified that they have been successfully deleted
*/
public function iShouldBeNotifiedThatTheyHaveBeenSuccessfullyDeleted(): void
private function assertIfNotBeAbleToEditItCurrency(string $currencyType): void
{
// Intentionally left blank to fulfill after handling bulk delete
$this->client->buildUpdateRequest('exchange_rates', $this->sharedStorage->get('exchange_rate_id'));

$this->client->addRequestData($currencyType, '/new-api/currencies/EUR');
$this->client->update();

$this->client->index('exchange_rates');
Assert::false(
$this->client->hasItemOnPositionWithValue(0, $currencyType, '/new-api/currencies/EUR'),
sprintf('The %s field with value \'/new-api/currencies/EUR\' exists', $currencyType)
);
}

private function getExchangeRateBetweenCurrencies(string $sourceCode, string $targetCode): ExchangeRateInterface
Expand All @@ -368,8 +324,8 @@ private function getExchangeRateFromResponse(
foreach ($this->client->getCollection() as $item)
{
if (
$item['sourceCurrency'] === '/new-api/currencies/'.$sourceCurrency->getCode() &&
$item['targetCurrency'] === '/new-api/currencies/'.$targetCurrency->getCode()
$item['sourceCurrency'] === '/new-api/currencies/' . $sourceCurrency->getCode() &&
$item['targetCurrency'] === '/new-api/currencies/' . $targetCurrency->getCode()
) {
return $item;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
</attribute>
</attribute>
<collectionOperations>
<collectionOperation name="get">
<attribute name="filters">
<attribute>exchange_rate.search_currency</attribute>
</attribute>
</collectionOperation>
<collectionOperation name="get" />
<collectionOperation name="post">
<attribute name="denormalization_context">
<attribute name="groups">exchange_rate:write</attribute>
Expand Down

0 comments on commit a9ed475

Please sign in to comment.