Skip to content

Commit

Permalink
API-1835: Support products-uuid endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
tomglvng authored Sep 29, 2022
1 parent 11c590f commit fb4deb7
Show file tree
Hide file tree
Showing 23 changed files with 1,198 additions and 31 deletions.
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions spec/AkeneoPimClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Akeneo\Pim\ApiClient\Api\ProductDraftApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductModelDraftApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductUuidApiInterface;
use Akeneo\Pim\ApiClient\Api\PublishedProductApiInterface;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityApiInterface;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeApiInterface;
Expand Down Expand Up @@ -79,6 +80,7 @@ function let(
AssetAttributeApiInterface $assetAttributeApi,
AssetAttributeOptionApiInterface $assetAttributeOptionApi,
AssetMediaFileApiInterface $assetMediaFileApi,
ProductUuidApiInterface $productUuidApi,
AppCatalogApiInterface $appCatalogApi,
AppCatalogProductApiInterface $appCatalogProductApi
) {
Expand Down Expand Up @@ -117,6 +119,7 @@ function let(
$assetAttributeApi,
$assetAttributeOptionApi,
$assetMediaFileApi,
$productUuidApi,
$appCatalogApi,
$appCatalogProductApi
);
Expand Down Expand Up @@ -292,6 +295,11 @@ function it_gets_asset_media_file_api($assetMediaFileApi)
$this->getAssetMediaFileApi()->shouldReturn($assetMediaFileApi);
}

function it_gets_product_uuid_api(ProductUuidApiInterface $productUuidApi)
{
$this->getProductUuidApi()->shouldReturn($productUuidApi);
}

function it_gets_app_catalog_api(AppCatalogApiInterface $appCatalogApi)
{
$this->getAppCatalogApi()->shouldReturn($appCatalogApi);
Expand Down
221 changes: 221 additions & 0 deletions spec/Api/ProductUuidApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
<?php

namespace spec\Akeneo\Pim\ApiClient\Api;

use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceListInterface;
use Akeneo\Pim\ApiClient\Api\ProductUuidApi;
use Akeneo\Pim\ApiClient\Api\ProductUuidApiInterface;
use Akeneo\Pim\ApiClient\Client\HttpClient;
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
use Akeneo\Pim\ApiClient\Exception\InvalidArgumentException;
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponse;
use PhpSpec\ObjectBehavior;

/**
* @copyright 2022 Akeneo SAS (https://www.akeneo.com)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class ProductUuidApiSpec extends ObjectBehavior
{
function let(
ResourceClientInterface $resourceClient,
PageFactoryInterface $pageFactory,
ResourceCursorFactoryInterface $cursorFactory
) {
$this->beConstructedWith($resourceClient, $pageFactory, $cursorFactory);
}

function it_is_initializable()
{
$this->shouldHaveType(ProductUuidApi::class);
$this->shouldImplement(ProductUuidApiInterface::class);
$this->shouldImplement(ListableResourceInterface::class);
$this->shouldImplement(UpsertableResourceListInterface::class);
}

function it_returns_a_product(ResourceClientInterface $resourceClient)
{
$uuid = '12951d98-210e-4bRC-ab18-7fdgf1bd14f3';
$product = [
'uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3',
'identifier' => 'foo',
'family' => 'tshirts',
'enabled' => true,
'categories' => [
'bar',
],
];

$resourceClient
->getResource(ProductUuidApi::PRODUCT_UUID_URI, [$uuid], [])
->willReturn($product);

$this->get($uuid)->shouldReturn($product);
}

function it_returns_a_product_with_query_parameters(ResourceClientInterface $resourceClient)
{
$uuid = '12951d98-210e-4bRC-ab18-7fdgf1bd14f3';
$product = [
'uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3',
'identifier' => 'foo',
'family' => 'tshirts',
'enabled' => true,
'categories' => [
'bar',
],
];

$resourceClient
->getResource(ProductUuidApi::PRODUCT_UUID_URI, [$uuid], ['with_attribute_options' => true])
->willReturn($product);

$this->get($uuid, ['with_attribute_options' => true])->shouldReturn($product);
}

function it_returns_a_list_of_products_with_default_parameters(
ResourceClientInterface $resourceClient,
PageFactoryInterface $pageFactory,
PageInterface $page
) {
$resourceClient
->getResources(ProductUuidApi::PRODUCTS_UUID_URI, [], 100, false, [])
->willReturn([]);

$pageFactory->createPage([])->willReturn($page);

$this->listPerPage()->shouldReturn($page);
}


function it_returns_a_list_of_products_with_limit_and_count(
ResourceClientInterface $resourceClient,
PageFactoryInterface $pageFactory,
PageInterface $page
) {
$resourceClient
->getResources(ProductUuidApi::PRODUCTS_UUID_URI, [], 10, true, [])
->willReturn([]);

$pageFactory->createPage([])->willReturn($page);

$this->listPerPage(10, true)->shouldReturn($page);
}

function it_returns_a_cursor_on_the_list_of_products(
ResourceClientInterface $resourceClient,
PageFactoryInterface $pageFactory,
ResourceCursorFactoryInterface $cursorFactory,
PageInterface $page,
ResourceCursorInterface $cursor
) {
$resourceClient
->getResources(ProductUuidApi::PRODUCTS_UUID_URI, [], 10, false, ['pagination_type' => 'search_after'])
->willReturn([]);

$pageFactory->createPage([])->willReturn($page);

$cursorFactory->createCursor(10, $page)->willReturn($cursor);

$this->all(10, [])->shouldReturn($cursor);
}

function it_returns_a_list_of_products_with_additional_query_parameters(
ResourceClientInterface $resourceClient,
PageFactoryInterface $pageFactory,
PageInterface $page
) {
$resourceClient
->getResources(ProductUuidApi::PRODUCTS_UUID_URI, [], 100, false, ['foo' => 'bar'])
->willReturn([]);

$pageFactory->createPage([])->willReturn($page);

$this->listPerPage(100, false, ['foo' => 'bar'])->shouldReturn($page);
}

function it_creates_a_product(ResourceClientInterface $resourceClient)
{
$resourceClient
->createResource(
ProductUuidApi::PRODUCTS_UUID_URI,
[],
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3', 'family' => 'bar']
)
->willReturn(HttpClient::HTTP_CREATED);

$this->create('12951d98-210e-4bRC-ab18-7fdgf1bd14f3', ['family' => 'bar'])->shouldReturn(
HttpClient::HTTP_CREATED
);
}

function it_throws_an_exception_if_identifier_is_provided_in_data_when_creating_a_product()
{
$this
->shouldThrow(
new InvalidArgumentException('The parameter "uuid" should not be defined in the data parameter')
)
->during(
'create',
[
'12951d98-210e-4bRC-ab18-7fdgf1bd14f3',
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3', 'family' => 'bar'],
]
);
}

function it_upserts_a_product(ResourceClientInterface $resourceClient)
{
$resourceClient
->upsertResource(
ProductUuidApi::PRODUCT_UUID_URI,
['12951d98-210e-4bRC-ab18-7fdgf1bd14f3'],
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3', 'identifier' => 'foo', 'family' => 'bar']
)
->willReturn(HttpClient::HTTP_NO_CONTENT);

$this->upsert(
'12951d98-210e-4bRC-ab18-7fdgf1bd14f3',
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3', 'identifier' => 'foo', 'family' => 'bar']
)
->shouldReturn(HttpClient::HTTP_NO_CONTENT);
}

function it_deletes_a_product(ResourceClientInterface $resourceClient)
{
$resourceClient
->deleteResource(ProductUuidApi::PRODUCT_UUID_URI, ['12951d98-210e-4bRC-ab18-7fdgf1bd14f3'])
->willReturn(HttpClient::HTTP_NO_CONTENT);

$this->delete('12951d98-210e-4bRC-ab18-7fdgf1bd14f3')->shouldReturn(HttpClient::HTTP_NO_CONTENT);
}

function it_upserts_a_list_of_products(
ResourceClientInterface $resourceClient,
UpsertResourceListResponse $response
) {
$resourceClient
->upsertStreamResourceList(
ProductUuidApi::PRODUCTS_UUID_URI,
[],
[
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'],
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f4'],
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f5'],
]
)
->willReturn($response);

$this
->upsertList([
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'],
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f4'],
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f5'],
])->shouldReturn($response);
}
}
13 changes: 13 additions & 0 deletions src/AkeneoPimClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Akeneo\Pim\ApiClient\Api\ProductDraftApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductModelDraftApiInterface;
use Akeneo\Pim\ApiClient\Api\ProductUuidApiInterface;
use Akeneo\Pim\ApiClient\Api\PublishedProductApiInterface;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityApiInterface;
use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeApiInterface;
Expand Down Expand Up @@ -85,6 +86,8 @@ class AkeneoPimClient implements AkeneoPimClientInterface
private AppCatalogApiInterface $appCatalogApi;
private AppCatalogProductApiInterface $appCatalogProductApi;

private ProductUuidApiInterface $productUuidApi;

public function __construct(
Authentication $authentication,
ProductApiInterface $productApi,
Expand Down Expand Up @@ -120,6 +123,7 @@ public function __construct(
AssetAttributeApiInterface $assetAttributeApi,
AssetAttributeOptionApiInterface $assetAttributeOptionApi,
AssetMediaFileApiInterface $assetMediaFileApi,
ProductUuidApiInterface $productUuidApi,
AppCatalogApiInterface $appCatalogApi,
AppCatalogProductApiInterface $appCatalogProductApi
) {
Expand Down Expand Up @@ -157,6 +161,7 @@ public function __construct(
$this->assetAttributeApi = $assetAttributeApi;
$this->assetAttributeOptionApi = $assetAttributeOptionApi;
$this->assetMediaFileApi = $assetMediaFileApi;
$this->productUuidApi = $productUuidApi;
$this->appCatalogApi = $appCatalogApi;
$this->appCatalogProductApi = $appCatalogProductApi;
}
Expand Down Expand Up @@ -441,6 +446,14 @@ public function getAssetMediaFileApi(): AssetMediaFileApiInterface
return $this->assetMediaFileApi;
}

/**
* {@inheritDoc}
*/
public function getProductUuidApi(): ProductUuidApiInterface
{
return $this->productUuidApi;
}

/**
* {@inheritDoc}
*/
Expand Down
Loading

0 comments on commit fb4deb7

Please sign in to comment.