Skip to content

Commit 5536151

Browse files
author
Vasiliev.A
committed
OperationRepositoryInterface getList api-functional test
1 parent 1c4078f commit 5536151

File tree

2 files changed

+160
-2
lines changed

2 files changed

+160
-2
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\AsynchronousOperations\Api;
8+
9+
use Magento\Framework\Webapi\Rest\Request;
10+
use Magento\TestFramework\TestCase\WebapiAbstract;
11+
use Magento\Framework\Bulk\OperationInterface;
12+
13+
class OperationRepositoryInterfaceTest extends WebapiAbstract
14+
{
15+
const RESOURCE_PATH = '/V1/bulk';
16+
const SERVICE_NAME = 'asynchronousOperationsOperationRepositoryV1';
17+
18+
/**
19+
* @magentoApiDataFixture Magento/AsynchronousOperations/_files/bulk.php
20+
*/
21+
public function testGetListByBulkStartTime()
22+
{
23+
$searchCriteria = [
24+
'searchCriteria' => [
25+
'filter_groups' => [
26+
[
27+
'filters' => [
28+
[
29+
'field' => 'start_time',
30+
'value' => '2010-10-10 00:00:00',
31+
'condition_type' => 'lteq',
32+
],
33+
],
34+
],
35+
],
36+
'current_page' => 1,
37+
],
38+
];
39+
40+
$serviceInfo = [
41+
'rest' => [
42+
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
43+
'httpMethod' => Request::HTTP_METHOD_GET,
44+
],
45+
'soap' => [
46+
'service' => self::SERVICE_NAME,
47+
'operation' => self::SERVICE_NAME . 'GetList',
48+
],
49+
];
50+
51+
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
52+
53+
$this->assertArrayHasKey('search_criteria', $response);
54+
$this->assertArrayHasKey('total_count', $response);
55+
$this->assertArrayHasKey('items', $response);
56+
57+
$this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']);
58+
$this->assertEquals(3, $response['total_count']);
59+
$this->assertEquals(3, count($response['items']));
60+
61+
foreach ($response['items'] as $item) {
62+
$this->assertEquals('bulk-uuid-6', $item['bulk_uuid']);
63+
}
64+
}
65+
66+
/**
67+
* @magentoApiDataFixture Magento/AsynchronousOperations/_files/bulk.php
68+
*/
69+
public function testGetList()
70+
{
71+
$searchCriteria = [
72+
'searchCriteria' => [
73+
'filter_groups' => [
74+
[
75+
'filters' => [
76+
[
77+
'field' => 'bulk_uuid',
78+
'value' => 'bulk-uuid-6',
79+
'condition_type' => 'eq',
80+
],
81+
],
82+
],
83+
[
84+
'filters' => [
85+
[
86+
'field' => 'status',
87+
'value' => OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED,
88+
'condition_type' => 'eq',
89+
],
90+
],
91+
],
92+
],
93+
'current_page' => 1,
94+
],
95+
];
96+
97+
$serviceInfo = [
98+
'rest' => [
99+
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
100+
'httpMethod' => Request::HTTP_METHOD_GET,
101+
],
102+
'soap' => [
103+
'service' => self::SERVICE_NAME,
104+
'operation' => self::SERVICE_NAME . 'GetList',
105+
],
106+
];
107+
108+
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
109+
110+
$this->assertArrayHasKey('search_criteria', $response);
111+
$this->assertArrayHasKey('total_count', $response);
112+
$this->assertArrayHasKey('items', $response);
113+
114+
$this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']);
115+
$this->assertEquals(1, $response['total_count']);
116+
$this->assertEquals(1, count($response['items']));
117+
118+
foreach ($response['items'] as $item) {
119+
$this->assertEquals('bulk-uuid-6', $item['bulk_uuid']);
120+
}
121+
}
122+
}

dev/tests/integration/testsuite/Magento/AsynchronousOperations/_files/bulk.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,42 @@
2020
'user_id' => 1,
2121
'description' => 'Bulk Description',
2222
'operation_count' => 1,
23+
'start_time' => null,
2324
],
2425
'in_progress_success' => [
2526
'uuid' => 'bulk-uuid-2',
2627
'user_id' => 1,
2728
'description' => 'Bulk Description',
2829
'operation_count' => 3,
30+
'start_time' => null,
2931
],
3032
'in_progress_failed' => [
3133
'uuid' => 'bulk-uuid-3',
3234
'user_id' => 1,
3335
'description' => 'Bulk Description',
3436
'operation_count' => 2,
37+
'start_time' => null,
3538
],
3639
'finish_success' => [
3740
'uuid' => 'bulk-uuid-4',
3841
'user_id' => 1,
3942
'description' => 'Bulk Description',
4043
'operation_count' => 1,
44+
'start_time' => null,
4145
],
4246
'finish_failed' => [
4347
'uuid' => 'bulk-uuid-5',
4448
'user_id' => 1,
4549
'description' => 'Bulk Description',
4650
'operation_count' => 2,
51+
'start_time' => null,
52+
],
53+
'started_searchable' => [
54+
'uuid' => 'bulk-uuid-6',
55+
'user_id' => 1,
56+
'description' => 'Bulk Description',
57+
'operation_count' => 3,
58+
'start_time' => '2009-10-10 00:00:00'
4759
]
4860
];
4961
// Only processed operations are saved into database (i.e. operations that are not in 'open' state)
@@ -88,11 +100,35 @@
88100
'error_code' => 2222,
89101
'result_message' => 'Entity with ID=4 does not exist',
90102
],
103+
[
104+
'bulk_uuid' => 'bulk-uuid-6',
105+
'topic_name' => 'topic-5',
106+
'serialized_data' => json_encode(['entity_id' => 5]),
107+
'status' => OperationInterface::STATUS_TYPE_COMPLETE,
108+
'error_code' => null,
109+
'result_message' => null,
110+
],
111+
[
112+
'bulk_uuid' => 'bulk-uuid-6',
113+
'topic_name' => 'topic-5',
114+
'serialized_data' => json_encode(['entity_id' => 5, 'meta_information' => 'Test']),
115+
'status' => OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED,
116+
'error_code' => 1111,
117+
'result_message' => 'Something went wrong during your request',
118+
],
119+
[
120+
'bulk_uuid' => 'bulk-uuid-6',
121+
'topic_name' => 'topic-5',
122+
'serialized_data' => json_encode(['entity_id' => 5]),
123+
'status' => OperationInterface::STATUS_TYPE_RETRIABLY_FAILED,
124+
'error_code' => 2222,
125+
'result_message' => 'Entity with ID=4 does not exist',
126+
],
91127

92128
];
93129

94-
$bulkQuery = "INSERT INTO {$bulkTable} (`uuid`, `user_id`, `description`, `operation_count`)"
95-
. " VALUES (:uuid, :user_id, :description, :operation_count);";
130+
$bulkQuery = "INSERT INTO {$bulkTable} (`uuid`, `user_id`, `description`, `operation_count`, `start_time`)"
131+
. " VALUES (:uuid, :user_id, :description, :operation_count, :start_time);";
96132
foreach ($bulks as $bulk) {
97133
$connection->query($bulkQuery, $bulk);
98134
}

0 commit comments

Comments
 (0)