From 693f044ef84ba8b33dba3b5de88ce3e07f6c20bd Mon Sep 17 00:00:00 2001 From: Fausto Quaggia Date: Mon, 8 Jul 2024 21:41:00 +0200 Subject: [PATCH] feat: index manager --- src/Manager/CloudManager.php | 2 +- src/Manager/IndexManager.php | 5 ++--- tests/Feature/IndexManagerTest.php | 12 ++++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Manager/CloudManager.php b/src/Manager/CloudManager.php index 2fa1dc4..d305d24 100644 --- a/src/Manager/CloudManager.php +++ b/src/Manager/CloudManager.php @@ -35,7 +35,7 @@ public function callIndexWebhook(string $endpoint, $payload = null) ] ]; - if ($payload) { + if (!is_null($payload)) { $config['body'] = json_encode($payload); } diff --git a/src/Manager/IndexManager.php b/src/Manager/IndexManager.php index ded951a..2db82df 100644 --- a/src/Manager/IndexManager.php +++ b/src/Manager/IndexManager.php @@ -49,8 +49,7 @@ public function deploy() public function hasPendingOperations() { - $response = $this->callIndexWebhook(Endpoints::HAS_DATA); - return property_exists($response, 'hasData') ? $response->hasData : false; + return $this->callIndexWebhook(Endpoints::HAS_DATA); } private function checkIndexID() @@ -60,7 +59,7 @@ private function checkIndexID() } } - private function callIndexWebhook($endpoint, $payload = []) + private function callIndexWebhook($endpoint, $payload = null) { $this->checkIndexID(); diff --git a/tests/Feature/IndexManagerTest.php b/tests/Feature/IndexManagerTest.php index 92e2293..57809cf 100644 --- a/tests/Feature/IndexManagerTest.php +++ b/tests/Feature/IndexManagerTest.php @@ -48,12 +48,12 @@ public function testShouldEmptyTheIndex() $lastRequest = end($this->capturedRequests); $this->assertEquals('POST', $lastRequest->getMethod()); $this->assertEquals('/api/v1/webhooks/mock-index/snapshot', $lastRequest->getUri()->getPath()); - $this->assertNull(json_decode($lastRequest->getBody()->getContents(), true)); + $this->assertEquals([], json_decode($lastRequest->getBody()->getContents(), true)); } public function testShouldInsertADocument() { - $data = ['id' => 1, 'name' => 'John Doe']; + $data = [['id' => 1, 'name' => 'John Doe']]; // Insert document $this->index->insert($data); $lastRequest = end($this->capturedRequests); @@ -64,7 +64,7 @@ public function testShouldInsertADocument() public function testShouldUpdateADocument() { - $data = ['id' => 1, 'name' => 'Jane Doe']; + $data = [['id' => 1, 'name' => 'Jane Doe']]; // Update document $this->index->update($data); $lastRequest = end($this->capturedRequests); @@ -76,16 +76,16 @@ public function testShouldUpdateADocument() public function testShouldDeleteADocument() { // Delete index - $this->index->delete(['id' => 1]); + $this->index->delete([['id' => 1]]); $lastRequest = end($this->capturedRequests); $this->assertEquals('POST', $lastRequest->getMethod()); $this->assertEquals('/api/v1/webhooks/mock-index/notify', $lastRequest->getUri()->getPath()); - $this->assertEquals(['remove' => ['id' => 1]], json_decode($lastRequest->getBody()->getContents(), true)); + $this->assertEquals(['remove' => [['id' => 1]]], json_decode($lastRequest->getBody()->getContents(), true)); } public function testShouldSnapshotTheIndex() { - $data = ['id' => 1, 'name' => 'John Doe']; + $data = [['id' => 1, 'name' => 'John Doe']]; // Snapshot index $this->index->snapshot($data); $lastRequest = end($this->capturedRequests);