Skip to content

Commit 9ef48b8

Browse files
authored
MAGE-1055: Fix current integration tests (#1620)
* MAGE-1055: change values alignment and config paths * MAGE-1055: fix flakyness * MAGE-1055: add more waiting in saveConfigurationToAlgolia
1 parent 899b1fb commit 9ef48b8

File tree

8 files changed

+82
-76
lines changed

8 files changed

+82
-76
lines changed

Model/IndicesConfigurator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,32 @@ public function saveConfigurationToAlgolia(int $storeId, bool $useTmpIndex = fal
104104
}
105105

106106
$this->setCategoriesSettings($storeId);
107+
$this->algoliaHelper->waitLastTask();
108+
107109
/* heck if we want to index CMS pages */
108110
if ($this->configHelper->isPagesIndexEnabled($storeId)) {
109111
$this->setPagesSettings($storeId);
112+
$this->algoliaHelper->waitLastTask();
110113
} else {
111114
$this->logger->log('CMS Page Indexing is not enabled for the store.');
112115
}
113116

114117
//Check if we want to index Query Suggestions
115118
if ($this->configHelper->isQuerySuggestionsIndexEnabled($storeId)) {
116119
$this->setQuerySuggestionsSettings($storeId);
120+
$this->algoliaHelper->waitLastTask();
117121
} else {
118122
$this->logger->log('Query Suggestions Indexing is not enabled for the store.');
119123
}
120124

121125
$this->setAdditionalSectionsSettings($storeId);
126+
$this->algoliaHelper->waitLastTask();
127+
122128
$this->setProductsSettings($storeId, $useTmpIndex);
129+
$this->algoliaHelper->waitLastTask();
123130

124131
$this->setExtraSettings($storeId, $useTmpIndex);
132+
$this->algoliaHelper->waitLastTask();
125133
}
126134

127135
/**

Test/Integration/AssertValues/Magento23.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

Test/Integration/AssertValues/Magento24.php renamed to Test/Integration/AssertValues/Magento246.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues;
44

5-
class Magento24
5+
class Magento246
66
{
77
public $productsOnStockCount = 180;
88
public $productsOutOfStockCount = 181;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues;
4+
5+
class Magento247
6+
{
7+
public $productsOnStockCount = 182;
8+
public $productsOutOfStockCount = 183;
9+
public $lastJobDataSize = 13;
10+
public $expectedCategory = 17;
11+
public $attributesForFaceting = 5;
12+
public $automaticalSetOfCategoryAttributesForFaceting = 4;
13+
public $expectedPages = 9;
14+
public $expectedExcludePages = 7;
15+
}

Test/Integration/ConfigTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testAutomaticalSetOfCategoriesFacet()
7070
}
7171
}
7272

73-
$this->setConfig('algoliasearch_instant/instant/facets', $this->getSerializer()->serialize($facets));
73+
$this->setConfig('algoliasearch_instant/instant_facets/facets', $this->getSerializer()->serialize($facets));
7474

7575
// Set don't replace category pages with Algolia - categories attribute shouldn't be included in facets
7676
$this->setConfig('algoliasearch_instant/instant/replace_categories', '0');
@@ -179,7 +179,7 @@ private function replicaCreationTest($withCustomerGroups = false)
179179
];
180180

181181
$this->setConfig('algoliasearch_instant/instant/is_instant_enabled', '1'); // Needed to set replicas to Algolia
182-
$this->setConfig('algoliasearch_instant/instant/sorts', $this->getSerializer()->serialize($sortingIndicesData));
182+
$this->setConfig('algoliasearch_instant/instant_sorts/sorts', $this->getSerializer()->serialize($sortingIndicesData));
183183
$this->setConfig('algoliasearch_advanced/advanced/customer_groups_enable', $enableCustomGroups);
184184

185185
$sortingIndicesWithRankingWhichShouldBeCreated = [
@@ -221,13 +221,11 @@ public function testExtraSettings()
221221
$indexName = $this->indexPrefix . 'default_' . $section;
222222

223223
$this->algoliaHelper->setSettings($indexName, ['exactOnSingleWordQuery' => 'attribute']);
224+
$this->algoliaHelper->waitLastTask();
224225
}
225226

226-
$this->algoliaHelper->waitLastTask();
227-
228227
foreach ($sections as $section) {
229228
$indexName = $this->indexPrefix . 'default_' . $section;
230-
231229
$currentSettings = $this->algoliaHelper->getSettings($indexName);
232230

233231
$this->assertArrayHasKey('exactOnSingleWordQuery', $currentSettings);

Test/Integration/ProductsIndexingTest.php

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,54 +33,6 @@ public function testIncludingOutOfStock()
3333
$this->processTest($indexer, 'products', $this->assertValues->productsOutOfStockCount);
3434
}
3535

36-
public function testDefaultIndexableAttributes()
37-
{
38-
$empty = $this->getSerializer()->serialize([]);
39-
40-
$this->setConfig('algoliasearch_products/products/product_additional_attributes', $empty);
41-
$this->setConfig('algoliasearch_instant/instant/facets', $empty);
42-
$this->setConfig('algoliasearch_instant/instant/sorts', $empty);
43-
$this->setConfig('algoliasearch_products/products/custom_ranking_product_attributes', $empty);
44-
45-
/** @var Product $indexer */
46-
$indexer = $this->getObjectManager()->create(Product::class);
47-
$indexer->executeRow($this->getValidTestProduct());
48-
49-
$this->algoliaHelper->waitLastTask();
50-
51-
$results = $this->algoliaHelper->getObjects($this->indexPrefix . 'default_products', [$this->getValidTestProduct()]);
52-
$hit = reset($results['results']);
53-
54-
$defaultAttributes = [
55-
'objectID',
56-
'name',
57-
'url',
58-
'visibility_search',
59-
'visibility_catalog',
60-
'categories',
61-
'categories_without_path',
62-
'thumbnail_url',
63-
'image_url',
64-
'in_stock',
65-
'price',
66-
'type_id',
67-
'algoliaLastUpdateAtCET',
68-
'categoryIds',
69-
];
70-
71-
if (!$hit) {
72-
$this->markTestIncomplete('Hit was not returned correctly from Algolia. No Hit to run assetions on.');
73-
}
74-
75-
foreach ($defaultAttributes as $key => $attribute) {
76-
$this->assertArrayHasKey($attribute, $hit, 'Products attribute "' . $attribute . '" should be indexed but it is not"');
77-
unset($hit[$attribute]);
78-
}
79-
80-
$extraAttributes = implode(', ', array_keys($hit));
81-
$this->assertEmpty($hit, 'Extra products attributes (' . $extraAttributes . ') are indexed and should not be.');
82-
}
83-
8436
public function testNoSpecialPrice()
8537
{
8638
/** @var Product $indexer */
@@ -139,6 +91,54 @@ public function deprecatedTestSpecialPrice()
13991
$this->assertEquals($to, $algoliaProduct['price']['USD']['special_to_date']);
14092
}
14193

94+
public function testDefaultIndexableAttributes()
95+
{
96+
$empty = $this->getSerializer()->serialize([]);
97+
98+
$this->setConfig('algoliasearch_products/products/product_additional_attributes', $empty);
99+
$this->setConfig('algoliasearch_instant/instant_facets/facets', $empty);
100+
$this->setConfig('algoliasearch_instant/instant_sorts/sorts', $empty);
101+
$this->setConfig('algoliasearch_products/products/custom_ranking_product_attributes', $empty);
102+
103+
/** @var Product $indexer */
104+
$indexer = $this->getObjectManager()->create(Product::class);
105+
$indexer->executeRow($this->getValidTestProduct());
106+
107+
$this->algoliaHelper->waitLastTask();
108+
109+
$results = $this->algoliaHelper->getObjects($this->indexPrefix . 'default_products', [$this->getValidTestProduct()]);
110+
$hit = reset($results['results']);
111+
112+
$defaultAttributes = [
113+
'objectID',
114+
'name',
115+
'url',
116+
'visibility_search',
117+
'visibility_catalog',
118+
'categories',
119+
'categories_without_path',
120+
'thumbnail_url',
121+
'image_url',
122+
'in_stock',
123+
'price',
124+
'type_id',
125+
'algoliaLastUpdateAtCET',
126+
'categoryIds',
127+
];
128+
129+
if (!$hit) {
130+
$this->markTestIncomplete('Hit was not returned correctly from Algolia. No Hit to run assetions on.');
131+
}
132+
133+
foreach ($defaultAttributes as $key => $attribute) {
134+
$this->assertArrayHasKey($attribute, $hit, 'Products attribute "' . $attribute . '" should be indexed but it is not"');
135+
unset($hit[$attribute]);
136+
}
137+
138+
$extraAttributes = implode(', ', array_keys($hit));
139+
$this->assertEmpty($hit, 'Extra products attributes (' . $extraAttributes . ') are indexed and should not be.');
140+
}
141+
142142
private function setOneProductOutOfStock()
143143
{
144144
/** @var StockRegistry $stockRegistry */

Test/Integration/QueueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function testSettings()
145145
$this->resetConfigs([
146146
'algoliasearch_queue/queue/number_of_job_to_run',
147147
'algoliasearch_advanced/queue/number_of_element_by_page',
148-
'algoliasearch_instant/instant/facets',
148+
'algoliasearch_instant/instant_facets/facets',
149149
'algoliasearch_products/products/product_additional_attributes',
150150
]);
151151

Test/Integration/TestCase.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Algolia\AlgoliaSearch\Helper\AlgoliaHelper;
77
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
88
use Algolia\AlgoliaSearch\Setup\Patch\Schema\ConfigPatch;
9-
use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento23;
10-
use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento24;
9+
use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento246;
10+
use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento247;
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
1212
use Magento\Framework\App\ProductMetadataInterface;
1313
use Magento\Store\Model\ScopeInterface;
@@ -33,7 +33,7 @@ abstract class TestCase extends \TC
3333
/** @var ConfigHelper */
3434
protected $configHelper;
3535

36-
/** @var Magento23|Magento24 */
36+
/** @var Magento246|Magento247 */
3737
protected $assertValues;
3838

3939
public function setUp(): void
@@ -97,10 +97,10 @@ private function bootstrap()
9797
return;
9898
}
9999

100-
if (version_compare($this->getMagentoVersion(), '2.4.0', '<')) {
101-
$this->assertValues = new Magento23();
100+
if (version_compare($this->getMagentoVersion(), '2.4.7', '<')) {
101+
$this->assertValues = new Magento246();
102102
} else {
103-
$this->assertValues = new Magento24();
103+
$this->assertValues = new Magento247();
104104
}
105105

106106
$this->configHelper = $this->getObjectManager()->create(ConfigHelper::class);

0 commit comments

Comments
 (0)