mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[ApiBundle] Add contract tests for ProductTaxon resource
This commit is contained in:
parent
4036f1f132
commit
e8f1a0a831
6 changed files with 242 additions and 0 deletions
135
tests/Api/Admin/ProductTaxonsTest.php
Normal file
135
tests/Api/Admin/ProductTaxonsTest.php
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
<?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\ProductInterface;
|
||||
use Sylius\Component\Core\Model\ProductTaxonInterface;
|
||||
use Sylius\Component\Core\Model\TaxonInterface;
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Sylius\Tests\Api\Utils\AdminUserLoginTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class ProductTaxonsTest extends JsonApiTestCase
|
||||
{
|
||||
use AdminUserLoginTrait;
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_product_taxon(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'product/product_taxon.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var ProductTaxonInterface $productTaxon */
|
||||
$productTaxon = $fixtures['product_mug_taxon_mugs'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: sprintf('/api/v2/admin/product-taxons/%s', $productTaxon->getId()),
|
||||
server: $header,
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/product_taxon/get_product_taxon_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_product_taxons(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'product/product_taxon.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
$this->client->request(method: 'GET', uri: '/api/v2/admin/product-taxons', server: $header);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/product_taxon/get_product_taxons_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_a_product_taxon(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'product/product_taxon.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var ProductInterface $product */
|
||||
$product = $fixtures['product_mug'];
|
||||
/** @var TaxonInterface $taxon */
|
||||
$taxon = $fixtures['taxon_caps'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'POST',
|
||||
uri: '/api/v2/admin/product-taxons',
|
||||
server: $header,
|
||||
content: json_encode([
|
||||
'product' => sprintf('/api/v2/admin/products/%s', $product->getCode()),
|
||||
'taxon' => sprintf('/api/v2/admin/taxons/%s', $taxon->getCode()),
|
||||
'position' => 10,
|
||||
], \JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/product_taxon/post_product_taxon_response',
|
||||
Response::HTTP_CREATED,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_product_taxon(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'product/product_taxon.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var ProductTaxonInterface $productTaxon */
|
||||
$productTaxon = $fixtures['product_cap_taxon_caps'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'PUT',
|
||||
uri: sprintf('/api/v2/admin/product-taxons/%s', $productTaxon->getId()),
|
||||
server: $header,
|
||||
content: json_encode([
|
||||
'position' => 1,
|
||||
], \JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponse(
|
||||
$this->client->getResponse(),
|
||||
'admin/product_taxon/put_product_taxon_response',
|
||||
Response::HTTP_OK,
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_deletes_a_product_taxon(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'product/product_taxon.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var ProductTaxonInterface $productTaxon */
|
||||
$productTaxon = $fixtures['product_cap_taxon_caps'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'DELETE',
|
||||
uri: sprintf('/api/v2/admin/product-taxons/%s', $productTaxon->getId()),
|
||||
server: $header,
|
||||
);
|
||||
|
||||
$this->assertResponseCode($this->client->getResponse(), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
25
tests/Api/DataFixtures/ORM/product/product_taxon.yaml
Normal file
25
tests/Api/DataFixtures/ORM/product/product_taxon.yaml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Sylius\Component\Core\Model\Product:
|
||||
product_mug:
|
||||
code: 'MUG'
|
||||
channels: ['@channel_web']
|
||||
currentLocale: 'en_US'
|
||||
product_cap:
|
||||
code: 'CAP'
|
||||
channels: ['@channel_web']
|
||||
currentLocale: 'en_US'
|
||||
|
||||
Sylius\Component\Core\Model\Taxon:
|
||||
taxon_mugs:
|
||||
code: 'MUGS'
|
||||
taxon_caps:
|
||||
code: 'CAPS'
|
||||
|
||||
Sylius\Component\Core\Model\ProductTaxon:
|
||||
product_mug_taxon_mugs:
|
||||
product: '@product_mug'
|
||||
taxon: '@taxon_mugs'
|
||||
position: 1
|
||||
product_cap_taxon_caps:
|
||||
product: '@product_cap'
|
||||
taxon: '@taxon_caps'
|
||||
position: 2
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ProductTaxon",
|
||||
"@id": "\/api\/v2\/admin\/product-taxons\/@integer@",
|
||||
"@type": "ProductTaxon",
|
||||
"id": @integer@,
|
||||
"product": "\/api\/v2\/admin\/products\/MUG",
|
||||
"taxon": "\/api\/v2\/admin\/taxons\/MUGS",
|
||||
"position": 1
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ProductTaxon",
|
||||
"@id": "\/api\/v2\/admin\/product-taxons",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/product-taxons\/@integer@",
|
||||
"@type": "ProductTaxon",
|
||||
"id": @integer@,
|
||||
"product": "\/api\/v2\/admin\/products\/MUG",
|
||||
"taxon": "\/api\/v2\/admin\/taxons\/MUGS",
|
||||
"position": 1
|
||||
},
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/product-taxons\/@integer@",
|
||||
"@type": "ProductTaxon",
|
||||
"id": @integer@,
|
||||
"product": "\/api\/v2\/admin\/products\/CAP",
|
||||
"taxon": "\/api\/v2\/admin\/taxons\/CAPS",
|
||||
"position": 2
|
||||
}
|
||||
],
|
||||
"hydra:totalItems": 2,
|
||||
"hydra:search": {
|
||||
"@type": "hydra:IriTemplate",
|
||||
"hydra:template": "\/api\/v2\/admin\/product-taxons{?product.code,product.code[],taxon.code,taxon.code[]}",
|
||||
"hydra:variableRepresentation": "BasicRepresentation",
|
||||
"hydra:mapping": [
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "product.code",
|
||||
"property": "product.code",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "product.code[]",
|
||||
"property": "product.code",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "taxon.code",
|
||||
"property": "taxon.code",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "taxon.code[]",
|
||||
"property": "taxon.code",
|
||||
"required": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ProductTaxon",
|
||||
"@id": "\/api\/v2\/admin\/product-taxons\/@integer@",
|
||||
"@type": "ProductTaxon",
|
||||
"id": @integer@,
|
||||
"product": "\/api\/v2\/admin\/products\/MUG",
|
||||
"taxon": "\/api\/v2\/admin\/taxons\/CAPS",
|
||||
"position": 10
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/ProductTaxon",
|
||||
"@id": "\/api\/v2\/admin\/product-taxons\/@integer@",
|
||||
"@type": "ProductTaxon",
|
||||
"id": @integer@,
|
||||
"product": "\/api\/v2\/admin\/products\/CAP",
|
||||
"taxon": "\/api\/v2\/admin\/taxons\/CAPS",
|
||||
"position": 1
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue