Skip to content

Commit 3432e51

Browse files
author
Mohan Ahuja
committed
ACP2E-726: Unable to query bulk operations by search criteria using REST Api
- Removed old integration test - Created API integration test - Reverted not related changes as per CR comments
1 parent 8e5dafa commit 3432e51

File tree

3 files changed

+102
-34
lines changed

3 files changed

+102
-34
lines changed

app/code/Magento/AsynchronousOperations/Model/OperationRepository.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Magento\AsynchronousOperations\Api\Data\OperationExtensionInterfaceFactory;
1515
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\CollectionFactory;
1616
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
17+
use Magento\Framework\Exception\InputException;
18+
use Magento\Framework\Exception\NoSuchEntityException;
1719

1820
/**
1921
* Repository class for @see \Magento\AsynchronousOperations\Api\OperationRepositoryInterface
@@ -82,6 +84,7 @@ public function __construct(
8284
$this->operationExtensionFactory = $operationExtension;
8385
$this->collectionProcessor = $collectionProcessor;
8486
$this->logger = $logger;
87+
$this->collectionProcessor = $collectionProcessor;
8588
}
8689

8790
/**

dev/tests/api-functional/testsuite/Magento/AsynchronousOperations/Api/OperationRepositoryInterfaceTest.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,35 @@
88

99
namespace Magento\AsynchronousOperations\Api;
1010

11+
use Magento\AsynchronousOperations\Model\MassSchedule;
1112
use Magento\Framework\Webapi\Rest\Request;
1213
use Magento\TestFramework\TestCase\WebapiAbstract;
1314
use Magento\Framework\Bulk\OperationInterface;
15+
use Magento\Customer\Api\Data\CustomerInterface;
1416

1517
class OperationRepositoryInterfaceTest extends WebapiAbstract
1618
{
1719
const RESOURCE_PATH = '/V1/bulk';
1820
const SERVICE_NAME = 'asynchronousOperationsOperationRepositoryV1';
1921

22+
/**
23+
* @var \Magento\Framework\ObjectManagerInterface
24+
*/
25+
protected $objectManager;
26+
27+
/**
28+
* @var MassSchedule
29+
*/
30+
private $massSchedule;
31+
32+
public function setUp(): void
33+
{
34+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
35+
$this->massSchedule = $this->objectManager->create(MassSchedule::class);
36+
37+
parent::setUp();
38+
}
39+
2040
/**
2141
* @magentoApiDataFixture Magento/AsynchronousOperations/_files/operation_searchable.php
2242
*/
@@ -123,4 +143,83 @@ public function testGetList()
123143
$this->assertEquals('bulk-uuid-searchable-6', $item['bulk_uuid']);
124144
}
125145
}
146+
147+
/**
148+
* Check multiple bulk operation inserted followed by search via getList
149+
*/
150+
public function testBulkGetListByStartTime()
151+
{
152+
$entityArray = [
153+
['customer' => $this->getCustomer(), "password" => "Strong-Password"],
154+
[
155+
'customer' => $this->getCustomer('customer2@abc.com', 'Second'),
156+
"password" => "Strong-Password"
157+
],
158+
];
159+
160+
// Adding bulk records twice
161+
$this->sendBulk($entityArray);
162+
$this->sendBulk($entityArray);
163+
164+
$searchCriteria = [
165+
'searchCriteria' => [
166+
'filter_groups' => [
167+
[
168+
'filters' => [
169+
[
170+
'field' => 'start_time',
171+
'value' => date('Y-m-d H:i:0'),
172+
'condition_type' => 'gt',
173+
],
174+
],
175+
],
176+
],
177+
'current_page' => 1,
178+
'page_size' => 20,
179+
],
180+
];
181+
182+
$serviceInfo = [
183+
'rest' => [
184+
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
185+
'httpMethod' => Request::HTTP_METHOD_GET,
186+
],
187+
'soap' => [
188+
'service' => self::SERVICE_NAME,
189+
'operation' => self::SERVICE_NAME . 'GetList',
190+
],
191+
];
192+
193+
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
194+
195+
$this->assertArrayHasKey('search_criteria', $response);
196+
$this->assertArrayHasKey('total_count', $response);
197+
$this->assertArrayHasKey('items', $response);
198+
199+
$this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']);
200+
$this->assertEquals(4, $response['total_count']);
201+
$this->assertCount(4, $response['items']);
202+
}
203+
204+
public function sendBulk($customers)
205+
{
206+
$result = $this->massSchedule->publishMass(
207+
'async.magento.customer.api.accountmanagementinterface.createaccount.post',
208+
$customers
209+
);
210+
211+
// Assert bulk accepted with no errors
212+
$this->assertFalse($result->isErrors());
213+
}
214+
215+
private function getCustomer($email = 'customer1@abc.com', $firstName = 'First', $lastName = 'Customer')
216+
{
217+
/** @var $customer \Magento\Customer\Model\Data\Customer */
218+
$customer = $this->objectManager->create(CustomerInterface::class);
219+
$customer
220+
->setFirstName($firstName)
221+
->setLastname($lastName)
222+
->setEmail($email);
223+
return $customer;
224+
}
126225
}

dev/tests/integration/testsuite/Magento/AsynchronousOperations/Model/ResourceModel/Operation/CollectionTest.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)