mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[PriceHistory][API] Add behat context
This commit is contained in:
parent
f774da1af8
commit
23d616c3c2
5 changed files with 134 additions and 0 deletions
|
|
@ -0,0 +1,90 @@
|
|||
<?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 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\ProductVariantInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class ChannelPricingLogEntryContext implements Context
|
||||
{
|
||||
public function __construct(
|
||||
private ApiClientInterface $client,
|
||||
private ResponseCheckerInterface $responseChecker,
|
||||
private SharedStorageInterface $sharedStorage,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I go to the price history of a (variant with code "[^"]+")$/
|
||||
*/
|
||||
public function iGoToThePriceHistoryOfAVariant(ProductVariantInterface $productVariant): void
|
||||
{
|
||||
$channel = $this->sharedStorage->get('channel');
|
||||
Assert::notNull($channel);
|
||||
|
||||
$this->sharedStorage->set('variant', $productVariant);
|
||||
|
||||
$this->client->index(Resources::CHANNEL_PRICING_LOG_ENTRY);
|
||||
$this->client->addFilter('channelPricing.channelCode', $channel->getCode());
|
||||
$this->client->addFilter('channelPricing.productVariant.code', $productVariant->getCode());
|
||||
$this->client->filter();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see :count log entries in the catalog price history
|
||||
* @Then I should see a single log entry in the catalog price history
|
||||
*/
|
||||
public function iShouldSeeLogEntriesInTheCatalogPriceHistoryForTheVariant(int $count = 1): void
|
||||
{
|
||||
Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^there should be a log entry on the (\d+)(?:|st|nd|rd|th) position with the ("[^"]+") selling price, (no|"[^"]+") original price and datetime of the price change$/
|
||||
*/
|
||||
public function thereShouldBeALogEntryOnThePositionWithTheSellingPriceOriginalPriceAndDatetimeOfThePriceChange(
|
||||
int $position,
|
||||
int $price,
|
||||
int|string $originalPrice,
|
||||
): void {
|
||||
if ('no' === $originalPrice) {
|
||||
$originalPrice = null;
|
||||
}
|
||||
|
||||
$logEntry = $this->responseChecker->getCollection($this->client->getLastResponse())[$position - 1];
|
||||
|
||||
Assert::same($logEntry['price'], $price);
|
||||
Assert::same($logEntry['originalPrice'], $originalPrice);
|
||||
Assert::keyExists($logEntry, 'loggedAt');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^there should be a log entry with the ("[^"]+") selling price, (no|"[^"]+") original price and datetime of the price change$/
|
||||
*/
|
||||
public function thereShouldBeALogEntryWithTheSellingPriceOriginalPriceAndDatetimeOfThePriceChange(
|
||||
int $price,
|
||||
int|string $originalPrice,
|
||||
): void {
|
||||
$this->thereShouldBeALogEntryOnThePositionWithTheSellingPriceOriginalPriceAndDatetimeOfThePriceChange(
|
||||
1,
|
||||
$price,
|
||||
$originalPrice,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -63,6 +63,19 @@ final class ManagingProductVariantsContext implements Context
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I set its original price to ("[^"]+") for ("[^"]+" channel)$/
|
||||
*/
|
||||
public function iSetItsOriginalPriceToForChannel(int $originalPrice, ChannelInterface $channel): void
|
||||
{
|
||||
$this->client->addRequestData('channelPricings', [
|
||||
$channel->getCode() => [
|
||||
'originalPrice' => $originalPrice,
|
||||
'channelCode' => $channel->getCode(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I set its minimum price to ("[^"]+") for ("[^"]+" channel)$/
|
||||
*/
|
||||
|
|
@ -126,6 +139,27 @@ final class ManagingProductVariantsContext implements Context
|
|||
$this->createNewVariantWithPrice($name, $price, $product, $channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I want to modify the :variant product variant
|
||||
*/
|
||||
public function iWantToModifyProductVariant(ProductVariantInterface $variant): void
|
||||
{
|
||||
$this->client->buildUpdateRequest(Resources::PRODUCT_VARIANTS, $variant->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I change its price to ("[^"]+") for ("[^"]+" channel)$/
|
||||
*/
|
||||
public function iChangeItsPriceToForChannel(int $originalPrice, ChannelInterface $channel): void
|
||||
{
|
||||
$this->client->addRequestData('channelPricings', [
|
||||
$channel->getCode() => [
|
||||
'price' => $originalPrice,
|
||||
'channelCode' => $channel->getCode(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that it has been successfully created
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ final class Resources
|
|||
|
||||
public const CATALOG_PROMOTIONS = 'catalog-promotions';
|
||||
|
||||
public const CHANNEL_PRICING_LOG_ENTRY = 'channel-pricing-log-entries';
|
||||
|
||||
public const CHANNELS = 'channels';
|
||||
|
||||
public const CONTACT_REQUESTS = 'contact-requests';
|
||||
|
|
|
|||
|
|
@ -194,5 +194,11 @@
|
|||
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
|
||||
<argument>%sylius.security.new_api_route%</argument>
|
||||
</service>
|
||||
|
||||
<service id="Sylius\Behat\Context\Api\Admin\ChannelPricingLogEntryContext" public="true">
|
||||
<argument type="service" id="sylius.behat.api_platform_client.admin" />
|
||||
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
|
||||
<argument type="service" id="sylius.behat.shared_storage" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
|
|||
|
|
@ -32,8 +32,10 @@ default:
|
|||
- sylius.behat.context.setup.product
|
||||
- sylius.behat.context.setup.admin_api_security
|
||||
- sylius.behat.context.setup.taxonomy
|
||||
- Sylius\Behat\Context\Setup\CatalogPromotionContext
|
||||
|
||||
- sylius.behat.context.api.admin.managing_product_variants
|
||||
- Sylius\Behat\Context\Api\Admin\ChannelPricingLogEntryContext
|
||||
filters:
|
||||
tags: "@managing_product_variants&&@api"
|
||||
javascript: false
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue