-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from akeneo/API-1835-bis
Add Product Draft UUID routes
- Loading branch information
Showing
14 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace spec\Akeneo\Pim\ApiClient\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Api\Operation\GettableResourceInterface; | ||
use Akeneo\Pim\ApiClient\Api\ProductDraftUuidApi; | ||
use Akeneo\Pim\ApiClient\Api\ProductDraftUuidApiInterface; | ||
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface; | ||
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface; | ||
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class ProductDraftUuidApiSpec extends ObjectBehavior | ||
{ | ||
function let( | ||
ResourceClientInterface $resourceClient, | ||
PageFactoryInterface $pageFactory, | ||
ResourceCursorFactoryInterface $cursorFactory | ||
) { | ||
$this->beConstructedWith($resourceClient, $pageFactory, $cursorFactory); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(ProductDraftUuidApi::class); | ||
$this->shouldImplement(ProductDraftUuidApiInterface::class); | ||
$this->shouldImplement(GettableResourceInterface::class); | ||
} | ||
|
||
function it_gets_a_product_draft($resourceClient) | ||
{ | ||
$draft = [ | ||
'uuid' => '944ca210-d8e0-4c57-9529-741e17e95c8d', | ||
'family' => 'bar', | ||
'parent' => null, | ||
'groups' => [], | ||
'categories' => [], | ||
'enabled' => true, | ||
'values' => [], | ||
'created' => 'this is a date formatted to ISO-8601', | ||
'updated' => 'this is a date formatted to ISO-8601', | ||
'associations' => [], | ||
'metadata' => [ | ||
'workflow_status' => 'draft_in_progress', | ||
], | ||
]; | ||
|
||
$resourceClient->getResource(ProductDraftUuidApi::PRODUCT_DRAFT_UUID_URI, ['944ca210-d8e0-4c57-9529-741e17e95c8d'])->willReturn($draft); | ||
|
||
$this->get('944ca210-d8e0-4c57-9529-741e17e95c8d')->shouldReturn($draft); | ||
} | ||
|
||
function it_submits_a_product_draft_for_approval($resourceClient) | ||
{ | ||
$resourceClient->createResource(ProductDraftUuidApi::PRODUCT_PROPOSAL_UUID_URI, ['944ca210-d8e0-4c57-9529-741e17e95c8d'])->willReturn(201); | ||
|
||
$this->submitForApproval('944ca210-d8e0-4c57-9529-741e17e95c8d')->shouldReturn(201); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akeneo\Pim\ApiClient\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface; | ||
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface; | ||
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface; | ||
|
||
/** | ||
* @copyright 2022 Akeneo SAS (https://www.akeneo.com) | ||
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
class ProductDraftUuidApi implements ProductDraftUuidApiInterface | ||
{ | ||
public const PRODUCT_DRAFT_UUID_URI = '/api/rest/v1/products-uuid/%s/draft'; | ||
public const PRODUCT_PROPOSAL_UUID_URI = '/api/rest/v1/products-uuid/%s/proposal'; | ||
|
||
protected ResourceClientInterface $resourceClient; | ||
protected PageFactoryInterface $pageFactory; | ||
protected ResourceCursorFactoryInterface $cursorFactory; | ||
|
||
public function __construct( | ||
ResourceClientInterface $resourceClient, | ||
PageFactoryInterface $pageFactory, | ||
ResourceCursorFactoryInterface $cursorFactory | ||
) { | ||
$this->resourceClient = $resourceClient; | ||
$this->pageFactory = $pageFactory; | ||
$this->cursorFactory = $cursorFactory; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get(string $uuid): array | ||
{ | ||
return $this->resourceClient->getResource(static::PRODUCT_DRAFT_UUID_URI, [$uuid]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function submitForApproval(string $uuid): int | ||
{ | ||
return $this->resourceClient->createResource(static::PRODUCT_PROPOSAL_UUID_URI, [$uuid]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akeneo\Pim\ApiClient\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Api\Operation\GettableResourceInterface; | ||
|
||
/** | ||
* @copyright 2022 Akeneo SAS (https://www.akeneo.com) | ||
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
interface ProductDraftUuidApiInterface extends GettableResourceInterface | ||
{ | ||
/** | ||
* Submits a product draft for approval, by its uuid. | ||
*/ | ||
public function submitForApproval(string $uuid): int; | ||
} |
67 changes: 67 additions & 0 deletions
67
tests/Api/ProductDraftUuid/GetProductDraftUuidIntegration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Akeneo\Pim\ApiClient\tests\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Api\ProductDraftUuidApi; | ||
use Akeneo\Pim\ApiClient\Client\HttpClient; | ||
use donatj\MockWebServer\RequestInfo; | ||
use donatj\MockWebServer\Response; | ||
use donatj\MockWebServer\ResponseStack; | ||
use PHPUnit\Framework\Assert; | ||
|
||
/** | ||
* @copyright 2022 Akeneo SAS (https://www.akeneo.com) | ||
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
class GetProductDraftUuidIntegration extends ApiTestCase | ||
{ | ||
public function test_get_product() | ||
{ | ||
$this->server->setResponseOfPath( | ||
'/'.sprintf(ProductDraftUuidApi::PRODUCT_DRAFT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), | ||
new ResponseStack( | ||
new Response($this->getProductDraft(), [], HttpClient::HTTP_OK) | ||
) | ||
); | ||
|
||
$api = $this->createClientByPassword()->getProductDraftUuidApi(); | ||
$product = $api->get('12951d98-210e-4bRC-ab18-7fdgf1bd14f3'); | ||
|
||
Assert::assertSame('GET', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]); | ||
Assert::assertEquals($product, json_decode($this->getProductDraft(), true)); | ||
} | ||
|
||
public function test_get_unknown_product() | ||
{ | ||
$this->server->setResponseOfPath( | ||
'/'.sprintf(ProductDraftUuidApi::PRODUCT_DRAFT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), | ||
new ResponseStack( | ||
new Response('{"code": 404, "message":"Resource `12951d98-210e-4bRC-ab18-7fdgf1bd14f3` does not exist."}', [], 404) | ||
) | ||
); | ||
|
||
$this->expectException(\Akeneo\Pim\ApiClient\Exception\NotFoundHttpException::class); | ||
$this->expectExceptionMessage('Resource `12951d98-210e-4bRC-ab18-7fdgf1bd14f3` does not exist.'); | ||
|
||
$api = $this->createClientByPassword()->getProductDraftUuidApi(); | ||
$api->get('12951d98-210e-4bRC-ab18-7fdgf1bd14f3'); | ||
} | ||
|
||
private function getProductDraft(): string | ||
{ | ||
return <<<JSON | ||
[ | ||
{ | ||
"uuid" : "12951d98-210e-4bRC-ab18-7fdgf1bd14f3", | ||
"identifier" : "black_sneakers", | ||
"family" : "sneakers", | ||
"groups": [], | ||
"categories": ["summer_collection"], | ||
"values": [{ | ||
"color": {"locale": null, "scope": null, "data": "black"} | ||
}] | ||
} | ||
] | ||
JSON; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.