Skip to content

Commit d3d00d2

Browse files
committed
MAGE-1044 Test ranking on replica sync command
1 parent e420ed3 commit d3d00d2

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

Test/Integration/Product/ReplicaIndexingTest.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testStandardReplicaConfig(): void
6565
$this->assertFalse($this->isVirtualReplica($currentSettings['replicas'], $sortIndexName));
6666

6767
$replicaSettings = $this->assertReplicaIndexExists($indexName, $sortIndexName);
68-
$this->assertStandardReplicaRanking($replicaSettings, $sortAttr, $sortDir);
68+
$this->assertStandardReplicaRanking($replicaSettings, "$sortDir($sortAttr)");
6969
}
7070

7171
/**
@@ -119,7 +119,7 @@ public function testVirtualReplicaConfig(): void
119119

120120
// Assert replica index created
121121
$replicaSettings = $this->assertReplicaIndexExists($indexName, $sortIndexName);
122-
$this->assertVirtualReplicaRanking($replicaSettings, $sortAttr, $sortDir);
122+
$this->assertVirtualReplicaRanking($replicaSettings, "$sortDir($sortAttr)");
123123

124124
// Restore prior state (for this test only)
125125
$this->configHelper->setSorting($ogSortingState);
@@ -184,26 +184,33 @@ public function testReplicaSync(): void
184184
$this->mockProperty($cmd, 'output', \Symfony\Component\Console\Output\OutputInterface::class);
185185

186186
$cmd->syncReplicas();
187+
$this->algoliaHelper->waitLastTask();
187188

188189
$currentSettings = $this->algoliaHelper->getSettings($indexName);
189190
$this->assertArrayHasKey('replicas', $currentSettings);
190191
$replicas = $currentSettings['replicas'];
191192

192193
$this->assertEquals(count($sorting), count($replicas));
193-
$this->assertSortToReplicaConfigParity($sorting, $replicas);
194-
195-
// TODO: Test ranking
196-
194+
$this->assertSortToReplicaConfigParity($indexName, $sorting, $replicas);
197195
}
198196

199-
protected function assertSortToReplicaConfigParity(array $sorting, array $replicas): void
197+
protected function assertSortToReplicaConfigParity(string $primaryIndexName, array $sorting, array $replicas): void
200198
{
201199
foreach ($sorting as $sortAttr) {
202200
$replicaIndexName = $sortAttr['name'];
203-
$needle = array_key_exists('virtualReplica', $sortAttr) && $sortAttr['virtualReplica']
201+
$isVirtual = array_key_exists('virtualReplica', $sortAttr) && $sortAttr['virtualReplica'];
202+
$needle = $isVirtual
204203
? "virtual($replicaIndexName)"
205204
: $replicaIndexName;
206205
$this->assertContains($needle, $replicas);
206+
207+
$replicaSettings = $this->assertReplicaIndexExists($primaryIndexName, $replicaIndexName);
208+
$sort = reset($sortAttr['ranking']);
209+
if ($isVirtual) {
210+
$this->assertVirtualReplicaRanking($replicaSettings, $sort);
211+
} else {
212+
$this->assertStandardReplicaRanking($replicaSettings, $sort);
213+
}
207214
}
208215
}
209216

@@ -215,13 +222,28 @@ protected function assertReplicaIndexExists(string $primaryIndexName, string $re
215222
return $replicaSettings;
216223
}
217224

218-
protected function assertStandardReplicaRanking(array $replicaSettings, string $sortAttr, string $sortDir): void
225+
protected function assertReplicaRanking(array $replicaSettings, string $rankingKey, string $sort) {
226+
$this->assertArrayHasKey($rankingKey, $replicaSettings);
227+
$this->assertEquals($sort, reset($replicaSettings[$rankingKey]));
228+
}
229+
230+
protected function assertStandardReplicaRanking(array $replicaSettings, string $sort): void
231+
{
232+
$this->assertReplicaRanking($replicaSettings, 'ranking', $sort);
233+
}
234+
235+
protected function assertVirtualReplicaRanking(array $replicaSettings, string $sort): void
236+
{
237+
$this->assertReplicaRanking($replicaSettings, 'customRanking', $sort);
238+
}
239+
240+
protected function assertStandardReplicaRankingOld(array $replicaSettings, string $sortAttr, string $sortDir): void
219241
{
220242
$this->assertArrayHasKey('ranking', $replicaSettings);
221243
$this->assertEquals("$sortDir($sortAttr)", array_shift($replicaSettings['ranking']));
222244
}
223245

224-
protected function assertVirtualReplicaRanking(array $replicaSettings, string $sortAttr, string $sortDir): void
246+
protected function assertVirtualReplicaRankingOld(array $replicaSettings, string $sortAttr, string $sortDir): void
225247
{
226248
$this->assertArrayHasKey('customRanking', $replicaSettings);
227249
$this->assertEquals("$sortDir($sortAttr)", array_shift($replicaSettings['customRanking']));

0 commit comments

Comments
 (0)