Skip to content

Commit

Permalink
refactor #14899 [PriceHistory] Extract config (NoResponseMate)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.13 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.13 |
| Bug fix?        | no                                                       |
| New feature?    | yes                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | no |
| Related tickets | - |
| License         | MIT                                                          |

Commits
-------

c845cd6 [PriceHistory][Behat] Update channel edition scenarios
cade56c [PriceHistory] Add ChannelPriceHistoryConfig
77addfe [Channel][PriceHistory] Extract config
28e8a8b [API] Crud of ChannelPriceHistoryConfig
2ed5c9c [Admin] Use ChannelPriceHistoryConfig in channel crud
c932710 [PriceHistory] Update prices processing on period change
36c4c33 [API] Remove leftover validation listener
  • Loading branch information
GSadee committed Mar 30, 2023
2 parents b4ee5ae + 36c4c33 commit 2f77425
Show file tree
Hide file tree
Showing 74 changed files with 1,979 additions and 647 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,60 @@ Feature: Specifying the lowest price for discounted products checking period whi
And this channel has 15 days set as the lowest price for discounted products checking period
And I am logged in as an administrator

@api @ui
@no-api @ui
Scenario: Changing the lowest price for discounted products checking period
When I want to modify a channel "EU"
And I specify 30 days as the lowest price for discounted products checking period
And I save my changes
Then I should be notified that it has been successfully edited
And its lowest price for discounted products checking period should be set to 30 days

@api @ui
@no-api @ui
Scenario: Being prevented from changing the lowest price for discounted products checking period to zero
When I want to modify a channel "EU"
And I specify 0 days as the lowest price for discounted products checking period
And I try to save my changes
Then I should be notified that the lowest price for discounted products checking period must be greater than 0

@api @ui
@no-api @ui
Scenario: Being prevented from changing the lowest price for discounted products checking period to a negative value
When I want to modify a channel "EU"
And I specify -10 days as the lowest price for discounted products checking period
And I try to save my changes
Then I should be notified that the lowest price for discounted products checking period must be greater than 0

@api @ui
@no-api @ui
Scenario: Being prevented from changing the lowest price for discounted products checking period to a too big value
When I want to modify a channel "EU"
And I specify 99999999999 days as the lowest price for discounted products checking period
And I try to save my changes
Then I should be notified that the lowest price for discounted products checking period must be lower

@api @no-ui
Scenario: Changing the lowest price for discounted products checking period
When I want to modify the price history config of channel "EU"
And I change the lowest price for discounted products checking period to 30 days
And I save my changes
Then I should be notified that it has been successfully edited
And its lowest price for discounted products checking period should be set to 30 days

@api @no-ui
Scenario: Being prevented from changing the lowest price for discounted products checking period to zero
When I want to modify the price history config of channel "EU"
And I change the lowest price for discounted products checking period to 0 days
And I try to save my changes
Then I should be notified that the lowest price for discounted products checking period must be greater than 0

@api @no-ui
Scenario: Being prevented from changing the lowest price for discounted products checking period to a negative value
When I want to modify the price history config of channel "EU"
And I change the lowest price for discounted products checking period to -10 days
And I try to save my changes
Then I should be notified that the lowest price for discounted products checking period must be greater than 0

@api @no-ui
Scenario: Being prevented from changing the lowest price for discounted products checking period to a too big value
When I want to modify the price history config of channel "EU"
And I change the lowest price for discounted products checking period to 99999999999 days
And I try to save my changes
Then I should be notified that the lowest price for discounted products checking period must be lower
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,34 @@ Feature: Choosing whether to show the lowest product price or not while editing
And the channel "US Channel" has showing the lowest price of discounted products disabled
And I am logged in as an administrator

@api @ui
@no-api @ui
Scenario: Enabling showing the lowest price of discounted products on a channel
When I want to modify a channel "US Channel"
And I enable showing the lowest price of discounted products
And I save my changes
Then I should be notified that it has been successfully edited
And the "US Channel" channel should have the lowest price of discounted products prior to the current discount enabled

@api @ui
@no-api @ui
Scenario: Disabling showing the lowest price of discounted products on a channel
When I want to modify a channel "EU Channel"
And I disable showing the lowest price of discounted products
And I save my changes
Then I should be notified that it has been successfully edited
And the "EU Channel" channel should have the lowest price of discounted products prior to the current discount disabled

@api @no-ui
Scenario: Enabling showing the lowest price of discounted products on a channel
When I want to modify the price history config of channel "US Channel"
And I change showing of the lowest price of discounted products to be enabled
And I save my changes
Then I should be notified that it has been successfully edited
And the "US Channel" channel should have the lowest price of discounted products prior to the current discount enabled

@api @no-ui
Scenario: Disabling showing the lowest price of discounted products on a channel
When I want to modify the price history config of channel "EU Channel"
And I change showing of the lowest price of discounted products to be disabled
And I save my changes
Then I should be notified that it has been successfully edited
And the "EU Channel" channel should have the lowest price of discounted products prior to the current discount disabled
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ Feature: Excluding chosen taxons from displaying the lowest price of discounted
And the store classifies its products as "T-Shirts", "Caps" and "Sweaters"
And I am logged in as an administrator

@api @ui @javascript
@no-api @ui @javascript
Scenario: Excluding a singular taxon from displaying the lowest price of discounted products
When I want to modify a channel "Poland"
And I exclude the "T-Shirts" taxon from showing the lowest price of discounted products
And I save my changes
Then I should be notified that it has been successfully edited
And this channel should have "T-Shirts" taxon excluded from displaying the lowest price of discounted products

@api @ui @javascript
@no-api @ui @javascript
Scenario: Excluding multiple taxons from displaying the lowest price of discounted products
When I want to modify a channel "Poland"
And I exclude the "T-Shirts" and "Caps" taxons from showing the lowest price of discounted products
And I save my changes
Then I should be notified that it has been successfully edited
And this channel should have "T-Shirts" and "Caps" taxons excluded from displaying the lowest price of discounted products

@ui @javascript @no-api
@no-api @ui @javascript
Scenario: Removing excluded taxon from displaying the lowest price of discounted products
Given the channel "Poland" has "T-Shirts" and "Caps" taxons excluded from showing the lowest price of discounted products
When I want to modify this channel
Expand All @@ -34,3 +34,19 @@ Feature: Excluding chosen taxons from displaying the lowest price of discounted
Then I should be notified that it has been successfully edited
And this channel should have "Caps" taxon excluded from displaying the lowest price of discounted products
And this channel should not have "T-Shirts" taxon excluded from displaying the lowest price of discounted products

@api @no-ui
Scenario: Excluding a singular taxon from displaying the lowest price of discounted products
When I want to modify the price history config of channel "Poland"
And I exclude the "T-Shirts" taxon from showing the lowest price of discounted products
And I save my changes
Then I should be notified that it has been successfully edited
And this channel should have "T-Shirts" taxon excluded from displaying the lowest price of discounted products

@api @no-ui
Scenario: Excluding multiple taxons from displaying the lowest price of discounted products
When I want to modify the price history config of channel "Poland"
And I exclude the "T-Shirts" and "Caps" taxons from showing the lowest price of discounted products
And I save my changes
Then I should be notified that it has been successfully edited
And this channel should have "T-Shirts" and "Caps" taxons excluded from displaying the lowest price of discounted products
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function iGoToThePriceHistoryOfAVariant(ProductVariantInterface $productV

$this->sharedStorage->set('variant', $productVariant);

$this->client->index(Resources::CHANNEL_PRICING_LOG_ENTRY);
$this->client->index(Resources::CHANNEL_PRICING_LOG_ENTRIES);
$this->client->addFilter('channelPricing.channelCode', $channel->getCode());
$this->client->addFilter('channelPricing.productVariant.code', $productVariant->getCode());
$this->client->filter();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Behat\Context\Api\Admin;

use ApiPlatform\Core\Api\IriConverterInterface;
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Context\Api\Resources;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Webmozart\Assert\Assert;

final class ManagingChannelPriceHistoryConfigsContext implements Context
{
public function __construct(
private SharedStorageInterface $sharedStorage,
private ApiClientInterface $client,
private ResponseCheckerInterface $responseChecker,
private IriConverterInterface $iriConverter,
) {
}

/**
* @When /^I want to modify the price history config of (channel "[^"]+")$/
*/
public function iWantToModifyThePriceHistoryConfigOfChannel(ChannelInterface $channel): void
{
$this->sharedStorage->set('channel', $channel);
$this->client->buildUpdateRequest(
Resources::CHANNEL_PRICE_HISTORY_CONFIGS,
(string) $channel->getChannelPriceHistoryConfig()->getId(),
);
}

/**
* @When /^I change showing of the lowest price of discounted products to be (enabled|disabled)$/
*/
public function iChangeShowingOfTheLowestPriceOfDiscountedProducts(string $visible): void
{
$this->client->addRequestData(
'lowestPriceForDiscountedProductsVisible',
$visible === 'enabled',
);
}

/**
* @When /^I change the lowest price for discounted products checking period to (-?\d+) days$/
*/
public function iChangeTheLowestPriceForDiscountedProductsCheckingPeriodToDays(int $days): void
{
$this->client->addRequestData('lowestPriceForDiscountedProductsCheckingPeriod', $days);
}

/**
* @When I exclude the :taxon taxon from showing the lowest price of discounted products
*/
public function iExcludeTheTaxonFromShowingTheLowestPriceOfDiscountedProducts(TaxonInterface $taxon): void
{
$this->iExcludeTheTaxonsFromShowingTheLowestPriceOfDiscountedProducts([$taxon]);
}

/**
* @When /^I exclude the ("[^"]+" and "[^"]+" taxons) from showing the lowest price of discounted products$/
*/
public function iExcludeTheTaxonsFromShowingTheLowestPriceOfDiscountedProducts(iterable $taxons): void
{
$taxonsIris = [];
foreach ($taxons as $taxon) {
$taxonsIris[] = $this->iriConverter->getIriFromItem($taxon);
}

$this->client->addRequestData('taxonsExcludedFromShowingLowestPrice', $taxonsIris);
}

/**
* @Then /^the ("[^"]+" channel) should have the lowest price of discounted products prior to the current discount (enabled|disabled)$/
*/
public function theChannelShouldHaveTheLowestPriceOfDiscountedProductsPriorToTheCurrentDiscountEnabledOrDisabled(
ChannelInterface $channel,
string $visible,
): void {
$lowestPriceForDiscountedProductsVisible = $this->responseChecker->getValue(
$this->client->show(
Resources::CHANNEL_PRICE_HISTORY_CONFIGS,
(string) $channel->getChannelPriceHistoryConfig()->getId(),
),
'lowestPriceForDiscountedProductsVisible',
);

Assert::same($lowestPriceForDiscountedProductsVisible, $visible === 'enabled');
}

/**
* @Then /^the ("[^"]+" channel) should have the lowest price for discounted products checking period set to (\d+) days$/
* @Then /^(its) lowest price for discounted products checking period should be set to (\d+) days$/
*/
public function theChannelShouldHaveTheLowestPriceForDiscountedProductsCheckingPeriodSetToDays(
ChannelInterface $channel,
int $days,
): void {
$lowestPriceForDiscountedProductsCheckingPeriod = $this->responseChecker->getValue(
$this->client->show(
Resources::CHANNEL_PRICE_HISTORY_CONFIGS,
(string) $channel->getChannelPriceHistoryConfig()->getId(),
),
'lowestPriceForDiscountedProductsCheckingPeriod',
);

Assert::same($lowestPriceForDiscountedProductsCheckingPeriod, $days);
}

/**
* @Then I should be notified that the lowest price for discounted products checking period must be greater than 0
*/
public function iShouldBeNotifiedThatTheLowestPriceForDiscountedProductsCheckingPeriodMustBeGreaterThanZero(): void
{
Assert::true($this->responseChecker->hasViolationWithMessage(
$this->client->getLastResponse(),
'Value must be greater than 0',
'lowestPriceForDiscountedProductsCheckingPeriod',
));
}

/**
* @Then I should be notified that the lowest price for discounted products checking period must be lower
*/
public function iShouldBeNotifiedThatTheLowestPriceForDiscountedProductsCheckingPeriodMustBeLower(): void
{
Assert::true($this->responseChecker->hasViolationWithMessage(
$this->client->getLastResponse(),
'Value must be less than 2147483647',
'lowestPriceForDiscountedProductsCheckingPeriod',
));
}

/**
* @Then /^(this channel) should have ("[^"]+" taxon) excluded from displaying the lowest price of discounted products$/
*/
public function thisChannelShouldHaveTaxonExcludedFromDisplayingTheLowestPriceOfDiscountedProducts(
ChannelInterface $channel,
TaxonInterface $taxon,
): void {
$excludedTaxons = $this->responseChecker->getValue(
$this->client->show(
Resources::CHANNEL_PRICE_HISTORY_CONFIGS,
(string) $channel->getChannelPriceHistoryConfig()->getId(),
),
'taxonsExcludedFromShowingLowestPrice',
);

Assert::true($this->isResourceAdminIriInArray($taxon, $excludedTaxons));
}

/**
* @Then /^(this channel) should have ("([^"]+)" and "([^"]+)" taxons) excluded from displaying the lowest price of discounted products$/
*/
public function thisChannelShouldHaveTaxonsExcludedFromDisplayingTheLowestPriceOfDiscountedProducts(
ChannelInterface $channel,
iterable $taxons,
): void {
$excludedTaxons = $this->responseChecker->getValue(
$this->client->show(
Resources::CHANNEL_PRICE_HISTORY_CONFIGS,
(string) $channel->getChannelPriceHistoryConfig()->getId(),
),
'taxonsExcludedFromShowingLowestPrice',
);

foreach ($taxons as $taxon) {
Assert::true($this->isResourceAdminIriInArray($taxon, $excludedTaxons));
}
}

/**
* @Then /^(this channel) should not have ("[^"]+" taxon) excluded from displaying the lowest price of discounted products$/
*/
public function thisChannelShouldNotHaveTaxonExcludedFromDisplayingTheLowestPriceOfDiscountedProducts(
ChannelInterface $channel,
TaxonInterface $taxon,
): void {
$excludedTaxons = (array) $this->responseChecker->getValue(
$this->client->show(
Resources::CHANNEL_PRICE_HISTORY_CONFIGS,
(string) $channel->getChannelPriceHistoryConfig()->getId(),
),
'taxonsExcludedFromShowingLowestPrice',
);

Assert::false($this->isResourceAdminIriInArray($taxon, $excludedTaxons));
}

private function isResourceAdminIriInArray(ResourceInterface $resource, array $iris): bool
{
$iri = $this->iriConverter->getIriFromItemInSection($resource, 'admin');

return in_array($iri, $iris, true);
}
}
Loading

0 comments on commit 2f77425

Please sign in to comment.