minor #15002 Cover product integrity scenarios in 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 | 
| License         | MIT

Commits
-------

5c319cc0b6 Cover product integrity scenarios in API
This commit is contained in:
Kamil Grygierzec 2023-05-02 10:53:03 +02:00 committed by GitHub
commit e5d808bcb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 2 deletions

View file

@ -23,7 +23,7 @@ Feature: Order products integrity
Then I should be informed that this product has been disabled Then I should be informed that this product has been disabled
And I should not see the thank you page And I should not see the thank you page
@ui @ui @api
Scenario: Preventing customer from completing checkout with no longer available product variant Scenario: Preventing customer from completing checkout with no longer available product variant
Given I have "Small" variant of product "Super Cool T-Shirt" in the cart Given I have "Small" variant of product "Super Cool T-Shirt" in the cart
And I have proceeded selecting "Offline" payment method And I have proceeded selecting "Offline" payment method

View file

@ -115,6 +115,7 @@ final class CartContext implements Context
/** /**
* @When /^I add ("[^"]+" variant) of (this product) to the (cart)$/ * @When /^I add ("[^"]+" variant) of (this product) to the (cart)$/
* @When /^I add ("[^"]+" variant) of (product "[^"]+") to the (cart)$/ * @When /^I add ("[^"]+" variant) of (product "[^"]+") to the (cart)$/
* @When /^I have ("[^"]+" variant) of (product "[^"]+") in the (cart)$/
*/ */
public function iAddVariantOfThisProductToTheCart( public function iAddVariantOfThisProductToTheCart(
ProductVariantInterface $productVariant, ProductVariantInterface $productVariant,
@ -122,6 +123,7 @@ final class CartContext implements Context
?string $tokenValue, ?string $tokenValue,
): void { ): void {
$this->putProductVariantToCart($productVariant, $tokenValue, 1); $this->putProductVariantToCart($productVariant, $tokenValue, 1);
$this->sharedStorage->set('variant', $productVariant);
} }
/** /**

View file

@ -18,7 +18,9 @@ use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\RequestFactoryInterface; use Sylius\Behat\Client\RequestFactoryInterface;
use Sylius\Behat\Context\Api\Resources; use Sylius\Behat\Context\Api\Resources;
use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Symfony\Component\HttpFoundation\Request as HTTPRequest; use Symfony\Component\HttpFoundation\Request as HTTPRequest;
use Webmozart\Assert\Assert;
final class CheckoutCompleteContext implements Context final class CheckoutCompleteContext implements Context
{ {
@ -44,4 +46,15 @@ final class CheckoutCompleteContext implements Context
$this->client->executeCustomRequest($request); $this->client->executeCustomRequest($request);
} }
/**
* @Then /^I should be informed that (this variant) has been disabled$/
*/
public function iShouldBeInformedThatThisVariantHasBeenDisabled(ProductVariantInterface $productVariant): void
{
$lastResponseContent = $this->client->getLastResponse()->getContent();
Assert::string($lastResponseContent);
Assert::contains($lastResponseContent, sprintf('This product %s has been disabled.', $productVariant->getName()));
}
} }

View file

@ -477,7 +477,6 @@ final class CheckoutContext implements Context
* @Given I completed the payment step with :paymentMethod payment method * @Given I completed the payment step with :paymentMethod payment method
* @When I choose :paymentMethod payment method * @When I choose :paymentMethod payment method
* @When I select :paymentMethod payment method * @When I select :paymentMethod payment method
* @When I have proceeded selecting :paymentMethod payment method
* @When I proceed selecting :paymentMethod payment method * @When I proceed selecting :paymentMethod payment method
* @When /^the (?:customer|visitor) proceed with ("[^"]+" payment)$/ * @When /^the (?:customer|visitor) proceed with ("[^"]+" payment)$/
* @Given /^the (?:customer|visitor) has proceeded ("[^"]+" payment)$/ * @Given /^the (?:customer|visitor) has proceeded ("[^"]+" payment)$/
@ -513,6 +512,16 @@ final class CheckoutContext implements Context
$this->iChoosePaymentMethod($paymentMethod); $this->iChoosePaymentMethod($paymentMethod);
} }
/**
* @When I have proceeded selecting :paymentMethod payment method
*/
public function iHaveProceededSelectingPaymentMethod(PaymentMethodInterface $paymentMethod): void
{
$this->addressOrder($this->getArrayWithDefaultAddress());
$this->iCompleteTheShippingStepWithFirstShippingMethod();
$this->iChoosePaymentMethod($paymentMethod);
}
/** /**
* @Then /^(address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+") should be filled as (billing) address$/ * @Then /^(address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+") should be filled as (billing) address$/
* @Then /^the visitor should has ("[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+" specified as) (billing) address$/ * @Then /^the visitor should has ("[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+" specified as) (billing) address$/

View file

@ -28,6 +28,7 @@ use Sylius\Component\Core\Model\ProductTranslationInterface;
use Sylius\Component\Core\Model\ProductVariantInterface; use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Model\TaxonInterface; use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface; use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface;
use Sylius\Component\Core\Uploader\ImageUploaderInterface; use Sylius\Component\Core\Uploader\ImageUploaderInterface;
use Sylius\Component\Product\Factory\ProductFactoryInterface; use Sylius\Component\Product\Factory\ProductFactoryInterface;
use Sylius\Component\Product\Generator\ProductVariantGeneratorInterface; use Sylius\Component\Product\Generator\ProductVariantGeneratorInterface;
@ -59,6 +60,7 @@ final class ProductContext implements Context
private FactoryInterface $productImageFactory, private FactoryInterface $productImageFactory,
private ObjectManager $objectManager, private ObjectManager $objectManager,
private ProductVariantGeneratorInterface $productVariantGenerator, private ProductVariantGeneratorInterface $productVariantGenerator,
private ProductVariantRepositoryInterface $productVariantRepository,
private ProductVariantResolverInterface $defaultVariantResolver, private ProductVariantResolverInterface $defaultVariantResolver,
private ImageUploaderInterface $imageUploader, private ImageUploaderInterface $imageUploader,
private SlugGeneratorInterface $slugGenerator, private SlugGeneratorInterface $slugGenerator,
@ -1089,6 +1091,8 @@ final class ProductContext implements Context
*/ */
public function theSizeColorVariantOfThisProductIsDisabled(ProductVariantInterface $productVariant): void public function theSizeColorVariantOfThisProductIsDisabled(ProductVariantInterface $productVariant): void
{ {
/** @var ProductVariantInterface $productVariant */
$productVariant = $this->productVariantRepository->find($productVariant->getId());
$productVariant->setEnabled(false); $productVariant->setEnabled(false);
$this->objectManager->flush(); $this->objectManager->flush();

View file

@ -153,6 +153,7 @@
<argument type="service" id="sylius.factory.product_image" /> <argument type="service" id="sylius.factory.product_image" />
<argument type="service" id="doctrine.orm.entity_manager" /> <argument type="service" id="doctrine.orm.entity_manager" />
<argument type="service" id="sylius.generator.product_variant" /> <argument type="service" id="sylius.generator.product_variant" />
<argument type="service" id="sylius.repository.product_variant" />
<argument type="service" id="sylius.product_variant_resolver.default" /> <argument type="service" id="sylius.product_variant_resolver.default" />
<argument type="service" id="sylius.image_uploader" /> <argument type="service" id="sylius.image_uploader" />
<argument type="service" id="sylius.generator.slug" /> <argument type="service" id="sylius.generator.slug" />

View file

@ -15,6 +15,7 @@ default:
- sylius.behat.context.transform.locale - sylius.behat.context.transform.locale
- sylius.behat.context.transform.payment - sylius.behat.context.transform.payment
- sylius.behat.context.transform.product - sylius.behat.context.transform.product
- sylius.behat.context.transform.product_variant
- sylius.behat.context.transform.shared_storage - sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.shipping_method - sylius.behat.context.transform.shipping_method
- sylius.behat.context.transform.zone - sylius.behat.context.transform.zone