Skip to content

Commit

Permalink
minor #14947 Cover reapplying promotion on cart changes scenarios in …
Browse files Browse the repository at this point in the history
…API (jakubtobiasz)

This PR was merged into the 1.13 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.13
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | n/a
| License         | MIT




Commits
-------

2f56278 Cover reapplying promotion on cart changes scenarios in API
  • Loading branch information
TheMilek committed Apr 19, 2023
2 parents c53b676 + 2f56278 commit db561c9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Reapplying promotion on cart change
And there is a promotion "Holiday promotion"
And I am a logged in customer

@ui
@ui @api
Scenario: Not receiving discount on shipping after removing last item from cart
Given the store has "DHL" shipping method with "$10.00" fee
And the promotion gives "100%" discount on shipping to every order
Expand All @@ -21,7 +21,7 @@ Feature: Reapplying promotion on cart change
And there should be no shipping fee
And there should be no discount

@ui
@ui @api
Scenario: Receiving discount on shipping after shipping method change
Given the store has "DHL" shipping method with "$10.00" fee
And the store has "FedEx" shipping method with "$30.00" fee
Expand All @@ -32,7 +32,7 @@ Feature: Reapplying promotion on cart change
Then my cart total should be "$100.00"
And my cart shipping should be for Free

@ui
@ui @api
Scenario: Receiving discount after removing an item from the cart and then adding another one
Given the store has a product "Symfony T-Shirt" priced at "$150.00"
And the promotion gives "$10.00" discount to every order
Expand All @@ -42,18 +42,18 @@ Feature: Reapplying promotion on cart change
Then my cart total should be "$140.00"
And my discount should be "-$10.00"

@ui
@ui @api
Scenario: Not receiving discount when cart does not meet the required total value after removing an item
Given the promotion gives "$10.00" discount to every order with items total at least "$120.00"
And I have 2 products "PHP T-Shirt" in the cart
When I change "PHP T-Shirt" quantity to 1
When I change product "PHP T-Shirt" quantity to 1
Then my cart total should be "$100.00"
And there should be no discount

@ui
@ui @api
Scenario: Not receiving discount when cart does not meet the required quantity after removing an item
Given the promotion gives "$10.00" discount to every order with quantity at least 3
And I have 3 products "PHP T-Shirt" in the cart
When I change "PHP T-Shirt" quantity to 1
When I change product "PHP T-Shirt" quantity to 1
Then my cart total should be "$100.00"
And there should be no discount
12 changes: 10 additions & 2 deletions src/Sylius/Behat/Context/Api/Shop/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,24 @@ public function iAddThisProductWithToTheCart(
}

/**
* @Given /^I change (product "[^"]+") quantity to (\d+)$/
* @When /^I change (product "[^"]+") quantity to (\d+) in my (cart)$/
* @Given I change :productName quantity to :quantity
* @When /^the (?:visitor|customer) change (product "[^"]+") quantity to (\d+) in his (cart)$/
* @When /^the visitor try to change (product "[^"]+") quantity to (\d+) in the customer (cart)$/
* @When /^I try to change (product "[^"]+") quantity to (\d+) in my (cart)$/
*/
public function iChangeQuantityToInMyCart(ProductInterface $product, int $quantity, string $tokenValue): void
public function iChangeQuantityToInMyCart(ProductInterface $product, int $quantity, ?string $tokenValue = null): void
{
if (null === $tokenValue && $this->sharedStorage->has('cart_token')) {
$tokenValue = $this->sharedStorage->get('cart_token');
}

$itemResponse = $this->getOrderItemResponseFromProductInCart($product, $tokenValue);
$this->changeQuantityOfOrderItem((string) $itemResponse['id'], $quantity, $tokenValue);
}

/**
* @Given /^I removed (product "[^"]+") from the (cart)$/
* @When /^I remove (product "[^"]+") from the (cart)$/
*/
public function iRemoveProductFromTheCart(ProductInterface $product, string $tokenValue): void
Expand Down Expand Up @@ -362,6 +367,7 @@ public function myIncludedInPriceTaxesShouldBe(int $taxTotal): void

/**
* @Then /^my (cart) should be empty$/
* @Then /^(cart) should be empty with no value$/
*/
public function myCartShouldBeEmpty(string $tokenValue): void
{
Expand Down Expand Up @@ -686,6 +692,8 @@ public function myCartShouldHaveItems(int $quantity, ProductInterface $product):
* @Then /^my cart shipping total should be ("[^"]+")$/
* @Then I should not see shipping total for my cart
* @Then /^my cart estimated shipping cost should be ("[^"]+")$/
* @Then there should be no shipping fee
* @Then my cart shipping should be for Free
*/
public function myCartShippingFeeShouldBe(int $shippingTotal = 0): void
{
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ public function iTryToConfirmMyOrder(): void
* @When /^the visitor try to proceed with ("[^"]+" shipping method) in the customer cart$/
* @When I try to change shipping method to :shippingMethod
* @Given I proceed selecting :shippingMethod shipping method
* @Given I chose :shippingMethod shipping method
* @When I change shipping method to :shippingMethod
*/
public function iProceededWithShippingMethod(ShippingMethodInterface $shippingMethod): void
{
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Ui/Shop/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function iRemoveVariantFromTheCart(ProductVariantInterface $variant): voi

/**
* @Given I change :productName quantity to :quantity
* @Given I change product :productName quantity to :quantity
* @Given I change product :productName quantity to :quantity in my cart
*/
public function iChangeQuantityTo($productName, $quantity)
Expand Down

0 comments on commit db561c9

Please sign in to comment.