|
| 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 | +} |
0 commit comments