mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
review fixes
This commit is contained in:
parent
f29d5af98e
commit
225ce2048d
9 changed files with 30 additions and 214 deletions
|
|
@ -1,156 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* 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\Tests\Api\Admin;
|
||||
|
||||
use Sylius\Component\Core\Model\PromotionInterface;
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Sylius\Tests\Api\Utils\AdminUserLoginTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class PromotionsTest extends JsonApiTestCase
|
||||
{
|
||||
use AdminUserLoginTrait;
|
||||
|
||||
/** @test */
|
||||
public function it_gets_promotion_coupons(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'promotion/promotion.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var PromotionInterface $promotion */
|
||||
$promotion = $fixtures['promotion_1_off'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: sprintf('/api/v2/admin/promotions/%s/coupons', $promotion->getCode()),
|
||||
server: $header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/promotion/get_promotion_coupons_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_promotion(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'promotion/promotion.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var PromotionInterface $promotion */
|
||||
$promotion = $fixtures['promotion_50_off'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'PUT',
|
||||
uri: sprintf('/api/v2/admin/promotions/%s', $promotion->getCode()),
|
||||
server: $header,
|
||||
content: json_encode([
|
||||
'name' => 'Christmas',
|
||||
'code' => 'new_code',
|
||||
'appliesToDiscounted' => true,
|
||||
'exclusive' => true,
|
||||
'usageLimit' => 11,
|
||||
'couponBased' => false,
|
||||
'rules' => [
|
||||
[
|
||||
'type' => CartQuantityRuleChecker::TYPE,
|
||||
'configuration' => [
|
||||
'count' => 1,
|
||||
],
|
||||
],
|
||||
],
|
||||
'actions' => [
|
||||
[
|
||||
'type' => FixedDiscountPromotionActionCommand::TYPE,
|
||||
'configuration' => [
|
||||
'WEB' => [
|
||||
'amount' => 2,
|
||||
],
|
||||
'MOBILE' => [
|
||||
'amount' => 2,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'channels' => [
|
||||
'/api/v2/admin/channels/MOBILE',
|
||||
],
|
||||
'translations' => ['en_US' => [
|
||||
'@id' => sprintf('/api/v2/admin/promotion-translations/%s', $promotion->getTranslation('en_US')->getId()),
|
||||
'label' => 'Christmas',
|
||||
]],
|
||||
], \JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/promotion/put_promotion_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_promotion_to_last_priority_when_priority_is_minus_one(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'promotion/promotion.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var PromotionInterface $promotion */
|
||||
$promotion = $fixtures['promotion_50_off'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'PUT',
|
||||
uri: sprintf('/api/v2/admin/promotions/%s', $promotion->getCode()),
|
||||
server: $header,
|
||||
content: json_encode([
|
||||
'priority' => -1,
|
||||
], \JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/promotion/put_promotion_to_last_priority_when_priority_is_minus_one_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_does_not_update_a_promotion_with_duplicate_locale_translation(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'promotion/promotion.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var PromotionInterface $promotion */
|
||||
$promotion = $fixtures['promotion_50_off'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'PUT',
|
||||
uri: sprintf('/api/v2/admin/promotions/%s', $promotion->getCode()),
|
||||
server: $header,
|
||||
content: json_encode([
|
||||
'translations' => ['en_US' => [
|
||||
'label' => 'Christmas',
|
||||
]],
|
||||
], \JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/promotion/put_promotion_with_duplicate_locale_translation',
|
||||
Response::HTTP_UNPROCESSABLE_ENTITY,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -243,7 +243,7 @@
|
|||
<argument type="service" id="sylius.behat.shared_storage" />
|
||||
</service>
|
||||
|
||||
<service id="Sylius\Behat\Context\Api\Admin\RemovingProductContext">
|
||||
<service id="sylius.behat.context.api.admin.removing_product" class="Sylius\Behat\Context\Api\Admin\RemovingProductContext">
|
||||
<argument type="service" id="sylius.behat.api_platform_client.admin" />
|
||||
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
|
||||
</service>
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ default:
|
|||
|
||||
- sylius.behat.context.api.admin.managing_promotions
|
||||
- sylius.behat.context.api.admin.response
|
||||
- sylius.behat.context.api.admin.removing_product
|
||||
- sylius.behat.context.api.admin.save
|
||||
- Sylius\Behat\Context\Api\Admin\RemovingProductContext
|
||||
- Sylius\Behat\Context\Api\Admin\RemovingTaxonContext
|
||||
- sylius.behat.context.api.admin.translation
|
||||
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* 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\Bundle\ApiBundle\Doctrine\ORM\QueryExtension\Common\Promotion;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
// TODO: refactor it to allow passing an array of classes //
|
||||
final readonly class NonArchivedExtension implements QueryCollectionExtensionInterface
|
||||
{
|
||||
public function __construct(private string $promotionClass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array-key, mixed> $context
|
||||
*/
|
||||
public function applyToCollection(
|
||||
QueryBuilder $queryBuilder,
|
||||
QueryNameGeneratorInterface $queryNameGenerator,
|
||||
string $resourceClass,
|
||||
?Operation $operation = null,
|
||||
array $context = [],
|
||||
): void {
|
||||
if ($this->promotionClass !== $resourceClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($context['filters']['exists']['archivedAt'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rootAlias = $queryBuilder->getRootAliases()[0];
|
||||
|
||||
$queryBuilder->andWhere($queryBuilder->expr()->isNull(sprintf('%s.archivedAt', $rootAlias)));
|
||||
}
|
||||
}
|
||||
|
|
@ -36,9 +36,9 @@
|
|||
</order>
|
||||
|
||||
<filters>
|
||||
<filter>sylius_api.promotion_coupon_search_filter</filter>
|
||||
<filter>sylius_api.promotion_order_filter</filter>
|
||||
<filter>sylius_api.exists_filter.archived_at</filter>
|
||||
<filter>sylius_api.search_filter.promotion</filter>
|
||||
<filter>sylius_api.order_filter.promotion</filter>
|
||||
<filter>sylius_api.exists_filter.promotion</filter>
|
||||
</filters>
|
||||
</operation>
|
||||
|
||||
|
|
|
|||
|
|
@ -314,14 +314,14 @@
|
|||
<!-- <tag name="api_platform.filter" />-->
|
||||
<!-- </service>-->
|
||||
|
||||
<service id="sylius_api.promotion_coupon_search_filter" parent="api_platform.doctrine.orm.search_filter" public="true">
|
||||
<service id="sylius_api.search_filter.promotion" parent="api_platform.doctrine.orm.search_filter" public="true">
|
||||
<argument type="collection">
|
||||
<argument key="coupons.code">exact</argument>
|
||||
</argument>
|
||||
<tag name="api_platform.filter" />
|
||||
</service>
|
||||
|
||||
<service id="sylius_api.promotion_order_filter" parent="api_platform.doctrine.orm.order_filter" public="true">
|
||||
<service id="sylius_api.order_filter.promotion" parent="api_platform.doctrine.orm.order_filter" public="true">
|
||||
<argument type="collection">
|
||||
<argument key="priority" />
|
||||
</argument>
|
||||
|
|
@ -408,7 +408,7 @@
|
|||
<tag name="api_platform.filter" />
|
||||
</service>
|
||||
|
||||
<service id="sylius_api.exists_filter.archived_at" parent="api_platform.doctrine.orm.exists_filter" public="true">
|
||||
<service id="sylius_api.exists_filter.promotion" parent="api_platform.doctrine.orm.exists_filter" public="true">
|
||||
<argument type="collection">
|
||||
<argument key="archivedAt" />
|
||||
</argument>
|
||||
|
|
|
|||
|
|
@ -72,6 +72,28 @@ final class PromotionsTest extends JsonApiTestCase
|
|||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_promotion_coupons(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'promotion/promotion.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var PromotionInterface $promotion */
|
||||
$promotion = $fixtures['promotion_1_off'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: sprintf('/api/v2/admin/promotions/%s/coupons', $promotion->getCode()),
|
||||
server: $header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/promotion/get_promotion_coupons_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_promotion(): void
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue