[Behat] Add API test coverage for features/promotion/tracking_usage folder

This commit is contained in:
Wojdylak 2023-12-13 14:32:18 +01:00
parent 59c2798883
commit 4036f1f132
No known key found for this signature in database
GPG key ID: 7509E560A6821ABE
8 changed files with 48 additions and 9 deletions

View file

@ -16,7 +16,7 @@ Feature: Checking a promotion usage after placing an order
And there is a promotion "Christmas promotion"
And I am logged in as an administrator
@ui
@api @ui
Scenario: Seeing item fixed discount promotion usage unchanged after order placement
Given the promotion gives "$10.00" off on every product with minimum price at "$50.00"
And the promotion gives another "$5.00" off on every product classified as "T-Shirts"
@ -26,7 +26,7 @@ Feature: Checking a promotion usage after placing an order
When I browse promotions
Then the promotion "Christmas promotion" should not be used
@ui
@api @ui
Scenario: Seeing item fixed discount promotion usage increased after order placement
Given the promotion gives "$10.00" off on every product with minimum price at "$50.00"
And the promotion gives another "$5.00" off on every product classified as "Mugs"
@ -36,7 +36,7 @@ Feature: Checking a promotion usage after placing an order
When I browse promotions
Then the promotion "Christmas promotion" should be used 1 time
@ui
@api @ui
Scenario: Seeing shipping percentage discount promotion usage unchanged after order placement
Given the promotion gives "100%" discount on shipping to every order
And there is a customer "john.doe@gmail.com" that placed an order "#00000022"

View file

@ -12,7 +12,7 @@ Feature: Decreasing a promotion coupon usage after cancelling an order
And the store has promotion "Christmas sale" with coupon "SANTA2016"
And I am logged in as an administrator
@ui
@api @ui
Scenario: Seeing promotion coupon usage decreased after order cancellation
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022"
And the customer bought a single "PHP T-Shirt" using "SANTA2016" coupon
@ -21,7 +21,7 @@ Feature: Decreasing a promotion coupon usage after cancelling an order
When I browse all coupons of "Christmas sale" promotion
Then "SANTA2016" coupon should be used 0 times
@ui
@api @ui
Scenario: Seeing promotion coupon usage decreased to 1 after second order cancellation
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022"
And the customer bought a single "PHP T-Shirt" using "SANTA2016" coupon

View file

@ -12,7 +12,7 @@ Feature: Decreasing a promotion usage after cancelling an order
And there is a promotion "Limited promotion" limited to 5 usages
And I am logged in as an administrator
@ui
@api @ui
Scenario: Seeing promotion usage decreased after order cancellation
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022"
And the customer bought a single "PHP T-Shirt"

View file

@ -12,7 +12,7 @@ Feature: Increasing a promotion coupon usage after placing an order
And the store has promotion "Christmas sale" with coupon "SANTA2016"
And I am logged in as an administrator
@ui
@api @ui
Scenario: Seeing promotion coupon usage increased after order placement
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022"
And the customer bought a single "PHP T-Shirt" using "SANTA2016" coupon
@ -20,7 +20,7 @@ Feature: Increasing a promotion coupon usage after placing an order
When I browse all coupons of "Christmas sale" promotion
Then "SANTA2016" coupon should be used 1 time
@ui
@api @ui
Scenario: Seeing promotion coupon usage increased correctly after few orders placement
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022"
And the customer bought a single "PHP T-Shirt" using "SANTA2016" coupon

View file

@ -13,7 +13,7 @@ Feature: Increasing a promotion usage after placing an order
And it gives "$10.00" discount to every order
And I am logged in as an administrator
@ui
@api @ui
Scenario: Seeing promotion usage increased after order placement
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022"
And the customer bought a single "PHP T-Shirt"

View file

@ -40,6 +40,7 @@ final class ManagingPromotionCouponsContext implements Context
/**
* @Given /^I am browsing coupons of (this promotion)$/
* @When /^I want to view all coupons of (this promotion)$/
* @When /^I browse all coupons of ("[^"]+" promotion)$/
*/
public function iWantToViewAllCouponsOfThisPromotion(PromotionInterface $promotion): void
{
@ -610,6 +611,24 @@ final class ManagingPromotionCouponsContext implements Context
Assert::false($this->responseChecker->hasValue($this->client->update(), 'code', 'NEW_CODE'));
}
/**
* @Then /^("[^"]+" coupon) should be used (\d+) time(?:|s)$/
*/
public function couponShouldHaveUsageLimit(PromotionCouponInterface $promotionCoupon, int $used): void
{
$returnedPromotionCoupon = current($this->responseChecker->getCollectionItemsWithValue(
$this->client->getLastResponse(),
'code',
$promotionCoupon->getCode(),
));
Assert::same(
$returnedPromotionCoupon['used'],
$used,
sprintf('The promotion coupon %s has been used %s times', $promotionCoupon->getCode(), $returnedPromotionCoupon['used']),
);
}
private function sortBy(string $order, string $field): void
{
$this->client->sort([$field => str_starts_with($order, 'de') ? 'desc' : 'asc']);

View file

@ -827,6 +827,25 @@ final class ManagingPromotionsContext implements Context
Assert::same($item[$field], $value);
}
/**
* @Then the promotion :promotion should be used :usage time(s)
* @Then the promotion :promotion should not be used
*/
public function thePromotionShouldBeUsedTime(PromotionInterface $promotion, int $usage = 0): void
{
$returnedPromotion = current($this->responseChecker->getCollectionItemsWithValue(
$this->client->getLastResponse(),
'code',
$promotion->getCode()
));
Assert::same(
$returnedPromotion['used'],
$usage,
sprintf('The promotion %s has been used %s times', $promotion->getName(), $returnedPromotion['used']),
);
}
private function addToRequestAction(string $type, array $configuration): void
{
$data['actions'][] = [

View file

@ -27,6 +27,7 @@ default:
- sylius.behat.context.setup.order
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.product
- sylius.behat.context.setup.product_taxon
- sylius.behat.context.setup.promotion
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.taxonomy