diff --git a/features/inventory/checkout_inventory/holding_inventory_units_during_checkout_process.feature b/features/inventory/checkout_inventory/holding_inventory_units_during_checkout_process.feature index 62e4b8dff01..d1cfd0a1cb2 100644 --- a/features/inventory/checkout_inventory/holding_inventory_units_during_checkout_process.feature +++ b/features/inventory/checkout_inventory/holding_inventory_units_during_checkout_process.feature @@ -14,7 +14,7 @@ Feature: Holding inventory units during checkout And there is a customer "sylius@example.com" that placed an order "#00000022" And I am logged in as an administrator - @ui + @ui @api Scenario: Holding inventory units Given the customer bought 3 "Iron Maiden T-Shirt" products And the customer chose "Free" shipping method to "United States" with "Offline" payment @@ -22,7 +22,7 @@ Feature: Holding inventory units during checkout Then 3 units of this product should be on hold And 5 units of this product should be on hand - @ui + @ui @api Scenario: Release hold units after order has been paid Given the customer bought 3 "Iron Maiden T-Shirt" products And the customer chose "Free" shipping method to "United States" with "Offline" payment diff --git a/features/inventory/managing_inventory/decreasing_invetory_below_on_hold_validation.feature b/features/inventory/managing_inventory/decreasing_invetory_below_on_hold_validation.feature index c60b39da36a..bfd87d11b59 100644 --- a/features/inventory/managing_inventory/decreasing_invetory_below_on_hold_validation.feature +++ b/features/inventory/managing_inventory/decreasing_invetory_below_on_hold_validation.feature @@ -17,7 +17,7 @@ Feature: Validation of decreasing inventory below on hold validation And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment And I am logged in as an administrator - @ui + @ui @api Scenario: Decreasing inventory when order was placed When I want to modify the "Wyborowa Vodka Exquisite" product variant And I change its quantity of inventory to 2 @@ -25,7 +25,7 @@ Feature: Validation of decreasing inventory below on hold validation Then I should be notified that on hand quantity must be greater than the number of on hold units And this variant should have a 5 item currently in stock - @ui + @ui @api Scenario: Decreasing inventory when order was cancelled Given the order "#00000023" was cancelled When I want to modify the "Wyborowa Vodka Exquisite" product variant @@ -34,7 +34,7 @@ Feature: Validation of decreasing inventory below on hold validation Then I should be notified that it has been successfully edited And this variant should have a 2 item currently in stock - @ui + @ui @api Scenario: Decreasing inventory when order was paid Given the order "#00000023" is already paid When I want to modify the "Wyborowa Vodka Exquisite" product variant diff --git a/features/inventory/verify_reserved_inventory_is_back_in_stock_on_order_cancelling.feature b/features/inventory/managing_inventory/verify_reserved_inventory_is_back_in_stock_on_order_cancelling.feature similarity index 98% rename from features/inventory/verify_reserved_inventory_is_back_in_stock_on_order_cancelling.feature rename to features/inventory/managing_inventory/verify_reserved_inventory_is_back_in_stock_on_order_cancelling.feature index 985ee6135de..c99f2d795f5 100644 --- a/features/inventory/verify_reserved_inventory_is_back_in_stock_on_order_cancelling.feature +++ b/features/inventory/managing_inventory/verify_reserved_inventory_is_back_in_stock_on_order_cancelling.feature @@ -18,7 +18,7 @@ Feature: Inventory releasing on order cancellation And the store allows paying with "Cash on Delivery" And I am logged in as an administrator - @ui + @ui @api Scenario: Verify the reserved inventory is back in stock after cancellation of a new order Given there is a customer "john.doe@gmail.com" that placed an order "#00000022" And the customer bought 3 units of "Green" variant of product "T-Shirt banana" @@ -28,7 +28,7 @@ Feature: Inventory releasing on order cancellation Then the variant "Green" should have 5 items on hand And the "Green" variant should have 0 items on hold - @ui + @ui @api Scenario: Verify the reserved inventory and quantity of product's items is back in stock after cancellation of paid order Given there is a customer "john.doe@gmail.com" that placed an order "#00000022" And the customer bought 3 units of "Green" variant of product "T-Shirt banana" @@ -39,7 +39,7 @@ Feature: Inventory releasing on order cancellation Then the variant "Green" should have 5 items on hand And the "Green" variant should have 0 items on hold - @ui + @ui @api Scenario: Verify the reserved inventory is back in stock after cancellation of a new order with two variants of product Given there is a customer "john.doe@gmail.com" that placed an order "#00000023" And the customer bought 3 units of "Green" variant of product "T-Shirt banana" @@ -52,7 +52,7 @@ Feature: Inventory releasing on order cancellation And the variant "Red" should have 5 items on hand And the "Red" variant should have 0 items on hold - @ui + @ui @api Scenario: Verify the reserved inventory and quantity of product's items is back in stock after cancellation of paid order with two variants of product Given there is a customer "john.doe@gmail.com" that placed an order "#00000023" And the customer bought 3 units of "Green" variant of product "T-Shirt banana" @@ -66,7 +66,7 @@ Feature: Inventory releasing on order cancellation And the variant "Red" should have 5 items on hand And the "Red" variant should have 0 items on hold - @ui + @ui @api Scenario: Verify the reserved inventory is back in stock after cancellation of a new order with two variants of different products Given there is a customer "john.doe@gmail.com" that placed an order "#00000024" And the customer bought 3 units of "Green" variant of product "T-Shirt banana" @@ -78,7 +78,7 @@ Feature: Inventory releasing on order cancellation And the "Yellow" variant of "Skirt watermelon" product should have 5 items on hand And the "Yellow" variant of "Skirt watermelon" product should have 0 items on hold - @ui + @ui @api Scenario: Verify the reserved inventory and quantity of product's items is back in stock after cancellation of paid order with two variants of different products Given there is a customer "john.doe@gmail.com" that placed an order "#00000024" And the customer bought 3 units of "Green" variant of product "T-Shirt banana" @@ -91,7 +91,7 @@ Feature: Inventory releasing on order cancellation And the "Yellow" variant of "Skirt watermelon" product should have 5 items on hand And the "Yellow" variant of "Skirt watermelon" product should have 0 items on hold - @ui + @ui @api Scenario: Verify the reserved inventory and quantity of product's items is back in stock after cancellation of a refunded order Given there is a customer "john.doe@gmail.com" that placed an order "#00000022" And the customer bought 3 units of "Green" variant of product "T-Shirt banana" diff --git a/features/inventory/viewing_product_variant_with_specify_quantity_of_items_on_hand.feature b/features/inventory/managing_inventory/viewing_product_variant_with_specify_quantity_of_items_on_hand.feature similarity index 98% rename from features/inventory/viewing_product_variant_with_specify_quantity_of_items_on_hand.feature rename to features/inventory/managing_inventory/viewing_product_variant_with_specify_quantity_of_items_on_hand.feature index 221d4c1c49f..a9313f26829 100644 --- a/features/inventory/viewing_product_variant_with_specify_quantity_of_items_on_hand.feature +++ b/features/inventory/managing_inventory/viewing_product_variant_with_specify_quantity_of_items_on_hand.feature @@ -15,7 +15,7 @@ Feature: Seeing product's variant with specify quantity of items on hand And the store allows paying with "Cash on Delivery" And I am logged in as an administrator - @ui + @ui @api Scenario: Seeing decreased quantity of product's items in selected variant after order payment Given there is a customer "lucy@teamlucifer.com" that placed an order "#00000666" And the customer bought 3 units of "Green" variant of product "T-Shirt banana" @@ -25,7 +25,7 @@ Feature: Seeing product's variant with specify quantity of items on hand When I view all variants of the product "T-Shirt banana" Then the variant "Green" should have 2 items on hand - @ui + @ui @api Scenario: Seeing decreased quantity of product's items from different variants after order payment Given there is a customer "lucy@teamlucifer.com" that placed an order "#00000666" And the customer bought 3 units of "Yellow" variant of product "T-Shirt banana" diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingProductVariantsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingProductVariantsContext.php index 468427e61ad..44f5a6f206f 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingProductVariantsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingProductVariantsContext.php @@ -19,11 +19,13 @@ use Sylius\Behat\Client\ResponseCheckerInterface; use Sylius\Behat\Context\Api\Resources; use Sylius\Behat\Service\Converter\SectionAwareIriConverterInterface; +use Sylius\Component\Core\Formatter\StringInflector; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Model\ProductVariantInterface; use Sylius\Component\Product\Model\ProductOptionInterface; use Sylius\Component\Product\Model\ProductOptionValueInterface; +use Sylius\Component\Product\Resolver\ProductVariantResolverInterface; use Sylius\Component\Shipping\Model\ShippingCategoryInterface; use Webmozart\Assert\Assert; @@ -32,6 +34,7 @@ final class ManagingProductVariantsContext implements Context private const FIRST_COLLECTION_ITEM = 0; public function __construct( + private ProductVariantResolverInterface $variantResolver, private ApiClientInterface $client, private ResponseCheckerInterface $responseChecker, private IriConverterInterface $iriConverter, @@ -225,6 +228,7 @@ public function iDoNotWantToHaveShippingRequiredForThisProductVariant(): void /** * @When /^I want to view all variants of (this product)$/ + * @When /^I view(?:| all) variants of the (product "[^"]+")$/ */ public function iWantToViewAllVariantsOfThisProduct(ProductInterface $product): void { @@ -287,6 +291,14 @@ public function iSetItsDimensionsTo(float $value): void ]); } + /** + * @When I change its quantity of inventory to :amount + */ + public function iChangeItsQuantityOfInventoryTo(int $amount): void + { + $this->client->updateRequestData(['onHand' => $amount]); + } + /** * @Then I should be notified that it has been successfully created */ @@ -584,6 +596,71 @@ public function theProductShouldHaveOnlyOneVariant(ProductInterface $product): v $this->iShouldSeeNumberOfProductVariantsInTheList(1); } + /** + * @Then /^(\d+) units of (this product) should be (on hand|on hold)$/ + */ + public function unitsOfThisProductShouldBeOn( + int $quantity, + ProductInterface $product, + string $field, + ): void { + /** @var ProductVariantInterface $variant */ + $variant = $this->variantResolver->getVariant($product); + Assert::isInstanceOf($variant, ProductVariantInterface::class); + + $this->iWantToViewAllVariantsOfThisProduct($product); + $this->theVariantShouldHaveItemsOn($variant, $quantity, $field); + } + + /** + * @Then /^there should be no units of (this product) on hold$/ + */ + public function thereShouldBeNoUnitsOfThisProductOnHold(ProductInterface $product): void + { + $this->unitsOfThisProductShouldBeOn(0, $product, 'on hold'); + } + + /** + * @Then /^the ("[^"]+" variant) should have (\d+) items (on hand|on hold)$/ + * @Then /^the (variant "[^"]+") should have (\d+) items (on hand|on hold)$/ + */ + public function theVariantShouldHaveItemsOn(ProductVariantInterface $variant, int $quantity, string $field): void + { + $variantsData = $this->responseChecker->getCollectionItemsWithValue( + $this->client->getLastResponse(), + 'code', + $variant->getCode(), + ); + + $variantData = array_pop($variantsData); + + Assert::same( + (int) $variantData[StringInflector::nameToCamelCase($field)], + $quantity, + ); + } + + /** + * @Then /^the ("[^"]+" variant of product "[^"]+") should have (\d+) items (on hand|on hold)$/ + * @Then /^the ("[^"]+" variant of "[^"]+" product) should have (\d+) items (on hand|on hold)$/ + * @Then /^(this variant) should have a (\d+) item currently in stock$/ + */ + public function theVariantOfProductShouldHaveItemsOn( + ProductVariantInterface $variant, + int $quantity, + string $field = 'on hand', + ): void { + $actualQuantity = $this->responseChecker->getValue( + $this->client->show(Resources::PRODUCT_VARIANTS, $variant->getCode()), + StringInflector::nameToCamelCase($field), + ); + + Assert::same( + (int) $actualQuantity, + $quantity, + ); + } + /** * @Then I should be notified that code has to be unique */ @@ -644,4 +721,15 @@ public function iShouldBeNotifiedThatTheVariantCanHaveOnlyOneValueConfiguredForA 'The product variant can have only one value configured for a single option.', ); } + + /** + * @Then I should be notified that on hand quantity must be greater than the number of on hold units + */ + public function iShouldBeNotifiedThatOnHandQuantityMustBeGreaterThanTheNumberOfOnHoldUnits(): void + { + Assert::contains( + $this->responseChecker->getError($this->client->getLastResponse()), + 'On hand must be greater than the number of on hold units', + ); + } } diff --git a/src/Sylius/Behat/Context/Transform/ProductVariantContext.php b/src/Sylius/Behat/Context/Transform/ProductVariantContext.php index c2998855c98..0d0c867cf11 100644 --- a/src/Sylius/Behat/Context/Transform/ProductVariantContext.php +++ b/src/Sylius/Behat/Context/Transform/ProductVariantContext.php @@ -32,6 +32,7 @@ public function __construct( /** * @Transform /^"([^"]+)" variant of product "([^"]+)"$/ + * @Transform /^"([^"]+)" variant of "([^"]+)" product$/ */ public function getProductVariantByNameAndProduct(string $variantName, string $productName): ProductVariantInterface { @@ -71,6 +72,7 @@ public function getProductVariantByNameAndThisProduct(string $variantName): Prod /** * @Transform /^"([^"]+)" product variant$/ * @Transform /^"([^"]+)" variant$/ + * @Transform /^variant "([^"]+)"$/ * @Transform :productVariant * @Transform :variant */ diff --git a/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml b/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml index cf1e127f801..a2029dd0091 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml @@ -132,6 +132,7 @@ + diff --git a/src/Sylius/Behat/Resources/config/suites.yml b/src/Sylius/Behat/Resources/config/suites.yml index 92c39b2c0db..b4d6f065165 100644 --- a/src/Sylius/Behat/Resources/config/suites.yml +++ b/src/Sylius/Behat/Resources/config/suites.yml @@ -25,6 +25,7 @@ imports: - suites/api/homepage/viewing_products.yml - suites/api/inventory/cart_inventory.yml - suites/api/inventory/checkout_inventory.yaml + - suites/api/inventory/managing_inventory.yaml - suites/api/locale/locales.yaml - suites/api/locale/managing_locales.yml - suites/api/order/managing_orders.yml diff --git a/src/Sylius/Behat/Resources/config/suites/api/inventory/checkout_inventory.yaml b/src/Sylius/Behat/Resources/config/suites/api/inventory/checkout_inventory.yaml index 91e4f9a625b..98c3f94a458 100644 --- a/src/Sylius/Behat/Resources/config/suites/api/inventory/checkout_inventory.yaml +++ b/src/Sylius/Behat/Resources/config/suites/api/inventory/checkout_inventory.yaml @@ -6,12 +6,15 @@ default: api_checkout_inventory: contexts: - sylius.behat.context.hook.doctrine_orm - + + - sylius.behat.context.setup.admin_api_security - sylius.behat.context.setup.channel + - sylius.behat.context.setup.order + - sylius.behat.context.setup.payment - sylius.behat.context.setup.product - sylius.behat.context.setup.shipping - - sylius.behat.context.setup.payment - sylius.behat.context.setup.shop_api_security + - sylius.behat.context.setup.user - sylius.behat.context.transform.address - sylius.behat.context.transform.cart @@ -22,9 +25,10 @@ default: - sylius.behat.context.transform.product - sylius.behat.context.transform.shared_storage - sylius.behat.context.transform.shipping_method - + - sylius.behat.context.api.shop.cart - sylius.behat.context.api.shop.checkout + - sylius.behat.context.api.admin.managing_product_variants filters: tags: "@checkout_inventory&&@api" diff --git a/src/Sylius/Behat/Resources/config/suites/api/inventory/managing_inventory.yaml b/src/Sylius/Behat/Resources/config/suites/api/inventory/managing_inventory.yaml new file mode 100644 index 00000000000..32b0066ab91 --- /dev/null +++ b/src/Sylius/Behat/Resources/config/suites/api/inventory/managing_inventory.yaml @@ -0,0 +1,35 @@ +# This file is part of the Sylius package. +# (c) Sylius Sp. z o.o. + +default: + suites: + api_managing_inventory: + contexts: + - sylius.behat.context.hook.doctrine_orm + + - sylius.behat.context.setup.admin_api_security + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.order + - sylius.behat.context.setup.payment + - sylius.behat.context.setup.product + - sylius.behat.context.setup.shipping + - sylius.behat.context.setup.shop_api_security + - sylius.behat.context.setup.user + + - sylius.behat.context.transform.address + - sylius.behat.context.transform.cart + - sylius.behat.context.transform.customer + - sylius.behat.context.transform.lexical + - sylius.behat.context.transform.order + - sylius.behat.context.transform.payment + - 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.api.admin.managing_product_variants + - sylius.behat.context.api.admin.response + - sylius.behat.context.api.admin.save + + filters: + tags: "@managing_inventory&&@api"