GetSourcesAssignedToStockOrderedByPriorityTest.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryApi\Test\Api\StockSourceLink;
  8. use Magento\Framework\Webapi\Exception;
  9. use Magento\Framework\Webapi\Rest\Request;
  10. use Magento\InventoryApi\Api\Data\SourceInterface;
  11. use Magento\TestFramework\TestCase\WebapiAbstract;
  12. class GetSourcesAssignedToStockOrderedByPriorityTest extends WebapiAbstract
  13. {
  14. /**#@+
  15. * Service constants
  16. */
  17. const RESOURCE_PATH_GET_ASSIGNED_SOURCES_FOR_STOCK
  18. = '/V1/inventory/get-sources-assigned-to-stock-ordered-by-priority';
  19. const SERVICE_NAME_GET_ASSIGNED_SOURCES_FOR_STOCK = 'inventoryApiGetSourcesAssignedToStockOrderedByPriorityV1';
  20. /**#@-*/
  21. /**
  22. * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  23. * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
  24. * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
  25. */
  26. public function testGetAssignedSourcesForStock()
  27. {
  28. $stockId = 30;
  29. $serviceInfo = [
  30. 'rest' => [
  31. 'resourcePath' => self::RESOURCE_PATH_GET_ASSIGNED_SOURCES_FOR_STOCK . '/' . $stockId,
  32. 'httpMethod' => Request::HTTP_METHOD_GET,
  33. ],
  34. 'soap' => [
  35. 'service' => self::SERVICE_NAME_GET_ASSIGNED_SOURCES_FOR_STOCK,
  36. 'operation' => self::SERVICE_NAME_GET_ASSIGNED_SOURCES_FOR_STOCK . 'Execute',
  37. ],
  38. ];
  39. $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST)
  40. ? $this->_webApiCall($serviceInfo)
  41. : $this->_webApiCall($serviceInfo, ['stockId' => $stockId]);
  42. self::assertEquals(
  43. ['us-1', 'eu-disabled', 'eu-3', 'eu-2', 'eu-1'],
  44. array_column($response, SourceInterface::SOURCE_CODE)
  45. );
  46. }
  47. /**
  48. * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
  49. * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
  50. * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
  51. */
  52. public function testGetAssignedSourcesWithNotNumericStockId()
  53. {
  54. if (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) {
  55. $this->markTestSkipped(
  56. 'Test works only for REST adapter because in SOAP one stock_id would be converted'
  57. . ' into zero (zero is allowed input for service never mind it\'s unreadable value as'
  58. . ' there are no stocks in the system with stock_id given)'
  59. );
  60. }
  61. $stockId = 'not_numeric';
  62. $serviceInfo = [
  63. 'rest' => [
  64. 'resourcePath' => self::RESOURCE_PATH_GET_ASSIGNED_SOURCES_FOR_STOCK . '/' . $stockId,
  65. 'httpMethod' => Request::HTTP_METHOD_GET,
  66. ],
  67. ];
  68. try {
  69. $this->_webApiCall($serviceInfo);
  70. $this->fail('Expected throwing exception');
  71. } catch (\Exception $e) {
  72. $errorData = $this->processRestExceptionResult($e);
  73. self::assertEquals(
  74. 'The "not_numeric" value\'s type is invalid. The "int" type was expected. Verify and try again.',
  75. $errorData['message']
  76. );
  77. self::assertEquals(Exception::HTTP_BAD_REQUEST, $e->getCode());
  78. }
  79. }
  80. }