Skip to content

Commit 2270df9

Browse files
committed
ACP2E-1875: [Magento Cloud] Products incorrectly showed Out of Stock then all products show in stock
- added unit tests
1 parent 6bc6034 commit 2270df9

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/FulltextTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public function testExecute()
117117
$this->fulltextResource->expects($this->exactly(2))
118118
->method('getRelationsByChild')
119119
->willReturn($ids);
120+
$this->saveHandler->expects($this->exactly(count($stores)))->method('enableStackedActions');
121+
$this->saveHandler->expects($this->exactly(count($stores)))->method('triggerStackedActions');
122+
$this->saveHandler->expects($this->exactly(count($stores)))->method('disableStackedActions');
120123
$this->saveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
121124
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');
122125
$this->saveHandler->expects($this->exactly(2))->method('isAvailable')->willReturn(true);
@@ -134,6 +137,40 @@ function ($store) use ($ids) {
134137
$this->model->execute($ids);
135138
}
136139

140+
public function testExecuteWithStackedQueriesException()
141+
{
142+
$ids = [1, 2, 3];
143+
$stores = [0 => 'Store 1'];
144+
$this->setupDataProvider($stores);
145+
146+
$indexData = new \ArrayObject([]);
147+
$this->fulltextResource->expects($this->exactly(1))
148+
->method('getRelationsByChild')
149+
->willReturn($ids);
150+
$this->saveHandler->expects($this->exactly(count($stores)))->method('enableStackedActions');
151+
$this->saveHandler->expects($this->exactly(count($stores) + 1))->method('deleteIndex');
152+
$this->saveHandler->expects($this->exactly(count($stores) + 1))->method('saveIndex');
153+
$this->saveHandler->expects($this->exactly(count($stores)))
154+
->method('triggerStackedActions')
155+
->willThrowException(new \Exception('error'));
156+
$this->saveHandler->expects($this->exactly(count($stores)))->method('disableStackedActions');
157+
158+
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');
159+
$this->saveHandler->expects($this->exactly(1))->method('isAvailable')->willReturn(true);
160+
$consecutiveStoreRebuildArguments = array_map(
161+
function ($store) use ($ids) {
162+
return [$store, $ids];
163+
},
164+
$stores
165+
);
166+
$this->fullAction->expects($this->exactly(2))
167+
->method('rebuildStoreIndex')
168+
->withConsecutive(...$consecutiveStoreRebuildArguments)
169+
->willReturn(new \ArrayObject([$indexData, $indexData]));
170+
171+
$this->model->execute($ids);
172+
}
173+
137174
/**
138175
* @param $stores
139176
*/

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/ElasticsearchTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,39 @@ public function testAddDocs(): void
312312
);
313313
}
314314

315+
/**
316+
* @return void
317+
* @throws Exception
318+
*/
319+
public function testAddDocsStackedQueries(): void
320+
{
321+
$this->client->expects($this->once())
322+
->method('bulkQuery');
323+
$this->model->enableStackQueriesMode();
324+
$this->assertSame(
325+
$this->model,
326+
$this->model->addDocs(
327+
['1' => ['name' => 'Product Name'],
328+
],
329+
1,
330+
'product'
331+
)
332+
);
333+
$this->model->triggerStackedQueries();
334+
}
335+
336+
/**
337+
* @return void
338+
* @throws Exception
339+
*/
340+
public function testTriggerStackedQueriesWhenEmpty(): void
341+
{
342+
$this->client->expects($this->never())
343+
->method('bulkQuery');
344+
$this->model->enableStackQueriesMode();
345+
$this->model->triggerStackedQueries();
346+
}
347+
315348
/**
316349
* Test addDocs() method
317350
*
@@ -378,6 +411,21 @@ public function testDeleteDocs(): void
378411
);
379412
}
380413

414+
/**
415+
* @return void
416+
* @throws Exception
417+
*/
418+
public function testDeleteDocsStackedQueries(): void
419+
{
420+
$this->client->expects($this->once())
421+
->method('bulkQuery');
422+
$this->assertSame(
423+
$this->model,
424+
$this->model->deleteDocs(['1' => 1], 1, 'product'));
425+
$this->model->enableStackQueriesMode();
426+
$this->model->triggerStackedQueries();
427+
}
428+
381429
/**
382430
* Test deleteDocs() method
383431
*

app/code/Magento/Elasticsearch/Test/Unit/Model/Indexer/IndexerHandlerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,27 @@ protected function setUp(): void
180180
);
181181
}
182182

183+
public function testDisableStackedActions(): void
184+
{
185+
$this->adapter->expects($this->once())->method('disableStackQueriesMode');
186+
$this->model->disableStackedActions();
187+
}
188+
189+
public function testEnableStackedActions(): void
190+
{
191+
$this->adapter->expects($this->once())->method('enableStackQueriesMode');
192+
$this->model->enableStackedActions();
193+
}
194+
195+
/**
196+
* @throws \Exception
197+
*/
198+
public function testTriggerStackedActions(): void
199+
{
200+
$this->adapter->expects($this->once())->method('triggerStackedQueries');
201+
$this->model->triggerStackedActions();
202+
}
203+
183204
public function testIsAvailable()
184205
{
185206
$this->adapter->expects($this->any())

0 commit comments

Comments
 (0)