From baeab8d28553da1be0829fdf65acb7f142cc1555 Mon Sep 17 00:00:00 2001 From: Simon Erkelens Date: Fri, 20 Oct 2023 21:53:47 +1300 Subject: [PATCH] Add check for Synonyms being pushed/deleted in Elastic --- composer.json | 5 -- src/Tasks/ElasticIndexTask.php | 7 --- .../ElasticSynonymExtensionTest.php | 50 +++++++++++++++++++ 3 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 tests/unit/Extensions/ElasticSynonymExtensionTest.php diff --git a/composer.json b/composer.json index b3e01fa..32b18ef 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,6 @@ "email": "github@casa-laguna.net", "homepage": "https://firesphere.dev", "role": "Lead developer" - }, - { - "name": "Marco `Sheepy` Hermo", - "email": "marco@silverstripe.com", - "role": "Lead developer" } ], "require": { diff --git a/src/Tasks/ElasticIndexTask.php b/src/Tasks/ElasticIndexTask.php index b0ffa81..c7f4a32 100644 --- a/src/Tasks/ElasticIndexTask.php +++ b/src/Tasks/ElasticIndexTask.php @@ -227,11 +227,6 @@ public function getGroups(): int return $this->groups; } - public function setGroups(int $groups): void - { - $this->groups = $groups; - } - /** * Index a single class for a given index. {@link static::indexClassForIndex()} * @@ -239,8 +234,6 @@ public function setGroups(int $groups): void * @param string $class Class to index * @param int $group Group to index * @return int|bool - * @throws HTTPException - * @throws ValidationException */ private function indexClass(bool $isGroup, string $class, int $group) { diff --git a/tests/unit/Extensions/ElasticSynonymExtensionTest.php b/tests/unit/Extensions/ElasticSynonymExtensionTest.php new file mode 100644 index 0000000..78d2456 --- /dev/null +++ b/tests/unit/Extensions/ElasticSynonymExtensionTest.php @@ -0,0 +1,50 @@ +requireDefaultRecords(); + /** @var SynonymSet $set */ + $set = SynonymSet::get()->first(); + /** @var SearchSynonym $synonym */ + $synonym = SearchSynonym::create(['Keyword' => 'Simon', 'Synonym' => 'Firesphere']); + $extension = new ElasticSynonymExtension(); + $extension->setOwner($synonym); + + $synonym->write(); + $extension->onAfterWrite(); + + /** @var Client $client */ + $client = Injector::inst()->get(ElasticCoreService::class)->getClient(); + $synonymCheck = $client->synonyms()->getSynonymRule([ + 'set_id' => $set->Key, + 'rule_id' => $synonym->getModifiedID() + ]); + + $check = $synonymCheck->asArray(); + + $this->assertEquals(['id' => $set->Key, 'synonyms' => $synonym->getCombinedSynonym()], $check); + + $synonym->onAfterDelete(); + $extension->onAfterDelete(); + $synonymCheck = $client->synonyms()->getSynonymRule([ + 'set_id' => $set->Key, + 'rule_id' => $synonym->getModifiedID() + ]); + + $this->assertEquals(404, $synonymCheck->getStatusCode()); + + } +}