|
8 | 8 |
|
9 | 9 | namespace Magento\AsynchronousOperations\Api;
|
10 | 10 |
|
| 11 | +use Magento\AsynchronousOperations\Model\MassSchedule; |
11 | 12 | use Magento\Framework\Webapi\Rest\Request;
|
12 | 13 | use Magento\TestFramework\TestCase\WebapiAbstract;
|
13 | 14 | use Magento\Framework\Bulk\OperationInterface;
|
| 15 | +use Magento\Customer\Api\Data\CustomerInterface; |
14 | 16 |
|
15 | 17 | class OperationRepositoryInterfaceTest extends WebapiAbstract
|
16 | 18 | {
|
17 | 19 | const RESOURCE_PATH = '/V1/bulk';
|
18 | 20 | const SERVICE_NAME = 'asynchronousOperationsOperationRepositoryV1';
|
19 | 21 |
|
| 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 | + |
20 | 40 | /**
|
21 | 41 | * @magentoApiDataFixture Magento/AsynchronousOperations/_files/operation_searchable.php
|
22 | 42 | */
|
@@ -123,4 +143,83 @@ public function testGetList()
|
123 | 143 | $this->assertEquals('bulk-uuid-searchable-6', $item['bulk_uuid']);
|
124 | 144 | }
|
125 | 145 | }
|
| 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 | + } |
126 | 225 | }
|
0 commit comments