Skip to content

Commit

Permalink
feature #12805 [Behat][API][Taxes] Turn on chunk of taxation related …
Browse files Browse the repository at this point in the history
…scenarios (lchrusciel)

This PR was merged into the 1.11-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | Part of #11250
| License         | MIT

<!--
 - Bug fixes must be submitted against the 1.9 or 1.10 branch (the lowest possible)
 - Features and deprecations must be submitted against the master branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------

6bc0d75 [Behat][API][Taxes] Turn on chunk of taxation scenarios
ad4b1a8 [Behat][API][Shiipin] Turn on chunk of shipping scenarios with taxation
  • Loading branch information
lchrusciel committed Jul 16, 2021
2 parents aaae1bf + ad4b1a8 commit 836f701
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ Feature: Apply correct shipping fee on order
And the store has "UPS" shipping method with "$5.00" fee per unit for "United States" channel
And I am a logged in customer

@ui
@ui @api
Scenario: Adding proper shipping fee
Given I have product "PHP T-Shirt" in the cart
When I proceed selecting "DHL" shipping method
Then my cart total should be "$110.00"
And my cart shipping total should be "$10.00"

@ui
@ui @api
Scenario: Changing shipping fee after shipping method change
Given I have product "PHP T-Shirt" in the cart
And I chose "DHL" shipping method
When I change shipping method to "FedEx"
Then my cart total should be "$130.00"
And my cart shipping total should be "$30.00"

@ui
@ui @api
Scenario: Changing per unit shipping fee after decreasing quantity of item
Given I have 2 products "PHP T-Shirt" in the cart
And I chose "UPS" shipping method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Feature: Apply correct shipping fee with product taxes on order
And the store allows paying offline
And I am a logged in customer

@ui
@ui @api
Scenario: Proper shipping fee, tax and product tax
Given I have product "PHP T-Shirt" in the cart
When I proceed selecting "DHL" shipping method
Expand All @@ -30,7 +30,7 @@ Feature: Apply correct shipping fee with product taxes on order
And my cart taxes should be "$25.30"
And my cart shipping total should be "$12.30"

@ui
@ui @api
Scenario: Proper shipping fee, tax and products' taxes after addressing
Given I have 3 products "PHP T-Shirt" in the cart
When I proceed selecting "Germany" as billing country with "FedEx" method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Apply correct shipping fee with taxes on order
And the store allows paying offline
And I am a logged in customer

@ui
@ui @api
Scenario: Proper shipping fee and tax
Given I have product "PHP T-Shirt" in the cart
When I proceed selecting "DHL" shipping method
Expand All @@ -29,7 +29,7 @@ Feature: Apply correct shipping fee with taxes on order
And my cart taxes should be "$2.30"
And my cart shipping total should be "$12.30"

@ui
@ui @api
Scenario: Proper shipping fee and tax after addressing
Given I have product "PHP T-Shirt" in the cart
When I proceed selecting "Germany" as billing country with "DHL-World" method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Feature: Apply correct taxes based on customer data
Then my cart total should be "$110.00"
And my cart taxes should be "$10.00"

@ui
@ui @api
Scenario: Proper taxes after specifying shipping address
Given I am a logged in customer
When I add product "PHP T-Shirt" to the cart
And I specified the billing address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
Then my cart total should be "$123.00"
And my cart taxes should be "$23.00"

@ui
@ui @api
Scenario: Proper taxes after specifying shipping address
Given I am a logged in customer
When I add product "PHP T-Shirt" to the cart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Feature: Apply correct taxes for items with different tax rates
And the store has a product "Symfony Mug" priced at "$50.00"
And it belongs to "Mugs" tax category

@ui
@ui @api
Scenario: Proper taxes for different taxed products
When I add product "PHP T-Shirt" to the cart
And I add product "Symfony Mug" to the cart
Then my cart total should be "$175.50"
And my cart taxes should be "$25.50"

@ui
@ui @api
Scenario: Proper taxes for multiple products with different tax rate
When I add 3 products "PHP T-Shirt" to the cart
And I add 4 products "Symfony Mug" to the cart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ Feature: Apply correct taxes for items with the same tax rate
And the store has a product "Symfony Hat" priced at "$30.00"
And it belongs to "Clothes" tax category

@ui
@ui @api
Scenario: Proper taxes for taxed product
When I add product "PHP T-Shirt" to the cart
Then my cart total should be "$123.00"
And my cart taxes should be "$23.00"

@ui
@ui @api
Scenario: Proper taxes for multiple same products with the same tax rate
When I add 3 products "PHP T-Shirt" to the cart
Then my cart total should be "$369.00"
And my cart taxes should be "$69.00"

@ui
@ui @api
Scenario: Proper taxes for multiple different products with the same tax rate
When I add 3 products "PHP T-Shirt" to the cart
And I add 2 products "Symfony Hat" to the cart
Then my cart total should be "$442.80"
And my cart taxes should be "$82.80"

@ui
@ui @api
Scenario: Proper taxes after removing one of the item
Given I have 3 products "PHP T-Shirt" in the cart
And I have 2 products "Symfony Hat" in the cart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ Feature: Apply correct taxes for an order with a discount for an item in it
And there is a promotion "PHP promotion"
And the promotion gives "$10.10" off on a "PHP Mug" product

@ui
@ui @api
Scenario: Properly rounded up tax for single product
When I add product "Symfony Mug" to the cart
Then my cart total should be "$50.55"
And my cart taxes should be "$4.60"

@ui
@ui @api
Scenario: Properly rounded down tax for single product
When I add product "PHP Mug" to the cart
Then my cart total should be "$50.53"
And my cart taxes should be "$4.59"

@ui
@ui @api
Scenario: Properly rounded taxes for order with multiple products without discount
When I add 2 products "PHP T-Shirt" to the cart
And I add product "Symfony Mug" to the cart
Then my cart total should be "$75.15"
And my cart taxes should be "$9.20"

@ui
@ui @api
Scenario: Properly rounded taxes for order with multiple products with discount
When I add 2 products "PHP T-Shirt" to the cart
And I add 2 products "Symfony Mug" to the cart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: Apply correct taxes for an order with a discount for a shipping
And the promotion gives "10%" discount on shipping to every order
And I am a logged in customer

@ui
@ui @api
Scenario: Properly rounded up tax
Given the store has "DHL" shipping method with "$51.06" fee
And shipping method "DHL" belongs to "Shipping" tax category
Expand All @@ -22,7 +22,7 @@ Feature: Apply correct taxes for an order with a discount for a shipping
Then my cart total should be "$60.55"
And my cart taxes should be "$4.60"

@ui
@ui @api
Scenario: Properly rounded down tax
Given the store has "DHL" shipping method with "$51.04" fee
And shipping method "DHL" belongs to "Shipping" tax category
Expand All @@ -31,7 +31,7 @@ Feature: Apply correct taxes for an order with a discount for a shipping
Then my cart total should be "$60.53"
And my cart taxes should be "$4.59"

@ui
@ui @api
Scenario: Properly calculated taxes when item belongs to different tax category
Given the store has "Standard VAT" tax rate of 23% for "Mugs" within the "US" zone
And the store has a product "Sonata Mug" priced at "$10.00"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@ Feature: Apply correct taxes for an order with a discount applied for all items
And there is a promotion "PHP promotion"
And the promotion gives "$10.10" off if order contains a "PHP Mug" product

@ui
@ui @api
Scenario: Properly rounded up tax for a single product
When I add product "Symfony Mug" to the cart
Then my cart total should be "$50.55"
And my cart taxes should be "$4.60"

@ui
@ui @api
Scenario: Properly rounded down tax for a single product
When I add product "PHP Mug" to the cart
Then my cart total should be "$50.53"
And my cart taxes should be "$4.59"

@ui
@ui @api
Scenario: Properly rounded taxes for multiple products with different tax rate
When I add 2 products "PHP T-Shirt" to the cart
And I add product "PHP Mug" to the cart
Then my cart total should be "$74.79"
And my cart taxes should be "$8.85"

@ui
@ui @api
Scenario: Properly rounded taxes for multiple products with the same tax rate
When I add 2 products "Symfony Mug" to the cart
And I add product "PHP Mug" to the cart
Then my cart total should be "$162.73"
And my cart taxes should be "$14.79"

@ui
@ui @api
Scenario: Properly rounded taxes for order with multiple promotions and multiple products with different tax rate
And there is a promotion "Clothing promotion"
And the promotion gives "$5.00" off if order contains a "PHP T-Shirt" product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Apply correct taxes on visitor cart
And the store has a product "PHP T-Shirt" priced at "$100.00"
And it belongs to "Clothes" tax category

@ui
@ui @api
Scenario: Proper taxes for taxed product
When I add product "PHP T-Shirt" to the cart
Then my cart total should be "$123.00"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ Feature: Not applying taxes for products without tax category
And the store has a product "PHP T-Shirt" priced at "$100.00"
And the store has a product "Symfony Mug" priced at "$30.00"

@ui
@ui @api
Scenario: Proper taxes for untaxed product
When I add product "PHP T-Shirt" to the cart
Then my cart total should be "$100.00"
And there should be no taxes charged

@ui
@ui @api
Scenario: Proper taxes for untaxed product with quantity specified
When I add 3 products "PHP T-Shirt" to the cart
Then my cart total should be "$300.00"
And there should be no taxes charged

@ui
@ui @api
Scenario: Proper taxes for multiple untaxed products
When I add product "PHP T-Shirt" to the cart
And I add product "Symfony Mug" to the cart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ Feature: Round taxes on order item level
And the store has a product "PHP Mug" priced at "$45.94"
And it belongs to "Mugs" tax category

@ui
@ui @api
Scenario: Properly rounded up tax for single product
When I add product "Symfony Mug" to the cart
Then my cart total should be "$50.55"
And my cart taxes should be "$4.60"

@ui
@ui @api
Scenario: Properly rounded down tax for single product
When I add product "PHP Mug" to the cart
Then my cart total should be "$50.53"
And my cart taxes should be "$4.59"

@ui
@ui @api
Scenario: Properly rounded taxes for multiple products
When I add 10 products "PHP T-Shirt" to the cart
Then my cart total should be "$124.23"
Expand Down
16 changes: 14 additions & 2 deletions src/Sylius/Behat/Context/Api/Shop/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,13 @@ public function myCartShouldBeCleared(): void
*/
public function myCartSTotalShouldBe(string $tokenValue, int $total): void
{
$response = $this->cartsClient->show($tokenValue);
$responseTotal = $this->responseChecker->getValue(
$this->cartsClient->show($tokenValue),
$response,
'total'
);

Assert::same($total, (int) $responseTotal);
Assert::same($total, (int) $responseTotal, 'Expected totals are not the same. Received message:' . $response->getContent());
}

/**
Expand Down Expand Up @@ -540,6 +541,17 @@ public function myCartShouldHaveItemsTotal(int $itemsTotal): void
);
}

/**
* @Then /^my cart taxes should be ("[^"]+")$/
*/
public function myCartTaxesShouldBe(int $taxTotal): void
{
Assert::same(
$this->responseChecker->getValue($this->cartsClient->getLastResponse(), 'taxTotal'),
$taxTotal
);
}

/**
* @Then /^my cart should have (\d+) items of (product "([^"]+)")$/
* @Then /^my cart should have quantity of (\d+) items of (product "([^"]+)")$/
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 @@ -874,6 +874,8 @@ public function myDiscountShouldBe(int $discount = 0): void
*/
public function thereShouldBeNoTaxesCharged(): void
{
$this->ordersClient->show($this->sharedStorage->get('cart_token'));

Assert::same($this->responseChecker->getValue($this->ordersClient->getLastResponse(), 'taxTotal'), 0);
}

Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Behat/Resources/config/suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ imports:
- suites/api/shipping/managing_shipments.yml
- suites/api/shipping/managing_shipping_categories.yml
- suites/api/shipping/managing_shipping_methods.yml
- suites/api/taxation/applying_taxes.yml
- suites/api/taxation/managing_tax_categories.yml
- suites/api/taxon/managing_taxons.yml
- suites/api/user/managing_administrators.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

default:
suites:
api_applying_taxes:
contexts:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.address
- sylius.behat.context.transform.cart
- sylius.behat.context.transform.country
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.product
- sylius.behat.context.transform.product_variant
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.shipping_method
- sylius.behat.context.transform.tax_category
- sylius.behat.context.transform.zone

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.currency
- sylius.behat.context.setup.customer
- sylius.behat.context.setup.geographical
- sylius.behat.context.setup.product
- sylius.behat.context.setup.promotion
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.taxation
- sylius.behat.context.setup.user
- sylius.behat.context.setup.zone
- sylius.behat.context.setup.shop_api_security
- sylius.behat.context.setup.cart

- sylius.behat.context.api.shop.cart
- sylius.behat.context.api.shop.checkout

filters:
tags: "@applying_taxes && @api"

0 comments on commit 836f701

Please sign in to comment.