Skip to content

Commit

Permalink
[Behat] Number of products on channel configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Apr 8, 2024
1 parent 48167a2 commit 513a7ca
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/services/processor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<argument type="service" id="doctrine.orm.entity_manager" />
<argument type="service" id="sylius.repository.product" />
<argument type="service" id="CommerceWeavers\SyliusAlsoBoughtPlugin\Provider\BoughtTogetherProductsAssociationProviderInterface" />
<argument type="service" id="CommerceWeavers\SyliusAlsoBoughtPlugin\Provider\SynchronizableProductsNumberProviderInterface" />
<tag name="messenger.message_handler" bus="sylius.event_bus" priority="15" />
</service>
</services>
Expand Down
33 changes: 33 additions & 0 deletions features/synchronizing_bought_together_products.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,39 @@ Feature: Synchronizing bought together products
And the "Grains" product should have usually been bought with "Twigs", "Bird bath", "Bird netting", "Weaver" and "Swan"
And the "Bird feeder" product should have usually been bought with "Grains", "Twigs", "Bird bath", "Bird netting" and "Swift"

@cli
Scenario: Synchronizing maximum number of bought together products
Given the channel "United States" has 2 configured as number of synchronizable bought together products
And the store has a product association type "Bought together" with a code "bought_together"
And the store has products "Weaver", "Swan", "Swift", "Grains", "Twigs", "Bird feeder", "Bird bath" and "Bird netting"
And there is a customer "john.doe@example.com" that placed an order
And the customer bought a single "Weaver", "Bird bath" and "Bird netting"
And the customer bought 100 "Grains" products
And the customer bought 500 "Twigs" products
And the customer "John Doe" addressed it to "Elm Street", "90802" "Anytown" in the "United States" with identical billing address
And the customer chose "Free" shipping method with "Cash on delivery" payment
And this order is already paid
And there is another customer "john.galt@example.com" that placed an order
And the customer bought a single "Swan"
And the customer bought 200 "Grains" products
And the customer bought 20 "Twigs" products
And the customer "John Galt" addressed it to "Atlas Way", "385" "Libertyville" in the "United States" with identical billing address
And the customer chose "Free" shipping method with "Cash on delivery" payment
And this order is already paid
And there is another customer "jane.doe@example.com" that placed an order
And the customer bought a single "Swift", "Bird feeder", "Bird bath" and "Bird netting"
And the customer bought 100 "Grains" products
And the customer bought 100 "Twigs" products
And the customer "Jane Doe" addressed it to "Elm Street", "90802" "Anytown" in the "United States" with identical billing address
And the customer chose "Free" shipping method with "Cash on delivery" payment
And this order is already paid
When I synchronize bought together products by running command
Then I should be informed that the bought together products are synchronized
And the "Weaver" product should have usually been bought with "Grains" and "Twigs"
And the "Swan" product should have usually been bought with "Grains" and "Twigs"
And the "Grains" product should have usually been bought with "Twigs" and "Bird bath"
And the "Bird feeder" product should have usually been bought with "Grains" and "Twigs"

@cli
Scenario: Being notified about specific association type requirement
Given the store has a product "Weaver"
Expand Down
28 changes: 28 additions & 0 deletions tests/Behat/Context/Setup/ChannelContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusAlsoBoughtPlugin\Behat\Context\Setup;

use Behat\Behat\Context\Context;
use CommerceWeavers\SyliusAlsoBoughtPlugin\Entity\BoughtTogetherConfigurableChannelInterface;
use Doctrine\ORM\EntityManagerInterface;

final class ChannelContext implements Context
{
public function __construct(private readonly EntityManagerInterface $entityManager)
{
}

/**
* @Given the channel :channel has :number configured as number of synchronizable bought together products
*/
public function theChannelHasConfiguredAsNumberOfSynchronizableBoughtTogetherProducts(
BoughtTogetherConfigurableChannelInterface $channel,
int $number,
): void {
$channel->setNumberOfSynchronisedProducts($number);

$this->entityManager->flush();
}
}
4 changes: 4 additions & 0 deletions tests/Behat/Resources/services/contexts/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
<service id="Tests\CommerceWeavers\SyliusAlsoBoughtPlugin\Behat\Context\Setup\SynchronizeBoughtTogetherProductsContext">
<argument type="service" id="Tests\CommerceWeavers\SyliusAlsoBoughtPlugin\Behat\Context\Cli\SynchronizeBoughtTogetherProductsContext" />
</service>

<service id="Tests\CommerceWeavers\SyliusAlsoBoughtPlugin\Behat\Context\Setup\ChannelContext">
<argument type="service" id="doctrine.orm.entity_manager" />
</service>
</services>
</container>
9 changes: 5 additions & 4 deletions tests/Behat/Resources/suites/cli/also_bought.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ default:
cli_also_bought:
contexts:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.geographical
- sylius.behat.context.setup.order
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.product
- sylius.behat.context.setup.product_association
- sylius.behat.context.setup.product_association
- sylius.behat.context.setup.shipping
- Tests\CommerceWeavers\SyliusAlsoBoughtPlugin\Behat\Context\Setup\ChannelContext
- Tests\CommerceWeavers\SyliusAlsoBoughtPlugin\Behat\Context\Setup\OrderContext
- Tests\CommerceWeavers\SyliusAlsoBoughtPlugin\Behat\Context\Setup\ProductContext

- sylius.behat.context.transform.address
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.customer
Expand All @@ -22,7 +23,7 @@ default:
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.shipping_method
- Tests\CommerceWeavers\SyliusAlsoBoughtPlugin\Behat\Context\Transform\ProductContext

- Tests\CommerceWeavers\SyliusAlsoBoughtPlugin\Behat\Context\Cli\CreateBoughtTogetherProductAssociationTypeContext
- Tests\CommerceWeavers\SyliusAlsoBoughtPlugin\Behat\Context\Cli\SynchronizeBoughtTogetherProductsContext
filters:
Expand Down

0 comments on commit 513a7ca

Please sign in to comment.