-
Notifications
You must be signed in to change notification settings - Fork 248
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 #136 from magento-engcom/source-item-webapi
Source item webapi
- Loading branch information
Showing
5 changed files
with
246 additions
and
11 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
app/code/Magento/InventoryApi/Test/Api/SourceItemRepository/GetListTest.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,90 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryApi\Test\Api\SourceItemRepository; | ||
|
||
use Magento\Framework\Api\SearchCriteria; | ||
use Magento\Framework\Api\SortOrder; | ||
use Magento\Framework\Webapi\Rest\Request; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\TestFramework\Assert\AssertArrayContains; | ||
use Magento\TestFramework\TestCase\WebapiAbstract; | ||
|
||
class GetListTest extends WebapiAbstract | ||
{ | ||
/**#@+ | ||
* Service constants | ||
*/ | ||
const RESOURCE_PATH = '/V1/inventory/source-item'; | ||
const SERVICE_NAME = 'inventoryApiSourceItemRepositoryV1'; | ||
/**#@-*/ | ||
|
||
/** | ||
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php | ||
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php | ||
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php | ||
*/ | ||
public function testGetList() | ||
{ | ||
$requestData = [ | ||
'searchCriteria' => [ | ||
SearchCriteria::FILTER_GROUPS => [ | ||
[ | ||
'filters' => [ | ||
[ | ||
'field' => SourceItemInterface::SKU, | ||
'value' => 'SKU-1', | ||
'condition_type' => 'eq', | ||
], | ||
], | ||
], | ||
], | ||
SearchCriteria::SORT_ORDERS => [ | ||
[ | ||
'field' => SourceItemInterface::QUANTITY, | ||
'direction' => SortOrder::SORT_DESC, | ||
], | ||
], | ||
SearchCriteria::CURRENT_PAGE => 2, | ||
SearchCriteria::PAGE_SIZE => 2, | ||
], | ||
]; | ||
$expectedTotalCount = 4; | ||
$expectedItemsData = [ | ||
[ | ||
SourceItemInterface::SOURCE_ID => 10, | ||
SourceItemInterface::SKU => 'SKU-1', | ||
SourceItemInterface::QUANTITY => 5.5, | ||
SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, | ||
], | ||
[ | ||
SourceItemInterface::SOURCE_ID => 20, | ||
SourceItemInterface::SKU => 'SKU-1', | ||
SourceItemInterface::QUANTITY => 3, | ||
SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, | ||
], | ||
]; | ||
|
||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData), | ||
'httpMethod' => Request::HTTP_METHOD_GET, | ||
], | ||
'soap' => [ | ||
'service' => self::SERVICE_NAME, | ||
'operation' => self::SERVICE_NAME . 'GetList', | ||
], | ||
]; | ||
$response = (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) | ||
? $this->_webApiCall($serviceInfo) | ||
: $this->_webApiCall($serviceInfo, $requestData); | ||
|
||
AssertArrayContains::assert($requestData['searchCriteria'], $response['search_criteria']); | ||
self::assertEquals($expectedTotalCount, $response['total_count']); | ||
AssertArrayContains::assert($expectedItemsData, $response['items']); | ||
} | ||
} |
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
115 changes: 115 additions & 0 deletions
115
app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/SaveTest.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,115 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryApi\Test\Api\SourceItemsSave; | ||
|
||
use Magento\Framework\Api\SearchCriteria; | ||
use Magento\Framework\Webapi\Rest\Request; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\TestFramework\Assert\AssertArrayContains; | ||
use Magento\TestFramework\TestCase\WebapiAbstract; | ||
|
||
class SaveTest extends WebapiAbstract | ||
{ | ||
/**#@+ | ||
* Service constants | ||
*/ | ||
const RESOURCE_PATH = '/V1/inventory/source-item'; | ||
const SERVICE_NAME = 'inventoryApiSourceItemsSaveV1'; | ||
/**#@-*/ | ||
|
||
/** | ||
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php | ||
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php | ||
*/ | ||
public function testExecute() | ||
{ | ||
$sourceItems = [ | ||
[ | ||
SourceItemInterface::SOURCE_ID => 10, | ||
SourceItemInterface::SKU => 'SKU-1', | ||
SourceItemInterface::QUANTITY => 5.5, | ||
SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, | ||
], | ||
[ | ||
SourceItemInterface::SOURCE_ID => 20, | ||
SourceItemInterface::SKU => 'SKU-1', | ||
SourceItemInterface::QUANTITY => 3, | ||
SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, | ||
], | ||
]; | ||
|
||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => self::RESOURCE_PATH, | ||
'httpMethod' => Request::HTTP_METHOD_POST, | ||
], | ||
'soap' => [ | ||
'service' => self::SERVICE_NAME, | ||
'operation' => self::SERVICE_NAME . 'Execute', | ||
], | ||
]; | ||
$this->_webApiCall($serviceInfo, ['sourceItems' => $sourceItems]); | ||
|
||
$actualData = $this->getSourceItems(); | ||
|
||
self::assertEquals(2, $actualData['total_count']); | ||
AssertArrayContains::assert($sourceItems, $actualData['items']); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$sourceItems = [ | ||
[ | ||
SourceItemInterface::SOURCE_ID => 10, | ||
SourceItemInterface::SKU => 'SKU-1', | ||
], | ||
[ | ||
SourceItemInterface::SOURCE_ID => 20, | ||
SourceItemInterface::SKU => 'SKU-1', | ||
], | ||
]; | ||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => self::RESOURCE_PATH . '?' | ||
. http_build_query(['sourceItems' => $sourceItems]), | ||
'httpMethod' => Request::HTTP_METHOD_DELETE, | ||
], | ||
'soap' => [ | ||
'service' => self::SERVICE_NAME, | ||
'operation' => self::SERVICE_NAME . 'Execute', | ||
], | ||
]; | ||
(TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) | ||
? $this->_webApiCall($serviceInfo) | ||
: $this->_webApiCall($serviceInfo, ['sourceItems' => $sourceItems]); | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getSourceItems(): array | ||
{ | ||
$requestData = [ | ||
'searchCriteria' => [SearchCriteria::PAGE_SIZE => 10], | ||
]; | ||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData), | ||
'httpMethod' => Request::HTTP_METHOD_GET, | ||
], | ||
'soap' => [ | ||
'service' => 'inventoryApiSourceItemRepositoryV1', | ||
'operation' => 'inventoryApiSourceItemRepositoryV1GetList', | ||
], | ||
]; | ||
return (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) | ||
? $this->_webApiCall($serviceInfo) | ||
: $this->_webApiCall($serviceInfo, $requestData); | ||
} | ||
} |
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