Skip to content

Commit

Permalink
[API][Tax rate] Implement deleting_multiple_tax_rates feature
Browse files Browse the repository at this point in the history
  • Loading branch information
hatem20 authored and jakubtobiasz committed Feb 15, 2023
1 parent c8fe3b3 commit e147639
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Deleting multiple tax rates
And the store has "High VAT" tax rate of 40% for "Food" for the rest of the world
And I am logged in as an administrator

@ui @javascript
@ui @javascript @api
Scenario: Deleting multiple tax rates at once
When I browse tax rates
And I check the "Low VAT" tax rate
Expand Down
61 changes: 59 additions & 2 deletions src/Sylius/Behat/Context/Api/Admin/ManagingTaxRateContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

use ApiPlatform\Core\Api\IriConverterInterface;
use Behat\Behat\Context\Context;
use Behat\Behat\Tester\Exception\PendingException;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Core\Model\TaxRateInterface;
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
Expand All @@ -34,14 +34,19 @@ class ManagingTaxRateContext implements Context
/** @var IriConverterInterface */
private $iriConverter;

/** @var SharedStorageInterface */
private $sharedStorage;

public function __construct(
ApiClientInterface $client,
ResponseCheckerInterface $responseChecker,
IriConverterInterface $iriConverter
IriConverterInterface $iriConverter,
SharedStorageInterface $sharedStorage
) {
$this->client = $client;
$this->responseChecker = $responseChecker;
$this->iriConverter = $iriConverter;
$this->sharedStorage = $sharedStorage;
}

/**
Expand Down Expand Up @@ -121,6 +126,7 @@ public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void

/**
* @Then the tax rate :taxRate should appear in the registry
* @Then I should see the tax rate :taxRate in the list
*/
public function theTaxRateShouldAppearInTheRegistry(TaxRateInterface $taxRate): void
{
Expand Down Expand Up @@ -182,4 +188,55 @@ public function thisTaxRateShouldNoLongerExistInTheRegistry(TaxRateInterface $ta
sprintf('Tax rate with name %s exists', $name)
);
}

/**
* @When I browse tax rates
*/
public function iBrowseTaxRates(): void
{
$this->client->index();
}

/**
* @When I check the :taxRate tax rate
* @When I check also the :taxRate tax rate
*/
public function iCheckTheTaxRate(TaxRateInterface $taxRate): void
{
$taxRateToDelete = [];
if ($this->sharedStorage->has('tax_rate_to_delete')) {
$taxRateToDelete = $this->sharedStorage->get('tax_rate_to_delete');
}
$taxRateToDelete[] = $taxRate->getId();
$this->sharedStorage->set('tax_rate_to_delete', $taxRateToDelete);
}

/**
* @When I delete them
*/
public function iDeleteThem(): void
{
foreach ($this->sharedStorage->get('tax_rate_to_delete') as $id) {
$this->client->delete((string) $id)->getContent();
}
}

/**
* @Then I should be notified that they have been successfully deleted
*/
public function iShouldBeNotifiedThatTheyHaveBeenSuccessfullyDeleted(): void
{
Assert::true(
$this->responseChecker->isDeletionSuccessful($this->client->getLastResponse()),
'Tax rate could not be deleted'
);
}

/**
* @Then I should see a single tax rate in the list
*/
public function iShouldSeeASingleTaxRateInTheList(): void
{
Assert::same($this->responseChecker->countCollectionItems($this->client->index()), 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
<argument type="service" id="sylius.behat.api_platform_client.admin.tax_rate" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>

<service id="sylius.behat.context.api.admin.resetting_password" class="Sylius\Behat\Context\Api\Admin\ResettingPasswordContext">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ default:
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.admin_api_security
- sylius.behat.context.setup.taxation
- sylius.behat.context.setup.zone

- sylius.behat.context.api.admin.managing_tax_rates

Expand Down

0 comments on commit e147639

Please sign in to comment.