Skip to content

Commit f492741

Browse files
author
Anna Bukatar
committed
ACP2E-1969: Incorrect behavior for system messages when trying to delete bulk product using REST API
1 parent 25ede9d commit f492741

File tree

1 file changed

+54
-0
lines changed
  • app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized

1 file changed

+54
-0
lines changed

app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,60 @@ public function testAfterTo($operationDetails)
163163
$this->assertEquals(2, $result2['totalRecords']);
164164
}
165165

166+
/**
167+
* Tests that message building operations don't get called more than Plugin::MESSAGES_LIMIT times
168+
*
169+
* @return void
170+
*/
171+
public function testAfterToWithMessageLimit()
172+
{
173+
$result = ['items' =>[], 'totalRecords' => 1];
174+
$messagesCount = Plugin::MESSAGES_LIMIT + 1;
175+
$userId = 1;
176+
$bulkUuid = 2;
177+
$bulkArray = [
178+
'status' => BulkSummaryInterface::NOT_STARTED
179+
];
180+
181+
$bulkMock = $this->getMockBuilder(BulkSummary::class)
182+
->addMethods(['getStatus'])
183+
->onlyMethods(['getBulkId', 'getDescription', 'getStartTime'])
184+
->disableOriginalConstructor()
185+
->getMock();
186+
$userBulks = array_fill(0, $messagesCount, $bulkMock);
187+
$bulkMock->expects($this->exactly($messagesCount))
188+
->method('getBulkId')->willReturn($bulkUuid);
189+
$this->operationsDetailsMock
190+
->expects($this->exactly(Plugin::MESSAGES_LIMIT))
191+
->method('getDetails')
192+
->with($bulkUuid)
193+
->willReturn([
194+
'operations_successful' => 1,
195+
'operations_failed' => 0
196+
]);
197+
$bulkMock->expects($this->exactly(Plugin::MESSAGES_LIMIT))
198+
->method('getDescription')->willReturn('Bulk Description');
199+
$this->messagefactoryMock->expects($this->exactly($messagesCount))
200+
->method('create')->willReturn($this->messageMock);
201+
$this->messageMock->expects($this->exactly($messagesCount))->method('toArray')->willReturn($bulkArray);
202+
$this->authorizationMock
203+
->expects($this->once())
204+
->method('isAllowed')
205+
->with($this->resourceName)
206+
->willReturn(true);
207+
$this->userContextMock->expects($this->once())->method('getUserId')->willReturn($userId);
208+
$this->bulkNotificationMock
209+
->expects($this->once())
210+
->method('getAcknowledgedBulksByUser')
211+
->with($userId)
212+
->willReturn([]);
213+
$this->statusMapper->expects($this->exactly(Plugin::MESSAGES_LIMIT))
214+
->method('operationStatusToBulkSummaryStatus');
215+
$this->bulkStatusMock->expects($this->once())->method('getBulksByUser')->willReturn($userBulks);
216+
$result2 = $this->plugin->afterToArray($this->collectionMock, $result);
217+
$this->assertEquals($result['totalRecords'] + $messagesCount, $result2['totalRecords']);
218+
}
219+
166220
/**
167221
* @return array
168222
*/

0 commit comments

Comments
 (0)