Skip to content

Commit e9b1ed7

Browse files
committed
ACP2E-763: Bulk Rest API not working
1 parent fa1fc1f commit e9b1ed7

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\WebapiAsync\Model;
10+
11+
use Magento\Eav\Model\AttributeRepository;
12+
use Magento\TestFramework\TestCase\WebapiAbstract;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use Magento\Framework\Webapi\Rest\Request;
15+
16+
/**
17+
* Check async request for configurable products creation service
18+
*
19+
* @magentoAppIsolation enabled
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21+
*/
22+
class AsyncBulkConfigurableProductsTest extends WebapiAbstract
23+
{
24+
const SERVICE_NAME = 'asyncBulkConfigurableProductsV1';
25+
const ASYNC_BULK_RESOURCE_PATH = '/async/bulk/V1/configurable-products';
26+
27+
const BULK_UUID_KEY = 'bulk_uuid';
28+
29+
/**
30+
* @var \Magento\Framework\ObjectManagerInterface
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* @var AttributeRepository
36+
*/
37+
protected $attributeRepository;
38+
39+
protected function setUp(): void
40+
{
41+
$this->objectManager = Bootstrap::getObjectManager();
42+
$this->attributeRepository = $this->objectManager->get(\Magento\Eav\Model\AttributeRepository::class);
43+
}
44+
45+
/**
46+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
47+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_attribute.php
48+
*
49+
* @return void
50+
*/
51+
public function testAsyncScheduleBulkMultipleEntities()
52+
{
53+
$productSku = 'configurable';
54+
$attribute = $this->attributeRepository->get('catalog_product', 'test_configurable');
55+
56+
$this->_markTestAsRestOnly();
57+
$requestData = [
58+
[
59+
'sku' => $productSku,
60+
'option' => [
61+
'attribute_id' => (int)$attribute->getAttributeId(),
62+
'label' => 'test_configurable',
63+
'position' => 0,
64+
'is_use_default' => true,
65+
'values' => [
66+
[
67+
'value_index' => $attribute->getOptions()[1]->getValue()
68+
]
69+
]
70+
]
71+
]
72+
];
73+
$response = $this->saveConfigurableProductsBySku($requestData, 'options');
74+
$this->assertArrayHasKey(self::BULK_UUID_KEY, $response);
75+
$this->assertNotNull($response[self::BULK_UUID_KEY]);
76+
77+
$this->assertCount(1, $response['request_items']);
78+
$this->assertEquals('accepted', $response['request_items'][0]['status']);
79+
$this->assertFalse($response['errors']);
80+
}
81+
82+
/**
83+
* @param $requestData
84+
* @param string $urlParam
85+
* @param string|null $storeCode
86+
* @return mixed
87+
*/
88+
private function saveConfigurableProductsBySku($requestData, $urlParam, $storeCode = null)
89+
{
90+
$serviceInfo = [
91+
'rest' => [
92+
'resourcePath' => self::ASYNC_BULK_RESOURCE_PATH.'/bySku/'.$urlParam,
93+
'httpMethod' => Request::HTTP_METHOD_POST,
94+
],
95+
];
96+
97+
return $this->_webApiCall($serviceInfo, $requestData, null, $storeCode);
98+
}
99+
}

0 commit comments

Comments
 (0)