Skip to content

Commit

Permalink
feature #11178 [API] [Exchange Rate] Add api configuration and tests …
Browse files Browse the repository at this point in the history
…(Tomanhez)

This PR was merged into the api branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | api
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | no
| License         | MIT

<img width="1382" alt="Screenshot 2020-03-05 at 09 09 22" src="https://user-images.githubusercontent.com/39232096/75960906-42c30e80-5ec1-11ea-93b2-08961c47fc44.png">

<!--
 - Bug fixes must be submitted against the 1.6 branch (the lowest possible)
 - Features and deprecations must be submitted against the master branch
 - Make sure that the correct base branch is set
-->


Commits
-------

0915cbc Add tags fo api in ExchangeRates
9f4236b Add behat contexts for api ExchangeRates
0a58e51 Add behat configurations
533053d Add configuration for ExchangeRate
7d193e3 Fix test for ExchangeRate
  • Loading branch information
GSadee committed Mar 11, 2020
2 parents d78c837 + 7d193e3 commit 33e8487
Show file tree
Hide file tree
Showing 15 changed files with 471 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Adding a new exchange rate
Given the store has currency "US Dollar" and "British Pound"
And I am logged in as an administrator

@ui
@ui @api
Scenario: Adding a new exchange rate
Given I want to add a new exchange rate
When I specify its ratio as 1.20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Browsing exchange rates
And the exchange rate of "British Pound" to "Bhutanese Ngultrum" is 2.37
And I am logged in as an administrator

@ui
@ui @api
Scenario: Browsing store's exchange rates
When I am browsing exchange rates of the store
Then I should see 2 exchange rates on the list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Deleting exchange rates
Given the store has currency "US Dollar", "British Pound" and "Bhutanese Ngultrum"
And I am logged in as an administrator

@ui
@ui @api
Scenario: Deleted exchange rate should disappear from the list
Given the exchange rate of "US Dollar" to "British Pound" is 1.2
When I delete the exchange rate between "US Dollar" and "British Pound"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Editing exchange rate
Given the store has currency "US Dollar" and "British Pound"
And I am logged in as an administrator

@ui
@ui @api
Scenario: Change exchange rate's ratio
Given the exchange rate of "US Dollar" to "British Pound" is 1.30
And I am editing this exchange rate
Expand All @@ -17,9 +17,9 @@ Feature: Editing exchange rate
Then I should be notified that it has been successfully edited
And it should have a ratio of 3.21

@ui
@ui @api
Scenario: Being unable to change currencies
Given the exchange rate of "US Dollar" to "British Pound" is 1.30
When I want to edit this exchange rate
Then I should see that the source currency is disabled
And I should see that the target currency is disabled
Then I should not be able to edit its source currency
And I should not be able to edit its target currency
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Exchange rate validation
Given the store has currency "US Dollar" and "British Pound"
And I am logged in as an administrator

@ui
@ui @api
Scenario: Trying to add a new exchange rate without ratio
Given I want to add a new exchange rate
When I choose "US Dollar" as the source currency
Expand All @@ -18,7 +18,7 @@ Feature: Exchange rate validation
Then I should be notified that ratio is required
And the exchange rate between "US Dollar" and "British Pound" should not be added

@ui
@ui @api
Scenario: Trying to add a new exchange rate with negative ratio
Given I want to add a new exchange rate
When I choose "US Dollar" as the source currency
Expand All @@ -28,7 +28,7 @@ Feature: Exchange rate validation
Then I should be notified that the ratio must be greater than zero
And the exchange rate between "US Dollar" and "British Pound" should not be added

@ui
@ui @api
Scenario: Trying to add a new exchange rate with same target currency as source
Given I want to add a new exchange rate
When I specify its ratio as 1.23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Inability of adding exchange rates with the same currency pair
And the exchange rate of "Euro" to "British Pound" is 1.2
And I am logged in as an administrator

@ui
@ui @api
Scenario: Being prevented from adding an exchange rate for the same currency pair
Given I want to add a new exchange rate
When I specify its ratio as 3.20
Expand All @@ -20,7 +20,7 @@ Feature: Inability of adding exchange rates with the same currency pair
And I should still see one exchange rate on the list
And this exchange rate should have a ratio of 1.2

@ui
@ui @api
Scenario: Being prevented from adding an exchange rate for a reversed currency pair
Given I want to add a new exchange rate
When I specify its ratio as 3.20
Expand Down
5 changes: 3 additions & 2 deletions src/Sylius/Behat/Client/ApiClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function applyTransition(string $resource, string $id, string $transition

public function countCollectionItems(): int;

public function getCollection(): array;
public function getCollectionItems(): array;

public function getCollectionItemsWithValue(string $key, string $value): array;

Expand All @@ -64,7 +64,8 @@ public function responseHasValue(string $key, $value): bool;
/** @param string|int $value */
public function relatedResourceHasValue(string $resource, string $key, $value): bool;

public function hasItemWithValue(string $key, string $value): bool;
/** @param string|float $value */
public function hasItemWithValue(string $key, $value): bool;

public function hasItemOnPositionWithValue(int $position, string $key, string $value): bool;

Expand Down
15 changes: 8 additions & 7 deletions src/Sylius/Behat/Client/ApiPlatformClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function subResourceIndex(string $resource, string $subResource, string $

public function buildCreateRequest(string $resource): void
{
$this->request['url'] = '/new-api/'.$resource;
$this->request['url'] = '/new-api/' . $resource;
}

public function buildUpdateRequest(string $resource, string $id): void
Expand Down Expand Up @@ -123,14 +123,14 @@ public function countCollectionItems(): int
return (int) $this->getResponseContentValue('hydra:totalItems');
}

public function getCollection(): array
public function getCollectionItems(): array
{
return $this->getResponseContentValue('hydra:member');
}

public function getCollectionItemsWithValue(string $key, string $value): array
{
$items = array_filter($this->getCollection(), function (array $item) use ($key, $value): bool {
$items = array_filter($this->getCollectionItems(), function (array $item) use ($key, $value): bool {
return $item[$key] === $value;
});

Expand Down Expand Up @@ -171,9 +171,10 @@ public function relatedResourceHasValue(string $resource, string $key, $value):
return $this->getResponseContentValue($key) === $value;
}

public function hasItemWithValue(string $key, string $value): bool
/** @param string|float $value */
public function hasItemWithValue(string $key, $value): bool
{
foreach ($this->getCollection() as $resource) {
foreach ($this->getCollectionItems() as $resource) {
if ($resource[$key] === $value) {
return true;
}
Expand All @@ -184,12 +185,12 @@ public function hasItemWithValue(string $key, string $value): bool

public function hasItemOnPositionWithValue(int $position, string $key, string $value): bool
{
return $this->getCollection()[$position][$key] === $value;
return $this->getCollectionItems()[$position][$key] === $value;
}

public function hasItemWithTranslation(string $locale, string $key, string $translation): bool
{
foreach ($this->getCollection() as $resource) {
foreach ($this->getCollectionItems() as $resource) {
if (
isset($resource['translations']) &&
isset($resource['translations'][$locale]) &&
Expand Down
Loading

0 comments on commit 33e8487

Please sign in to comment.