Skip to content

Commit

Permalink
Adjust Tax Rates API related Behat scenarios to the new standard
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz committed Feb 15, 2023
1 parent 7cdf3e7 commit 57f94db
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ Feature: Filtering tax rates by end date
As an Administrator
I want to be able to filter tax rates on the list

Background:
Background:
Given the store operates on a single channel in "United States"
And the store has "2022 tax rate" tax rate of 50% for "Clothes" within the "US" zone with dates between "2022-01-01" and "2022-12-31"
And the store has "2023 tax rate" tax rate of 15% for "Clothes" within the "US" zone with dates between "2023-01-01" and "2023-12-31"
And the store has "3 weeks tax rate" tax rate of 25% for "Clothes" within the "US" zone with dates between "2022-12-24" and "2023-01-15"
And I am logged in as an administrator

@ui @api
@ui @no-api
Scenario: Filtering tax rates from end date
When I browse tax rates
And I filter tax rates by end date from "2022-12-26"
Then I should see the tax rate "2023 tax rate" in the list
And I should see the tax rate "2022 tax rate" in the list
And I should see the tax rate "3 weeks tax rate" in the list

@ui @api
Scenario: Filtering catalog promotions up to end date
@ui @no-api
Scenario: Filtering tax rates up to end date
When I browse tax rates
And I filter tax rates by end date up to "2022-12-31"
Then I should not see a tax rate with name "2023 tax rate"
And I should not see a tax rate with name "3 weeks tax rate"
But I should see the tax rate "2022 tax rate" in the list

@ui @api
Scenario: Filtering catalog promotions in a end date range
@ui @no-api
Scenario: Filtering tax rates in a end date range
When I browse tax rates
And I filter tax rates by end date from "2023-01-02" up to "2023-01-31"
Then I should not see a tax rate with name "2023 tax rate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ Feature: Filtering tax rates by start date
And the store has "3 weeks tax rate" tax rate of 25% for "Clothes" within the "US" zone with dates between "2022-12-24" and "2023-01-15"
And I am logged in as an administrator

@ui @api
@ui @no-api
Scenario: Filtering tax rates from start date
When I browse tax rates
And I filter tax rates by start date from "2022-12-26"
Then I should not see a tax rate with name "2022 tax rate"
And I should not see a tax rate with name "3 weeks tax rate"
But I should see the tax rate "2023 tax rate" in the list

@ui @api
@ui @no-api
Scenario: Filtering catalog promotions up to start date
When I browse tax rates
And I filter tax rates by start date up to "2022-12-22"
Then I should not see a tax rate with name "2023 tax rate"
And I should not see a tax rate with name "3 weeks tax rate"
But I should see the tax rate "2022 tax rate" in the list

@ui @api
@ui @no-api
Scenario: Filtering catalog promotions in a start date range
When I browse tax rates
And I filter tax rates by start date from "2022-08-20" up to "2022-12-26"
Expand Down
80 changes: 45 additions & 35 deletions src/Sylius/Behat/Context/Api/Admin/ManagingTaxRateContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Context\Api\Resources;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Core\Model\TaxRateInterface;
Expand All @@ -25,36 +26,20 @@

class ManagingTaxRateContext implements Context
{
/** @var ApiClientInterface */
private $client;

/** @var ResponseCheckerInterface */
private $responseChecker;

/** @var IriConverterInterface */
private $iriConverter;

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

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

/**
* @Given I want to create a new tax rate
* @When I want to create a new tax rate
*/
public function iWantToCreateANewTaxRate(): void
{
$this->client->buildCreateRequest();
$this->client->buildCreateRequest(Resources::TAX_RATES);
}

/**
Expand Down Expand Up @@ -123,6 +108,31 @@ public function iChooseTheDefaultTaxCalculator(): void
$this->client->addRequestData('calculator', 'default');
}

/**
* @When I make it start at :startDate and end at :endDate
*/
public function iMakeItStartAtAndEndAt(string $startDate, string $endDate): void
{
$this->client->addRequestData('startDate', $startDate);
$this->client->addRequestData('endDate', $endDate);
}

/**
* @When I set the start date to :startDate
*/
public function iSetTheStartDateTo(string $startDate): void
{
$this->client->addRequestData('startDate', $startDate);
}

/**
* @When I set the end date to :endDate
*/
public function iSetTheEndDateTo(string $endDate): void
{
$this->client->addRequestData('endDate', $endDate);
}

/**
* @When I add it
* @When I try to add it
Expand Down Expand Up @@ -152,7 +162,7 @@ public function theTaxRateShouldAppearInTheRegistry(TaxRateInterface $taxRate):
$name = $taxRate->getName();

Assert::true(
$this->responseChecker->hasItemWithValue($this->client->index(), 'name', $name),
$this->responseChecker->hasItemWithValue($this->client->index(Resources::TAX_RATES), 'name', $name),
sprintf('Tax rate with name %s does not exists', $name)
);
}
Expand Down Expand Up @@ -181,7 +191,7 @@ public function theTaxRateShouldIncludePrice(TaxRateInterface $taxRate): void
*/
public function iDeleteTaxRate(TaxRateInterface $taxRate): void
{
$this->client->delete((string) $taxRate->getId());
$this->client->delete(Resources::TAX_RATES, (string) $taxRate->getId());
}

/**
Expand All @@ -203,7 +213,7 @@ public function thisTaxRateShouldNoLongerExistInTheRegistry(TaxRateInterface $ta
$name = $taxRate->getName();

Assert::false(
$this->responseChecker->hasItemWithValue($this->client->index(), 'name', $name),
$this->responseChecker->hasItemWithValue($this->client->index(Resources::TAX_RATES), 'name', $name),
sprintf('Tax rate with name %s exists', $name)
);
}
Expand All @@ -213,7 +223,7 @@ public function thisTaxRateShouldNoLongerExistInTheRegistry(TaxRateInterface $ta
*/
public function iBrowseTaxRates(): void
{
$this->client->index();
$this->client->index(Resources::TAX_RATES);
}

/**
Expand All @@ -236,7 +246,7 @@ public function iCheckTheTaxRate(TaxRateInterface $taxRate): void
public function iDeleteThem(): void
{
foreach ($this->sharedStorage->get('tax_rate_to_delete') as $id) {
$this->client->delete((string) $id)->getContent();
$this->client->delete(Resources::TAX_RATES, (string) $id)->getContent();
}
}

Expand All @@ -256,7 +266,7 @@ public function iShouldBeNotifiedThatTheyHaveBeenSuccessfullyDeleted(): void
*/
public function iShouldSeeASingleTaxRateInTheList(): void
{
Assert::same($this->responseChecker->countCollectionItems($this->client->index()), 1);
Assert::same($this->responseChecker->countCollectionItems($this->client->index(Resources::TAX_RATES)), 1);
}

/**
Expand All @@ -281,7 +291,7 @@ public function iShouldBeNotifiedThatTaxRateWithThisCodeAlreadyExists(): void
public function thereShouldStillBeOnlyOneTaxRateWithCode(string $code): void
{
Assert::count(
$this->responseChecker->getCollectionItemsWithValue($this->client->index(), 'code', $code),
$this->responseChecker->getCollectionItemsWithValue($this->client->index(Resources::TAX_RATES), 'code', $code),
1,
sprintf('There is more than one tax rate with code %s', $code)
);
Expand All @@ -308,7 +318,7 @@ public function taxRateWithCodeShouldNotBeAdded(string $element, string $code):

private function isItemOnIndex(string $property, string $value): bool
{
return $this->responseChecker->hasItemWithValue($this->client->index(), $property, $value);
return $this->responseChecker->hasItemWithValue($this->client->index(Resources::TAX_RATES), $property, $value);
}

/**
Expand Down Expand Up @@ -339,7 +349,7 @@ public function iShouldBeNotifiedThatCategoryHasToBeSelected(): void
*/
public function iWantToModifyThisTaxRate(TaxRateInterface $taxRate): void
{
$this->client->buildUpdateRequest((string) $taxRate->getId());
$this->client->buildUpdateRequest(Resources::TAX_RATES, (string) $taxRate->getId());

/* cast amount to string */
$this->client->addRequestData('amount', (string) $taxRate->getAmount());
Expand Down Expand Up @@ -385,7 +395,7 @@ public function iRemoveItsName(): void
public function thisTaxRateShouldStillBeNamed(TaxRateInterface $taxRate, string $taxRateName): void
{
Assert::true(
$this->responseChecker->hasValue($this->client->show((string) $taxRate->getId()), 'name', $taxRateName),
$this->responseChecker->hasValue($this->client->show(Resources::TAX_RATES, (string) $taxRate->getId()), 'name', $taxRateName),
sprintf('Tax rate name is not %s', $taxRateName)
);
}
Expand Down Expand Up @@ -417,7 +427,7 @@ public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void
public function thisTaxRateAmountShouldBe(TaxRateInterface $taxRate, int $taxRateAmount): void
{
Assert::true(
$this->responseChecker->hasValue($this->client->show((string) $taxRate->getId()), 'amount', $taxRateAmount),
$this->responseChecker->hasValue($this->client->show(Resources::TAX_RATES, (string) $taxRate->getId()), 'amount', $taxRateAmount),
sprintf('Tax rate amount is not %s', $taxRateAmount)
);
}
Expand All @@ -428,7 +438,7 @@ public function thisTaxRateAmountShouldBe(TaxRateInterface $taxRate, int $taxRat
public function thisTaxRateShouldBeApplicableForTheTaxCategory(TaxRateInterface $taxRate, TaxCategoryInterface $taxCategory): void
{
Assert::true(
$this->responseChecker->hasValue($this->client->show((string) $taxRate->getId()), 'category', $this->iriConverter->getIriFromItem($taxCategory)),
$this->responseChecker->hasValue($this->client->show(Resources::TAX_RATES, (string) $taxRate->getId()), 'category', $this->iriConverter->getIriFromItem($taxCategory)),
sprintf('Tax rate is not applicable for %s tax category', $taxCategory)
);
}
Expand All @@ -439,7 +449,7 @@ public function thisTaxRateShouldBeApplicableForTheTaxCategory(TaxRateInterface
public function thisTaxRateShouldBeApplicableInZone(TaxRateInterface $taxRate, ZoneInterface $zone): void
{
Assert::true(
$this->responseChecker->hasValue($this->client->show((string) $taxRate->getId()), 'zone', $this->iriConverter->getIriFromItem($zone)),
$this->responseChecker->hasValue($this->client->show(Resources::TAX_RATES, (string) $taxRate->getId()), 'zone', $this->iriConverter->getIriFromItem($zone)),
sprintf('Tax rate is not applicable for %s zone', $zone)
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Behat/Context/Api/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ final class Resources

public const TAX_CATEGORIES = 'tax-categories';

PUBLIC CONST TAX_RATES = 'tax-rates';

public const ZONES = 'zones';

private function __construct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Behat\Context\Ui\Admin;

use Behat\Behat\Context\Context;
use Sylius\Behat\Element\Admin\TaxRate\FilterElementInterface;
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Sylius\Behat\Page\Admin\TaxRate\CreatePageInterface;
use Sylius\Behat\Page\Admin\TaxRate\UpdatePageInterface;
Expand Down
5 changes: 0 additions & 5 deletions src/Sylius/Behat/Resources/config/services/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,5 @@
<argument type="service" id="sylius.behat.content_type_guide"/>
<argument>%sylius.security.new_api_route%</argument>
</service>

<service id="sylius.behat.api_platform_client.admin.tax_rate" class="Sylius\Behat\Client\ApiPlatformClient" parent="sylius.behat.api_platform_client">
<argument>tax-rates</argument>
<argument>admin</argument>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
</service>

<service id="sylius.behat.context.api.admin.managing_tax_rates" class="Sylius\Behat\Context\Api\Admin\ManagingTaxRateContext">
<argument type="service" id="sylius.behat.api_platform_client.admin.tax_rate" />
<argument type="service" id="sylius.behat.api_platform_client.admin" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="sylius.behat.shared_storage" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ default:
- sylius.behat.context.api.admin.managing_tax_rates

filters:
tags: "@managing_tax_rates && @api"
javascript: false
tags: "@managing_tax_rates&&@api"
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,15 @@
<group>tax_rate:create</group>
<group>tax_rate:update</group>
</attribute>
<attribute name="startDate">
<group>tax_rate:read</group>
<group>tax_rate:create</group>
<group>tax_rate:update</group>
</attribute>
<attribute name="endDate">
<group>tax_rate:read</group>
<group>tax_rate:create</group>
<group>tax_rate:update</group>
</attribute>
</class>
</serializer>

0 comments on commit 57f94db

Please sign in to comment.