mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[PriceHistory][Test] Add contract tests for ChannelPricingLogEntry entity
This commit is contained in:
parent
bbbebe52a5
commit
0cdf3cfa5f
6 changed files with 346 additions and 0 deletions
104
tests/Api/Admin/ChannelPricingLogEntryTest.php
Normal file
104
tests/Api/Admin/ChannelPricingLogEntryTest.php
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
<?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\Tests\Api\Admin;
|
||||||
|
|
||||||
|
use Sylius\Component\Core\Model\ChannelPricingInterface;
|
||||||
|
use Sylius\Component\Core\Model\ChannelPricingLogEntryInterface;
|
||||||
|
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||||
|
use Sylius\Tests\Api\JsonApiTestCase;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
final class ChannelPricingLogEntryTest extends JsonApiTestCase
|
||||||
|
{
|
||||||
|
/** @test */
|
||||||
|
public function it_denies_access_to_a_channel_pricing_log_entries_for_not_authenticated_user(): void
|
||||||
|
{
|
||||||
|
$this->loadFixturesFromFiles(['product/product_variant_with_lowest_price.yaml']);
|
||||||
|
|
||||||
|
$this->client->request(
|
||||||
|
method: 'GET',
|
||||||
|
uri: '/api/v2/admin/channel-pricing-log-entries',
|
||||||
|
server: $this->getUnloggedHeader(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $this->client->getResponse();
|
||||||
|
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_gets_single_channel_pricing_log_entry(): void
|
||||||
|
{
|
||||||
|
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'product/product_variant_with_lowest_price.yaml']);
|
||||||
|
|
||||||
|
/** @var ChannelPricingInterface $channelPricing */
|
||||||
|
$channelPricing = $fixtures['channel_pricing_product_variant_mug_blue_home'];
|
||||||
|
|
||||||
|
/** @var RepositoryInterface $channelPricingLogEntryRepository */
|
||||||
|
$channelPricingLogEntryRepository = $this->getContainer()->get('sylius.repository.channel_pricing_log_entry');
|
||||||
|
/** @var ChannelPricingLogEntryInterface $firstLogEntry */
|
||||||
|
$channelPricingLogEntry = $channelPricingLogEntryRepository->findOneBy(['channelPricing' => $channelPricing]);
|
||||||
|
|
||||||
|
$this->client->request(
|
||||||
|
method: 'GET',
|
||||||
|
uri: sprintf('/api/v2/admin/channel-pricing-log-entries/%d', $channelPricingLogEntry->getId()),
|
||||||
|
server: $this->getLoggedHeader(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertResponse(
|
||||||
|
$this->client->getResponse(),
|
||||||
|
'admin/get_channel_pricing_log_entry_response',
|
||||||
|
Response::HTTP_OK
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_gets_all_channel_pricing_log_entries(): void
|
||||||
|
{
|
||||||
|
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'product/product_variant_with_lowest_price.yaml']);
|
||||||
|
|
||||||
|
$this->client->request(
|
||||||
|
method: 'GET',
|
||||||
|
uri: '/api/v2/admin/channel-pricing-log-entries',
|
||||||
|
server: $this->getLoggedHeader(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertResponse(
|
||||||
|
$this->client->getResponse(),
|
||||||
|
'admin/get_channel_pricing_log_entries_response',
|
||||||
|
Response::HTTP_OK
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_gets_filtered_channel_pricing_log_entries(): void
|
||||||
|
{
|
||||||
|
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'product/product_variant_with_lowest_price.yaml']);
|
||||||
|
|
||||||
|
$uri = '/api/v2/admin/channel-pricing-log-entries';
|
||||||
|
$uri .= '?channelPricing.channelCode=' . $fixtures['channel_home']->getCode();
|
||||||
|
$uri .= '&channelPricing.productVariant.code=' . $fixtures['product_variant_mug_blue']->getCode();
|
||||||
|
|
||||||
|
$this->client->request(
|
||||||
|
method: 'GET',
|
||||||
|
uri: $uri,
|
||||||
|
server: $this->getLoggedHeader(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertResponse(
|
||||||
|
$this->client->getResponse(),
|
||||||
|
'admin/get_filtered_channel_pricing_log_entries_response',
|
||||||
|
Response::HTTP_OK
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
Sylius\Component\Core\Model\Channel:
|
||||||
|
channel_home:
|
||||||
|
code: 'HOME'
|
||||||
|
name: 'Home Channel'
|
||||||
|
hostname: 'home.localhost'
|
||||||
|
description: 'Lorem ipsum'
|
||||||
|
baseCurrency: '@currency_usd'
|
||||||
|
defaultLocale: '@locale_en'
|
||||||
|
locales: ['@locale_en', '@locale_pl']
|
||||||
|
color: 'black'
|
||||||
|
enabled: true
|
||||||
|
taxCalculationStrategy: 'order_items_based'
|
||||||
|
channel_fashion:
|
||||||
|
code: 'FASHION'
|
||||||
|
name: 'Fashion Channel'
|
||||||
|
hostname: 'fashion.localhost'
|
||||||
|
description: 'Lorem ipsum'
|
||||||
|
baseCurrency: '@currency_usd'
|
||||||
|
defaultLocale: '@locale_en'
|
||||||
|
locales: ['@locale_en', '@locale_pl']
|
||||||
|
color: 'black'
|
||||||
|
enabled: true
|
||||||
|
taxCalculationStrategy: 'order_items_based'
|
||||||
|
|
||||||
|
Sylius\Component\Currency\Model\Currency:
|
||||||
|
currency_usd:
|
||||||
|
code: 'USD'
|
||||||
|
|
||||||
|
Sylius\Component\Locale\Model\Locale:
|
||||||
|
locale_en:
|
||||||
|
code: 'en_US'
|
||||||
|
locale_pl:
|
||||||
|
code: 'pl_PL'
|
||||||
|
locale_de:
|
||||||
|
code: 'de_DE'
|
||||||
|
|
||||||
|
Sylius\Component\Core\Model\Product:
|
||||||
|
product_mug:
|
||||||
|
code: 'MUG'
|
||||||
|
channels: ['@channel_home', '@channel_fashion']
|
||||||
|
currentLocale: 'en_US'
|
||||||
|
translations:
|
||||||
|
en_US: '@product_translation_mug'
|
||||||
|
|
||||||
|
Sylius\Component\Core\Model\ProductTranslation:
|
||||||
|
product_translation_mug:
|
||||||
|
slug: 'mug'
|
||||||
|
locale: 'en_US'
|
||||||
|
name: 'Mug'
|
||||||
|
description: '<paragraph(2)>'
|
||||||
|
translatable: '@product_mug'
|
||||||
|
|
||||||
|
Sylius\Component\Core\Model\ProductVariant:
|
||||||
|
product_variant_mug_blue:
|
||||||
|
code: 'MUG_BLUE'
|
||||||
|
product: '@product_mug'
|
||||||
|
currentLocale: 'en_US'
|
||||||
|
translations:
|
||||||
|
en_US: '@product_variant_translation_mug_blue'
|
||||||
|
channelPricings:
|
||||||
|
HOME: '@channel_pricing_product_variant_mug_blue_home'
|
||||||
|
FASHION: '@channel_pricing_product_variant_mug_blue_fashion'
|
||||||
|
|
||||||
|
product_variant_mug_red:
|
||||||
|
code: 'MUG_RED'
|
||||||
|
product: '@product_mug'
|
||||||
|
currentLocale: 'en_US'
|
||||||
|
translations:
|
||||||
|
en_US: '@product_variant_translation_mug_red'
|
||||||
|
channelPricings:
|
||||||
|
HOME: '@channel_pricing_product_variant_mug_red_home'
|
||||||
|
FASHION: '@channel_pricing_product_variant_mug_red_fashion'
|
||||||
|
|
||||||
|
Sylius\Component\Product\Model\ProductVariantTranslation:
|
||||||
|
product_variant_translation_mug_blue:
|
||||||
|
locale: 'en_US'
|
||||||
|
name: 'Blue Mug'
|
||||||
|
translatable: '@product_variant_mug_blue'
|
||||||
|
product_variant_translation_mug_red:
|
||||||
|
locale: 'en_US'
|
||||||
|
name: 'Red Mug'
|
||||||
|
translatable: '@product_variant_mug_red'
|
||||||
|
|
||||||
|
Sylius\Component\Core\Model\ChannelPricing:
|
||||||
|
channel_pricing_product_variant_mug_blue_home:
|
||||||
|
channelCode: 'HOME'
|
||||||
|
price: 1000
|
||||||
|
originalPrice: 2000
|
||||||
|
lowestPriceBeforeDiscount: 2100
|
||||||
|
channel_pricing_product_variant_mug_blue_fashion:
|
||||||
|
channelCode: 'FASHION'
|
||||||
|
price: 2000
|
||||||
|
channel_pricing_product_variant_mug_red_home:
|
||||||
|
channelCode: 'HOME'
|
||||||
|
price: 3000
|
||||||
|
channel_pricing_product_variant_mug_red_fashion:
|
||||||
|
channelCode: 'FASHION'
|
||||||
|
price: 3000
|
||||||
|
|
@ -14,9 +14,12 @@ declare(strict_types=1);
|
||||||
namespace Sylius\Tests\Api;
|
namespace Sylius\Tests\Api;
|
||||||
|
|
||||||
use ApiTestCase\JsonApiTestCase as BaseJsonApiTestCase;
|
use ApiTestCase\JsonApiTestCase as BaseJsonApiTestCase;
|
||||||
|
use Sylius\Tests\Api\Utils\AdminUserLoginTrait;
|
||||||
|
|
||||||
abstract class JsonApiTestCase extends BaseJsonApiTestCase
|
abstract class JsonApiTestCase extends BaseJsonApiTestCase
|
||||||
{
|
{
|
||||||
|
use AdminUserLoginTrait;
|
||||||
|
|
||||||
public const CONTENT_TYPE_HEADER = ['CONTENT_TYPE' => 'application/ld+json', 'HTTP_ACCEPT' => 'application/ld+json'];
|
public const CONTENT_TYPE_HEADER = ['CONTENT_TYPE' => 'application/ld+json', 'HTTP_ACCEPT' => 'application/ld+json'];
|
||||||
|
|
||||||
public const PATCH_CONTENT_TYPE_HEADER = ['CONTENT_TYPE' => 'application/merge-patch+json', 'HTTP_ACCEPT' => 'application/ld+json'];
|
public const PATCH_CONTENT_TYPE_HEADER = ['CONTENT_TYPE' => 'application/merge-patch+json', 'HTTP_ACCEPT' => 'application/ld+json'];
|
||||||
|
|
@ -37,4 +40,14 @@ abstract class JsonApiTestCase extends BaseJsonApiTestCase
|
||||||
|
|
||||||
return parent::get($id);
|
return parent::get($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getUnloggedHeader(): array
|
||||||
|
{
|
||||||
|
return self::CONTENT_TYPE_HEADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getLoggedHeader(): array
|
||||||
|
{
|
||||||
|
return array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
{
|
||||||
|
"@context": "\/api\/v2\/contexts\/ChannelPricingLogEntry",
|
||||||
|
"@id": "\/api\/v2\/admin\/channel-pricing-log-entries",
|
||||||
|
"@type": "hydra:Collection",
|
||||||
|
"hydra:member": [
|
||||||
|
{
|
||||||
|
"@id": "\/api\/v2\/admin\/channel-pricing-log-entries\/@integer@",
|
||||||
|
"@type": "ChannelPricingLogEntry",
|
||||||
|
"channelPricing": "\/api\/v2\/admin\/channel-pricings\/@integer@",
|
||||||
|
"price": 3000,
|
||||||
|
"originalPrice": null,
|
||||||
|
"loggedAt": "@date@"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@id": "\/api\/v2\/admin\/channel-pricing-log-entries\/@integer@",
|
||||||
|
"@type": "ChannelPricingLogEntry",
|
||||||
|
"channelPricing": "\/api\/v2\/admin\/channel-pricings\/@integer@",
|
||||||
|
"price": 1000,
|
||||||
|
"originalPrice": 2000,
|
||||||
|
"loggedAt": "@date@"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@id": "\/api\/v2\/admin\/channel-pricing-log-entries\/@integer@",
|
||||||
|
"@type": "ChannelPricingLogEntry",
|
||||||
|
"channelPricing": "\/api\/v2\/admin\/channel-pricings\/@integer@",
|
||||||
|
"price": 3000,
|
||||||
|
"originalPrice": null,
|
||||||
|
"loggedAt": "@date@"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@id": "\/api\/v2\/admin\/channel-pricing-log-entries\/@integer@",
|
||||||
|
"@type": "ChannelPricingLogEntry",
|
||||||
|
"channelPricing": "\/api\/v2\/admin\/channel-pricings\/@integer@",
|
||||||
|
"price": 2000,
|
||||||
|
"originalPrice": null,
|
||||||
|
"loggedAt": "@date@"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"hydra:totalItems": 4,
|
||||||
|
"hydra:search": {
|
||||||
|
"@type": "hydra:IriTemplate",
|
||||||
|
"hydra:template": "\/api\/v2\/admin\/channel-pricing-log-entries{?channelPricing.channelCode,channelPricing.channelCode[],channelPricing.productVariant.code,channelPricing.productVariant.code[]}",
|
||||||
|
"hydra:variableRepresentation": "BasicRepresentation",
|
||||||
|
"hydra:mapping": [
|
||||||
|
{
|
||||||
|
"@type": "IriTemplateMapping",
|
||||||
|
"variable": "channelPricing.channelCode",
|
||||||
|
"property": "channelPricing.channelCode",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@type": "IriTemplateMapping",
|
||||||
|
"variable": "channelPricing.channelCode[]",
|
||||||
|
"property": "channelPricing.channelCode",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@type": "IriTemplateMapping",
|
||||||
|
"variable": "channelPricing.productVariant.code",
|
||||||
|
"property": "channelPricing.productVariant.code",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@type": "IriTemplateMapping",
|
||||||
|
"variable": "channelPricing.productVariant.code[]",
|
||||||
|
"property": "channelPricing.productVariant.code",
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"@context": "\/api\/v2\/contexts\/ChannelPricingLogEntry",
|
||||||
|
"@id": "\/api\/v2\/admin\/channel-pricing-log-entries/@integer@",
|
||||||
|
"@type": "ChannelPricingLogEntry",
|
||||||
|
"channelPricing": "\/api\/v2\/admin\/channel-pricings\/@integer@",
|
||||||
|
"price": 1000,
|
||||||
|
"originalPrice": 2000,
|
||||||
|
"loggedAt": "@date@"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
{
|
||||||
|
"@context": "\/api\/v2\/contexts\/ChannelPricingLogEntry",
|
||||||
|
"@id": "\/api\/v2\/admin\/channel-pricing-log-entries",
|
||||||
|
"@type": "hydra:Collection",
|
||||||
|
"hydra:member": [
|
||||||
|
{
|
||||||
|
"@id": "\/api\/v2\/admin\/channel-pricing-log-entries\/@integer@",
|
||||||
|
"@type": "ChannelPricingLogEntry",
|
||||||
|
"channelPricing": "\/api\/v2\/admin\/channel-pricings\/@integer@",
|
||||||
|
"price": 1000,
|
||||||
|
"originalPrice": 2000,
|
||||||
|
"loggedAt": "@date@"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"hydra:totalItems": 1,
|
||||||
|
"hydra:view": {
|
||||||
|
"@id": @string@,
|
||||||
|
"@type": "hydra:PartialCollectionView"
|
||||||
|
},
|
||||||
|
"hydra:search": {
|
||||||
|
"@type": "hydra:IriTemplate",
|
||||||
|
"hydra:template": "\/api\/v2\/admin\/channel-pricing-log-entries{?channelPricing.channelCode,channelPricing.channelCode[],channelPricing.productVariant.code,channelPricing.productVariant.code[]}",
|
||||||
|
"hydra:variableRepresentation": "BasicRepresentation",
|
||||||
|
"hydra:mapping": [
|
||||||
|
{
|
||||||
|
"@type": "IriTemplateMapping",
|
||||||
|
"variable": "channelPricing.channelCode",
|
||||||
|
"property": "channelPricing.channelCode",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@type": "IriTemplateMapping",
|
||||||
|
"variable": "channelPricing.channelCode[]",
|
||||||
|
"property": "channelPricing.channelCode",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@type": "IriTemplateMapping",
|
||||||
|
"variable": "channelPricing.productVariant.code",
|
||||||
|
"property": "channelPricing.productVariant.code",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@type": "IriTemplateMapping",
|
||||||
|
"variable": "channelPricing.productVariant.code[]",
|
||||||
|
"property": "channelPricing.productVariant.code",
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue