Skip to content

Commit fb4deb7

Browse files
authored
API-1835: Support products-uuid endpoints
1 parent 11c590f commit fb4deb7

23 files changed

+1198
-31
lines changed

composer.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/AkeneoPimClientSpec.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Akeneo\Pim\ApiClient\Api\ProductDraftApiInterface;
3434
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
3535
use Akeneo\Pim\ApiClient\Api\ProductModelDraftApiInterface;
36+
use Akeneo\Pim\ApiClient\Api\ProductUuidApiInterface;
3637
use Akeneo\Pim\ApiClient\Api\PublishedProductApiInterface;
3738
use Akeneo\Pim\ApiClient\Api\ReferenceEntityApiInterface;
3839
use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeApiInterface;
@@ -79,6 +80,7 @@ function let(
7980
AssetAttributeApiInterface $assetAttributeApi,
8081
AssetAttributeOptionApiInterface $assetAttributeOptionApi,
8182
AssetMediaFileApiInterface $assetMediaFileApi,
83+
ProductUuidApiInterface $productUuidApi,
8284
AppCatalogApiInterface $appCatalogApi,
8385
AppCatalogProductApiInterface $appCatalogProductApi
8486
) {
@@ -117,6 +119,7 @@ function let(
117119
$assetAttributeApi,
118120
$assetAttributeOptionApi,
119121
$assetMediaFileApi,
122+
$productUuidApi,
120123
$appCatalogApi,
121124
$appCatalogProductApi
122125
);
@@ -292,6 +295,11 @@ function it_gets_asset_media_file_api($assetMediaFileApi)
292295
$this->getAssetMediaFileApi()->shouldReturn($assetMediaFileApi);
293296
}
294297

298+
function it_gets_product_uuid_api(ProductUuidApiInterface $productUuidApi)
299+
{
300+
$this->getProductUuidApi()->shouldReturn($productUuidApi);
301+
}
302+
295303
function it_gets_app_catalog_api(AppCatalogApiInterface $appCatalogApi)
296304
{
297305
$this->getAppCatalogApi()->shouldReturn($appCatalogApi);

spec/Api/ProductUuidApiSpec.php

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
<?php
2+
3+
namespace spec\Akeneo\Pim\ApiClient\Api;
4+
5+
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
6+
use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceListInterface;
7+
use Akeneo\Pim\ApiClient\Api\ProductUuidApi;
8+
use Akeneo\Pim\ApiClient\Api\ProductUuidApiInterface;
9+
use Akeneo\Pim\ApiClient\Client\HttpClient;
10+
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
11+
use Akeneo\Pim\ApiClient\Exception\InvalidArgumentException;
12+
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface;
13+
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
14+
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
15+
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
16+
use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponse;
17+
use PhpSpec\ObjectBehavior;
18+
19+
/**
20+
* @copyright 2022 Akeneo SAS (https://www.akeneo.com)
21+
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
22+
*/
23+
class ProductUuidApiSpec extends ObjectBehavior
24+
{
25+
function let(
26+
ResourceClientInterface $resourceClient,
27+
PageFactoryInterface $pageFactory,
28+
ResourceCursorFactoryInterface $cursorFactory
29+
) {
30+
$this->beConstructedWith($resourceClient, $pageFactory, $cursorFactory);
31+
}
32+
33+
function it_is_initializable()
34+
{
35+
$this->shouldHaveType(ProductUuidApi::class);
36+
$this->shouldImplement(ProductUuidApiInterface::class);
37+
$this->shouldImplement(ListableResourceInterface::class);
38+
$this->shouldImplement(UpsertableResourceListInterface::class);
39+
}
40+
41+
function it_returns_a_product(ResourceClientInterface $resourceClient)
42+
{
43+
$uuid = '12951d98-210e-4bRC-ab18-7fdgf1bd14f3';
44+
$product = [
45+
'uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3',
46+
'identifier' => 'foo',
47+
'family' => 'tshirts',
48+
'enabled' => true,
49+
'categories' => [
50+
'bar',
51+
],
52+
];
53+
54+
$resourceClient
55+
->getResource(ProductUuidApi::PRODUCT_UUID_URI, [$uuid], [])
56+
->willReturn($product);
57+
58+
$this->get($uuid)->shouldReturn($product);
59+
}
60+
61+
function it_returns_a_product_with_query_parameters(ResourceClientInterface $resourceClient)
62+
{
63+
$uuid = '12951d98-210e-4bRC-ab18-7fdgf1bd14f3';
64+
$product = [
65+
'uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3',
66+
'identifier' => 'foo',
67+
'family' => 'tshirts',
68+
'enabled' => true,
69+
'categories' => [
70+
'bar',
71+
],
72+
];
73+
74+
$resourceClient
75+
->getResource(ProductUuidApi::PRODUCT_UUID_URI, [$uuid], ['with_attribute_options' => true])
76+
->willReturn($product);
77+
78+
$this->get($uuid, ['with_attribute_options' => true])->shouldReturn($product);
79+
}
80+
81+
function it_returns_a_list_of_products_with_default_parameters(
82+
ResourceClientInterface $resourceClient,
83+
PageFactoryInterface $pageFactory,
84+
PageInterface $page
85+
) {
86+
$resourceClient
87+
->getResources(ProductUuidApi::PRODUCTS_UUID_URI, [], 100, false, [])
88+
->willReturn([]);
89+
90+
$pageFactory->createPage([])->willReturn($page);
91+
92+
$this->listPerPage()->shouldReturn($page);
93+
}
94+
95+
96+
function it_returns_a_list_of_products_with_limit_and_count(
97+
ResourceClientInterface $resourceClient,
98+
PageFactoryInterface $pageFactory,
99+
PageInterface $page
100+
) {
101+
$resourceClient
102+
->getResources(ProductUuidApi::PRODUCTS_UUID_URI, [], 10, true, [])
103+
->willReturn([]);
104+
105+
$pageFactory->createPage([])->willReturn($page);
106+
107+
$this->listPerPage(10, true)->shouldReturn($page);
108+
}
109+
110+
function it_returns_a_cursor_on_the_list_of_products(
111+
ResourceClientInterface $resourceClient,
112+
PageFactoryInterface $pageFactory,
113+
ResourceCursorFactoryInterface $cursorFactory,
114+
PageInterface $page,
115+
ResourceCursorInterface $cursor
116+
) {
117+
$resourceClient
118+
->getResources(ProductUuidApi::PRODUCTS_UUID_URI, [], 10, false, ['pagination_type' => 'search_after'])
119+
->willReturn([]);
120+
121+
$pageFactory->createPage([])->willReturn($page);
122+
123+
$cursorFactory->createCursor(10, $page)->willReturn($cursor);
124+
125+
$this->all(10, [])->shouldReturn($cursor);
126+
}
127+
128+
function it_returns_a_list_of_products_with_additional_query_parameters(
129+
ResourceClientInterface $resourceClient,
130+
PageFactoryInterface $pageFactory,
131+
PageInterface $page
132+
) {
133+
$resourceClient
134+
->getResources(ProductUuidApi::PRODUCTS_UUID_URI, [], 100, false, ['foo' => 'bar'])
135+
->willReturn([]);
136+
137+
$pageFactory->createPage([])->willReturn($page);
138+
139+
$this->listPerPage(100, false, ['foo' => 'bar'])->shouldReturn($page);
140+
}
141+
142+
function it_creates_a_product(ResourceClientInterface $resourceClient)
143+
{
144+
$resourceClient
145+
->createResource(
146+
ProductUuidApi::PRODUCTS_UUID_URI,
147+
[],
148+
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3', 'family' => 'bar']
149+
)
150+
->willReturn(HttpClient::HTTP_CREATED);
151+
152+
$this->create('12951d98-210e-4bRC-ab18-7fdgf1bd14f3', ['family' => 'bar'])->shouldReturn(
153+
HttpClient::HTTP_CREATED
154+
);
155+
}
156+
157+
function it_throws_an_exception_if_identifier_is_provided_in_data_when_creating_a_product()
158+
{
159+
$this
160+
->shouldThrow(
161+
new InvalidArgumentException('The parameter "uuid" should not be defined in the data parameter')
162+
)
163+
->during(
164+
'create',
165+
[
166+
'12951d98-210e-4bRC-ab18-7fdgf1bd14f3',
167+
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3', 'family' => 'bar'],
168+
]
169+
);
170+
}
171+
172+
function it_upserts_a_product(ResourceClientInterface $resourceClient)
173+
{
174+
$resourceClient
175+
->upsertResource(
176+
ProductUuidApi::PRODUCT_UUID_URI,
177+
['12951d98-210e-4bRC-ab18-7fdgf1bd14f3'],
178+
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3', 'identifier' => 'foo', 'family' => 'bar']
179+
)
180+
->willReturn(HttpClient::HTTP_NO_CONTENT);
181+
182+
$this->upsert(
183+
'12951d98-210e-4bRC-ab18-7fdgf1bd14f3',
184+
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3', 'identifier' => 'foo', 'family' => 'bar']
185+
)
186+
->shouldReturn(HttpClient::HTTP_NO_CONTENT);
187+
}
188+
189+
function it_deletes_a_product(ResourceClientInterface $resourceClient)
190+
{
191+
$resourceClient
192+
->deleteResource(ProductUuidApi::PRODUCT_UUID_URI, ['12951d98-210e-4bRC-ab18-7fdgf1bd14f3'])
193+
->willReturn(HttpClient::HTTP_NO_CONTENT);
194+
195+
$this->delete('12951d98-210e-4bRC-ab18-7fdgf1bd14f3')->shouldReturn(HttpClient::HTTP_NO_CONTENT);
196+
}
197+
198+
function it_upserts_a_list_of_products(
199+
ResourceClientInterface $resourceClient,
200+
UpsertResourceListResponse $response
201+
) {
202+
$resourceClient
203+
->upsertStreamResourceList(
204+
ProductUuidApi::PRODUCTS_UUID_URI,
205+
[],
206+
[
207+
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'],
208+
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f4'],
209+
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f5'],
210+
]
211+
)
212+
->willReturn($response);
213+
214+
$this
215+
->upsertList([
216+
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'],
217+
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f4'],
218+
['uuid' => '12951d98-210e-4bRC-ab18-7fdgf1bd14f5'],
219+
])->shouldReturn($response);
220+
}
221+
}

src/AkeneoPimClient.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Akeneo\Pim\ApiClient\Api\ProductDraftApiInterface;
3232
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
3333
use Akeneo\Pim\ApiClient\Api\ProductModelDraftApiInterface;
34+
use Akeneo\Pim\ApiClient\Api\ProductUuidApiInterface;
3435
use Akeneo\Pim\ApiClient\Api\PublishedProductApiInterface;
3536
use Akeneo\Pim\ApiClient\Api\ReferenceEntityApiInterface;
3637
use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeApiInterface;
@@ -85,6 +86,8 @@ class AkeneoPimClient implements AkeneoPimClientInterface
8586
private AppCatalogApiInterface $appCatalogApi;
8687
private AppCatalogProductApiInterface $appCatalogProductApi;
8788

89+
private ProductUuidApiInterface $productUuidApi;
90+
8891
public function __construct(
8992
Authentication $authentication,
9093
ProductApiInterface $productApi,
@@ -120,6 +123,7 @@ public function __construct(
120123
AssetAttributeApiInterface $assetAttributeApi,
121124
AssetAttributeOptionApiInterface $assetAttributeOptionApi,
122125
AssetMediaFileApiInterface $assetMediaFileApi,
126+
ProductUuidApiInterface $productUuidApi,
123127
AppCatalogApiInterface $appCatalogApi,
124128
AppCatalogProductApiInterface $appCatalogProductApi
125129
) {
@@ -157,6 +161,7 @@ public function __construct(
157161
$this->assetAttributeApi = $assetAttributeApi;
158162
$this->assetAttributeOptionApi = $assetAttributeOptionApi;
159163
$this->assetMediaFileApi = $assetMediaFileApi;
164+
$this->productUuidApi = $productUuidApi;
160165
$this->appCatalogApi = $appCatalogApi;
161166
$this->appCatalogProductApi = $appCatalogProductApi;
162167
}
@@ -441,6 +446,14 @@ public function getAssetMediaFileApi(): AssetMediaFileApiInterface
441446
return $this->assetMediaFileApi;
442447
}
443448

449+
/**
450+
* {@inheritDoc}
451+
*/
452+
public function getProductUuidApi(): ProductUuidApiInterface
453+
{
454+
return $this->productUuidApi;
455+
}
456+
444457
/**
445458
* {@inheritDoc}
446459
*/

0 commit comments

Comments
 (0)