Skip to content

Commit

Permalink
[API][Tax rate] Implement editing_tax_rate 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 161d25d commit 7cdf3e7
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
10 changes: 5 additions & 5 deletions features/taxation/managing_tax_rates/editing_tax_rate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ Feature: Editing tax rate
Then I should be notified that code cannot be changed
And tax rate "United States Sales Tax" should still have code "united_states_sales_tax"

@ui
@ui @api
Scenario: Seeing disabled code field when editing tax rate
When I want to modify a tax rate "United States Sales Tax"
Then the code field should be disabled

@ui
@ui @api
Scenario: Renaming the tax rate
When I want to modify a tax rate "United States Sales Tax"
And I rename it to "US VAT"
And I save my changes
Then I should be notified that it has been successfully edited
And this tax rate name should be "US VAT"

@ui
@ui @api
Scenario: Changing the tax rate amount
When I want to modify a tax rate "United States Sales Tax"
And I specify its amount as 16%
And I save my changes
Then I should be notified that it has been successfully edited
And this tax rate amount should be 16%

@ui
@ui @api
Scenario: Changing related tax category
Given the store has a tax category "Food and Beverage" also
When I want to modify a tax rate "United States Sales Tax"
Expand All @@ -48,7 +48,7 @@ Feature: Editing tax rate
Then I should be notified that it has been successfully edited
And this tax rate should be applicable for the "Food and Beverage" tax category

@ui
@ui @api
Scenario: Changing related zone
Given there is a zone "The Rest of the World" containing all other countries
When I want to modify a tax rate "United States Sales Tax"
Expand Down
67 changes: 65 additions & 2 deletions src/Sylius/Behat/Context/Api/Admin/ManagingTaxRateContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function iSpecifyItsCodeAs(?string $code = null): void
/**
* @When I name it :name
* @When I do not name it
* @When I rename it to :name
*/
public function iNameIt(?string $name = null): void
{
Expand All @@ -82,6 +83,7 @@ public function iNameIt(?string $name = null): void
/**
* @When I define it for the :zone zone
* @When I do not specify its zone
* @When I change its zone to :zone
*/
public function iDefineItForTheZone(?ZoneInterface $zone = null): void
{
Expand All @@ -92,6 +94,7 @@ public function iDefineItForTheZone(?ZoneInterface $zone = null): void

/**
* @When I make it applicable for the :taxCategory tax category
* @When I change it to be applicable for the :taxCategory tax category
* @When I do not specify related tax category
*/
public function iMakeItApplicableForTheTaxCategory(?TaxCategoryInterface $taxCategory = null): void
Expand Down Expand Up @@ -332,10 +335,14 @@ public function iShouldBeNotifiedThatCategoryHasToBeSelected(): void

/**
* @When /^I want to modify (this tax rate)$/
* @When I want to modify a tax rate :taxRate
*/
public function iWantToModifyThisTaxRate(TaxRateInterface $taxRate): void
{
$this->client->buildUpdateRequest((string) $taxRate->getId());

/* cast amount to string */
$this->client->addRequestData('amount', (string) $taxRate->getAmount());
}

/**
Expand All @@ -347,6 +354,7 @@ public function iRemoveItsAmount(): void
}

/**
* @When I save my changes
* @When I try to save my changes
*/
public function iSaveMyChanges(): void
Expand All @@ -357,7 +365,7 @@ public function iSaveMyChanges(): void
/**
* @Then /^(this tax rate) amount should still be ([^"]+)%$/
*/
public function thisTaxRateAmountShouldStillBe(TaxRateInterface $taxRate, $taxRateAmount): void
public function thisTaxRateAmountShouldStillBe(TaxRateInterface $taxRate, string $taxRateAmount): void
{
Assert::true($taxRate->getAmount(), $taxRateAmount);
}
Expand All @@ -372,12 +380,67 @@ public function iRemoveItsName(): void

/**
* @Then /^(this tax rate) should still be named "([^"]+)"$/
* @Then /^(this tax rate) name should be "([^"]*)"$/
*/
public function thisTaxRateShouldStillBeNamed(TaxRateInterface $taxRate, string $taxRateName): void
{
Assert::true(
$this->responseChecker->hasValue($this->client->show((string) $taxRate->getId()), 'name', $taxRateName),
sprintf('Tax category rate is not %s', $taxRateName)
sprintf('Tax rate name is not %s', $taxRateName)
);
}

/**
* @Then the code field should be disabled
*/
public function theCodeFieldShouldBeDisabled()
{
$this->client->updateRequestData(['code' => 'NEW_CODE']);

Assert::false($this->responseChecker->hasValue($this->client->update(), 'code', 'NEW_CODE'));
}

/**
* @Then I should be notified that it has been successfully edited
*/
public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void
{
Assert::true(
$this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()),
'Tax rate could not be edited'
);
}

/**
* @Then /^(this tax rate) amount should be ([^"]+)%$/
*/
public function thisTaxRateAmountShouldBe(TaxRateInterface $taxRate, int $taxRateAmount): void
{
Assert::true(
$this->responseChecker->hasValue($this->client->show((string) $taxRate->getId()), 'amount', $taxRateAmount),
sprintf('Tax rate amount is not %s', $taxRateAmount)
);
}

/**
* @Then /^(this tax rate) should be applicable for the ("[^"]+" tax category)$/
*/
public function thisTaxRateShouldBeApplicableForTheTaxCategory(TaxRateInterface $taxRate, TaxCategoryInterface $taxCategory): void
{
Assert::true(
$this->responseChecker->hasValue($this->client->show((string) $taxRate->getId()), 'category', $this->iriConverter->getIriFromItem($taxCategory)),
sprintf('Tax rate is not applicable for %s tax category', $taxCategory)
);
}

/**
* @Then /^(this tax rate) should be applicable in ("[^"]+" zone)$/
*/
public function thisTaxRateShouldBeApplicableInZone(TaxRateInterface $taxRate, ZoneInterface $zone): void
{
Assert::true(
$this->responseChecker->hasValue($this->client->show((string) $taxRate->getId()), 'zone', $this->iriConverter->getIriFromItem($zone)),
sprintf('Tax rate is not applicable for %s zone', $zone)
);
}
}

0 comments on commit 7cdf3e7

Please sign in to comment.