Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API][Admin] Cover inventory #15623

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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
When I view variants of the product "Iron Maiden T-Shirt"
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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
And I save my changes
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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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',
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(

/**
* @Transform /^"([^"]+)" variant of product "([^"]+)"$/
* @Transform /^"([^"]+)" variant of "([^"]+)" product$/
*/
public function getProductVariantByNameAndProduct(string $variantName, string $productName): ProductVariantInterface
{
Expand Down Expand Up @@ -71,6 +72,7 @@ public function getProductVariantByNameAndThisProduct(string $variantName): Prod
/**
* @Transform /^"([^"]+)" product variant$/
* @Transform /^"([^"]+)" variant$/
* @Transform /^variant "([^"]+)"$/
* @Transform :productVariant
* @Transform :variant
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
</service>

<service id="sylius.behat.context.api.admin.managing_product_variants" class="Sylius\Behat\Context\Api\Admin\ManagingProductVariantsContext">
<argument type="service" id="Sylius\Component\Product\Resolver\ProductVariantResolverInterface" />
<argument type="service" id="sylius.behat.api_platform_client.admin" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="api_platform.iri_converter" />
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Original file line number Diff line number Diff line change
@@ -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"