Skip to content

Commit 897034b

Browse files
author
Mohan Ahuja
committed
ACP2E-726: Unable to query bulk operations by search criteria using REST Api
- Unit test added
1 parent 26838dd commit 897034b

File tree

2 files changed

+72
-15
lines changed

2 files changed

+72
-15
lines changed

app/code/Magento/AsynchronousOperations/Test/Unit/Model/OperationRepositoryTest.php

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
namespace Magento\AsynchronousOperations\Test\Unit\Model;
99

1010
use Magento\AsynchronousOperations\Api\Data\OperationExtensionInterfaceFactory;
11-
use Magento\AsynchronousOperations\Model\BulkStatus;
1211
use Magento\AsynchronousOperations\Model\OperationRepository;
1312
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\Collection as OperationCollection;
1413
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\CollectionFactory as OperationCollectionFactory;
1514
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
1615
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1716
use Magento\Framework\EntityManager\EntityManager;
1817
use Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterfaceFactory as SearchResultFactory;
18+
use Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface;
19+
use Magento\Framework\Api\SearchCriteriaInterface;
1920
use PHPUnit\Framework\MockObject\MockObject;
2021
use PHPUnit\Framework\TestCase;
2122

@@ -29,7 +30,7 @@ class OperationRepositoryTest extends TestCase
2930
/**
3031
* @var OperationRepository
3132
*/
32-
private OperationRepository $model;
33+
private $model;
3334

3435
/**
3536
* @var EntityManager|MockObject
@@ -66,6 +67,66 @@ class OperationRepositoryTest extends TestCase
6667
*/
6768
private $logger;
6869

70+
/**
71+
* private $item
72+
*/
73+
private array $items = [
74+
"items"=> [
75+
[
76+
"extension_attributes" => [
77+
"start_time" => "2022-05-06 05:48:04"
78+
],
79+
"id" => 1,
80+
"bulk_uuid" => "89300764-2502-44c6-a377-70b9565c34b8",
81+
"topic_name" => "async.magento.customer.api.accountmanagementinterface.createaccount.post",
82+
"serialized_data" => "{\"entity_id\":null,\"entity_link\":\"\",\"meta_information\":\"{\\\"customer\\\":{\\\"email\\\":\\\"mshaw@example.com\\\",\\\"firstname\\\":\\\"Melanie Shaw\\\",\\\"lastname\\\":\\\"Doe\\\"},\\\"password\\\":\\\"Strong-Password\\\"}\"}",
83+
"result_serialized_data" => null,
84+
"status"=> 4,
85+
"result_message" => null,
86+
"error_code" => null
87+
],
88+
[
89+
"extension_attributes" => [
90+
"start_time" => "2022-05-06 05:48:04"
91+
],
92+
"id" => 2,
93+
"bulk_uuid" => "89300764-2502-44c6-a377-70b9565c34b8",
94+
"topic_name" => "async.magento.customer.api.accountmanagementinterface.createaccount.post",
95+
"serialized_data" => "{\"entity_id\":null,\"entity_link\":\"\",\"meta_information\":\"{\\\"customer\\\":{\\\"email\\\":\\\"bmartin@example.com\\\",\\\"firstname\\\":\\\"Bryce\\\",\\\"lastname\\\":\\\"Martin\\\"},\\\"password\\\":\\\"Strong-Password\\\"}\"}",
96+
"result_serialized_data" => null,
97+
"status" => 4,
98+
"result_message" => null,
99+
"error_code" => null
100+
],
101+
[
102+
"extension_attributes"=> [
103+
"start_time"=> "2022-05-06 05:48:04"
104+
],
105+
"id" => 3,
106+
"bulk_uuid" => "89300764-2502-44c6-a377-70b9565c34b8",
107+
"topic_name" => "async.magento.customer.api.accountmanagementinterface.createaccount.post",
108+
"serialized_data" => "{\"entity_id\":null,\"entity_link\":\"\",\"meta_information\":\"{\\\"customer\\\":{\\\"email\\\":\\\"bmartin@example.com\\\",\\\"firstname\\\":\\\"Bryce\\\",\\\"lastname\\\":\\\"Martin\\\"},\\\"password\\\":\\\"Strong-Password\\\"}\"}",
109+
"result_serialized_data" => null,
110+
"status" => 4,
111+
"result_message" => null,
112+
"error_code" => null
113+
],
114+
[
115+
"extension_attributes" => [
116+
"start_time" => "2022-05-06 05:48:04"
117+
],
118+
"id" => 4,
119+
"bulk_uuid" => "89300764-2502-44c6-a377-70b9565c34b8",
120+
"topic_name" => "async.magento.customer.api.accountmanagementinterface.createaccount.post",
121+
"serialized_data" => "{\"entity_id\":null,\"entity_link\":\"\",\"meta_information\":\"{\\\"customer\\\":{\\\"email\\\":\\\"tgomez@example.com\\\",\\\"firstname\\\":\\\"Teresa\\\",\\\"lastname\\\":\\\"Gomez\\\"},\\\"password\\\":\\\"Strong-Password\\\"}\"}",
122+
"result_serialized_data" => null,
123+
"status" => 4,
124+
"result_message" => null,
125+
"error_code" => null
126+
],
127+
],
128+
];
129+
69130
/**
70131
* @inheritdoc
71132
*/
@@ -91,22 +152,18 @@ protected function setUp(): void
91152
}
92153

93154
/**
94-
* @param int|null $failureType
95-
* @param array $failureCodes
96-
*
97155
* @return void
98-
* @dataProvider getFailedOperationsByBulkIdDataProvider
99156
*/
100-
public function testGetFailedOperationsByBulkId(?int $failureType, array $failureCodes): void
157+
public function testGetFailedOperationsByBulkId(): void
101158
{
102-
$bulkUuid = 'bulk-1';
159+
$searchResultInterface = $this->createMock(OperationSearchResultsInterface::class);
160+
$searchCriteria = $this->createMock(SearchCriteriaInterface::class);
161+
$this->searchResultFactory->expects($this->once())->method('create')->willReturn($searchResultInterface);
103162
$operationCollection = $this->createMock(OperationCollection::class);
163+
164+
$operationCollection->expects($this->once())->method('getItems')->willReturn($this->items);
165+
$operationCollection->expects($this->exactly(3))->method('addFieldToSelect')->willReturnSelf();
104166
$this->operationCollectionFactory->expects($this->once())->method('create')->willReturn($operationCollection);
105-
$operationCollection
106-
->method('addFieldToFilter')
107-
->withConsecutive(['bulk_uuid', $bulkUuid], ['status', $failureCodes])
108-
->willReturnOnConsecutiveCalls($operationCollection, $operationCollection);
109-
$operationCollection->expects($this->once())->method('getItems')->willReturn([$this->operationMock]);
110-
$this->assertEquals([$this->operationMock], $this->model->getFailedOperationsByBulkId($bulkUuid, $failureType));
167+
$this->model->getList($searchCriteria);
111168
}
112169
}

dev/tests/integration/testsuite/Magento/AsynchronousOperations/Cron/MarkIncompleteOperationsAsFailedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testExecute(): void
103103
);
104104
$this->assertEquals(1, $collection->count());
105105
$operation = $collection->getFirstItem();
106-
$this->assertEquals(1, $operation->getId());
106+
$this->assertEquals(2, $operation->getId());
107107
$this->assertEquals(0, $operation->getErrorCode());
108108
$this->assertEquals('Unknown Error', $operation->getResultMessage());
109109
}

0 commit comments

Comments
 (0)