Skip to content

Commit 34577af

Browse files
committed
magento-engcom/bulk-api#4 Support for Async operations in WebAPI
- Fixed integration tests
1 parent c21eafd commit 34577af

File tree

3 files changed

+10
-59
lines changed

3 files changed

+10
-59
lines changed

app/code/Magento/WebapiAsync/Controller/Rest/Async/InputParamsResolver.php

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,9 @@ public function resolve()
8989
{
9090
$this->requestValidator->validate();
9191
$webapiResolvedParams = [];
92-
$inputData = $this->request->getRequestData();
9392

94-
//simple check if async request have single or bulk entities
95-
if (array_key_exists(0, $inputData)) {
96-
foreach ($inputData as $key => $singleEntityParams) {
97-
if (is_integer($key)) {
98-
$webapiResolvedParams[$key] = $this->resolveBulkItemParams($singleEntityParams);
99-
}
100-
}
101-
} else {//single item request
102-
$webapiResolvedParams[] = $this->inputParamsResolver->resolve();
103-
}
93+
///single item request
94+
$webapiResolvedParams[] = $this->inputParamsResolver->resolve();
10495

10596
return $webapiResolvedParams;
10697
}
@@ -112,26 +103,4 @@ public function getRoute()
112103
{
113104
return $this->inputParamsResolver->getRoute();
114105
}
115-
116-
/**
117-
* Convert the input array from key-value format to a list of parameters
118-
* suitable for the specified class / method.
119-
*
120-
* Instead of \Magento\Webapi\Controller\Rest\InputParamsResolver
121-
* we don't need to merge body params with url params and use only body params
122-
*
123-
* @param array $inputData data to send to method in key-value format
124-
* @return array list of parameters that can be used to call the service method
125-
* @throws \Magento\Framework\Exception\InputException if no value is provided for required parameters
126-
* @throws \Magento\Framework\Webapi\Exception
127-
*/
128-
private function resolveBulkItemParams($inputData)
129-
{
130-
$route = $this->getRoute();
131-
$serviceMethodName = $route->getServiceMethod();
132-
$serviceClassName = $route->getServiceClass();
133-
$inputParams = $this->serviceInputProcessor->process($serviceClassName, $serviceMethodName, $inputData);
134-
135-
return $inputParams;
136-
}
137106
}

dev/tests/api-functional/testsuite/Magento/WebapiAsync/Model/BulkScheduleTest.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,17 @@ protected function setUp()
107107
public function testAsyncScheduleBulk($product)
108108
{
109109
$this->_markTestAsRestOnly();
110+
$this->skus[] = $product['product'][ProductInterface::SKU];
111+
$this->clearProducts();
112+
110113
$response = $this->saveProductAsync($product);
111114
$this->assertArrayHasKey(self::BULK_UUID_KEY, $response);
112115
$this->assertNotNull($response[self::BULK_UUID_KEY]);
113116

114-
if (count($product) <= 1) {
115-
$this->skus[] = $product['product'][ProductInterface::SKU];
116-
$this->assertCount(1, $response['request_items']);
117-
$this->assertEquals('accepted', $response['request_items'][0]['status']);
118-
$this->assertFalse($response['errors']);
119-
} else {
120-
$this->assertCount(count($product), $response['request_items']);
121-
foreach ($product as $productItem) {
122-
$this->skus[] = $productItem['product'][ProductInterface::SKU];
123-
}
124-
foreach ($response['request_items'] as $status) {
125-
$this->assertEquals('accepted', $status['status']);
126-
}
127-
$this->assertFalse($response['errors']);
128-
}
117+
$this->assertCount(1, $response['request_items']);
118+
$this->assertEquals('accepted', $response['request_items'][0]['status']);
119+
$this->assertFalse($response['errors']);
120+
129121
//assert one products is created
130122
try {
131123
$this->publisherConsumerController->waitForAsynchronousResult(
@@ -224,16 +216,6 @@ public function productCreationProvider()
224216
[['product' => $productBuilder([
225217
ProductInterface::TYPE_ID => 'virtual',
226218
ProductInterface::SKU => 'psku-test-2'])
227-
]],
228-
[[
229-
['product' => $productBuilder([
230-
ProductInterface::TYPE_ID => 'simple',
231-
ProductInterface::SKU => 'psku-test-1'
232-
])],
233-
['product' => $productBuilder([
234-
ProductInterface::TYPE_ID => 'virtual',
235-
ProductInterface::SKU => 'psku-test-2'
236-
])]
237219
]]
238220
];
239221
}

dev/tests/integration/framework/Magento/TestFramework/MessageQueue/PublisherConsumerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function waitForAsynchronousResult(callable $condition, $params)
161161
do {
162162
sleep(1);
163163
$assertion = call_user_func_array($condition, $params);
164-
} while (!$assertion && ($i++ < 20));
164+
} while (!$assertion && ($i++ < 180));
165165

166166
if (!$assertion) {
167167
throw new PreconditionFailedException("No asynchronous messages were processed.");

0 commit comments

Comments
 (0)