mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
Add scenarios for coupon usage tracking and re-enablement in feature tests
This commit is contained in:
parent
d1d9e48ade
commit
3f32813569
3 changed files with 75 additions and 0 deletions
|
|
@ -73,3 +73,59 @@ Feature: Applying promotion coupon with per customer usage limit
|
|||
When I check the details of my cart
|
||||
Then my cart total should be "$100.00"
|
||||
And there should be no discount applied
|
||||
|
||||
@api @ui
|
||||
Scenario: Orders placed before track usage was re-enabled do not count toward per customer usage limit
|
||||
Given this coupon can be used once per customer
|
||||
And I placed an order "#00000022"
|
||||
And I bought a single "PHP T-Shirt" using "SANTA2016" coupon
|
||||
And I chose "Free" shipping method to "United States" with "Cash on Delivery" payment
|
||||
And this coupon has had its track usage re-enabled
|
||||
And I added product "PHP T-Shirt" to the cart
|
||||
And I applied the coupon with code "SANTA2016"
|
||||
When I check the details of my cart
|
||||
Then my cart total should be "$90.00"
|
||||
And my discount should be "-$10.00"
|
||||
|
||||
@api @ui
|
||||
Scenario: Enabling track usage does not count orders placed before tracking was enabled
|
||||
Given this coupon has track usage disabled
|
||||
And this coupon can be used once per customer
|
||||
And I placed an order "#00000022"
|
||||
And I bought a single "PHP T-Shirt" using "SANTA2016" coupon
|
||||
And I chose "Free" shipping method to "United States" with "Cash on Delivery" payment
|
||||
And this coupon has had its track usage re-enabled
|
||||
And I added product "PHP T-Shirt" to the cart
|
||||
And I applied the coupon with code "SANTA2016"
|
||||
When I check the details of my cart
|
||||
Then my cart total should be "$90.00"
|
||||
And my discount should be "-$10.00"
|
||||
|
||||
@api @ui
|
||||
Scenario: Removing per customer usage limit allows customer to use the coupon after the limit was reached
|
||||
Given this coupon can be used once per customer
|
||||
And I placed an order "#00000022"
|
||||
And I bought a single "PHP T-Shirt" using "SANTA2016" coupon
|
||||
And I chose "Free" shipping method to "United States" with "Cash on Delivery" payment
|
||||
And this coupon has no per customer usage limit
|
||||
And I added product "PHP T-Shirt" to the cart
|
||||
And I applied the coupon with code "SANTA2016"
|
||||
When I check the details of my cart
|
||||
Then my cart total should be "$90.00"
|
||||
And my discount should be "-$10.00"
|
||||
|
||||
@api @ui
|
||||
Scenario: Orders placed after track usage was re-enabled still count toward per customer usage limit
|
||||
Given this coupon can be used once per customer
|
||||
And I placed an order "#00000022"
|
||||
And I bought a single "PHP T-Shirt" using "SANTA2016" coupon
|
||||
And I chose "Free" shipping method to "United States" with "Cash on Delivery" payment
|
||||
And this coupon has had its track usage re-enabled
|
||||
And I placed an order "#00000023"
|
||||
And I bought a single "PHP T-Shirt" using "SANTA2016" coupon
|
||||
And I chose "Free" shipping method to "United States" with "Cash on Delivery" payment
|
||||
And I added product "PHP T-Shirt" to the cart
|
||||
And I applied the coupon with code "SANTA2016"
|
||||
When I check the details of my cart
|
||||
Then my cart total should be "$100.00"
|
||||
And there should be no discount applied
|
||||
|
|
|
|||
|
|
@ -23,9 +23,11 @@ use Sylius\Component\Core\Factory\PromotionActionFactoryInterface;
|
|||
use Sylius\Component\Core\Factory\PromotionRuleFactoryInterface;
|
||||
use Sylius\Component\Core\Formatter\StringInflector;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Core\Model\ProductInterface;
|
||||
use Sylius\Component\Core\Model\PromotionCouponInterface;
|
||||
use Sylius\Component\Core\Model\PromotionInterface;
|
||||
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
|
||||
use Sylius\Component\Core\Model\TaxonInterface;
|
||||
use Sylius\Component\Core\Promotion\Checker\Rule\ContainsProductRuleChecker;
|
||||
use Sylius\Component\Core\Promotion\Checker\Rule\CustomerGroupRuleChecker;
|
||||
|
|
@ -58,6 +60,7 @@ final readonly class PromotionContext implements Context
|
|||
private ObjectManager $objectManager,
|
||||
private ExampleFactoryInterface $promotionExampleFactory,
|
||||
private MessageBusInterface $commandBus,
|
||||
private OrderRepositoryInterface $orderRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -308,6 +311,21 @@ final readonly class PromotionContext implements Context
|
|||
$this->objectManager->flush();
|
||||
}
|
||||
|
||||
#[Given('/^(this coupon) has had its track usage re-enabled$/')]
|
||||
public function thisCouponHasHadItsTrackUsageReEnabled(PromotionCouponInterface $coupon): void
|
||||
{
|
||||
/** @var OrderInterface[] $orders */
|
||||
$orders = $this->orderRepository->findBy(['promotionCoupon' => $coupon]);
|
||||
foreach ($orders as $order) {
|
||||
$order->setCheckoutCompletedAt(new \DateTimeImmutable('-1 day'));
|
||||
}
|
||||
|
||||
$coupon->setTrackUsage(false);
|
||||
$coupon->setTrackUsage(true);
|
||||
|
||||
$this->objectManager->flush();
|
||||
}
|
||||
|
||||
#[Given('/^(this coupon) has already reached its usage limit$/')]
|
||||
public function thisCouponHasReachedItsUsageLimit(PromotionCouponInterface $coupon): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -362,6 +362,7 @@ return static function (ContainerConfigurator $container) {
|
|||
service('doctrine.orm.entity_manager'),
|
||||
service('sylius.fixture.example_factory.promotion'),
|
||||
service('sylius.command_bus'),
|
||||
service('sylius.repository.order'),
|
||||
])
|
||||
;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue