Skip to content

Commit

Permalink
Add tests for checking proper price per channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomanhez committed May 13, 2021
1 parent 66fe6b2 commit 94d6ac1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ Feature: Adding a product to cart with prices dependent on a channel
In order to buy products in correct prices
As a Customer
I want to add products to my cart with prices dependent on visited channel

Background:
Given the store has currency "EUR"
And the store has currency "GBP"
And the store operates on a channel named "Web-EU" in "EUR" currency
And the store operates on a channel named "Web-EU" in "EUR" currency and with hostname "web-eu"
And that channel allows to shop using "EUR" and "GBP" currencies
And the store operates on another channel named "Web-GB" in "GBP" currency
And the store operates on another channel named "Web-GB" in "GBP" currency and with hostname "web-gb"
And that channel allows to shop using "EUR" and "GBP" currencies
And the store has a product "Leprechaun's Gold" priced at "€10.00" in "Web-EU" channel
And this product is also priced at "£15.00" in "Web-GB" channel
And I am a logged in customer

@ui
@ui @api
Scenario: Buying a product in default currency for browsed channel
Given I change my current channel to "Web-EU"
When I add product "Leprechaun's Gold" to the cart
Expand Down
22 changes: 22 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public function theAdministratorTryToSeeTheSummaryOfCart(?string $tokenValue): v
*/
public function iAddThisProductToTheCart(ProductInterface $product, ?string $tokenValue): void
{
if (!$this->sharedStorage->has('cart_token')) {
$this->pickupCart();
}

$this->putProductToCart($product, $tokenValue);

$this->sharedStorage->set('product', $product);
Expand Down Expand Up @@ -334,6 +338,24 @@ public function iShouldBeNotifiedThatQuantityOfAddedProductCannotBeLowerThan1():
);
}

/**
* @Then /^I should see "([^"]+)" with unit price ("[^"]+") in my cart$/
*/
public function iShouldSeeProductWithUnitPriceInMyCart(string $productName, int $unitPrice): void
{
$response = $this->cartsClient->getLastResponse();

foreach ($this->responseChecker->getValue($response, 'items') as $item) {
if ($item['productName'] === $productName) {
Assert::same($item['unitPrice'], $unitPrice);

return;
}
}

throw new \InvalidArgumentException(sprintf('The product %s does not exist', $productName));
}

/**
* @Then there should be one item in my cart
*/
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Setup/ChannelContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function storeOperatesOnASingleChannel($currencyCode = null)
/**
* @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)"$/
* @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)" in "([^"]+)" currency$/
* @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)" in "([^"]+)" currency and with hostname "([^"]+)"$/
* @Given the store operates on a channel identified by :code code
* @Given the store (also) operates on a(nother) channel named :channelName with hostname :hostname
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ default:

- sylius.behat.context.setup.cart
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.currency
- sylius.behat.context.setup.product
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.shipping_category
- sylius.behat.context.setup.shop_api_security
- sylius.behat.context.setup.user

- sylius.behat.context.transform.cart
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.product
- sylius.behat.context.transform.product_variant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<attribute name="path">/shop/orders/{tokenValue}/items</attribute>
<attribute name="messenger">input</attribute>
<attribute name="input">Sylius\Bundle\ApiBundle\Command\Cart\AddItemToCart</attribute>
<attribute name="normalization_context">
<attribute name="groups">shop:cart:read</attribute>
</attribute>
<attribute name="denormalization_context">
<attribute name="groups">shop:cart:add_item</attribute>
</attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<attribute name="unitPrice">
<group>admin:order_item:read</group>
<group>shop:order_item:read</group>
<group>shop:cart:read</group>
</attribute>
<attribute name="units">
<group>admin:order_item:read</group>
Expand Down Expand Up @@ -89,7 +90,7 @@
<attribute name="total">
<group>admin:order:read</group>
<group>admin:order_item:read</group>
<group>shop:order_item:read</group>
<!-- <group>shop:order_item:read</group>-->
</attribute>
</class>
</serializer>

0 comments on commit 94d6ac1

Please sign in to comment.