Skip to content

Commit

Permalink
feat: index manager
Browse files Browse the repository at this point in the history
  • Loading branch information
faustoq committed Jul 8, 2024
1 parent a5d4369 commit 693f044
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Manager/CloudManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function callIndexWebhook(string $endpoint, $payload = null)
]
];

if ($payload) {
if (!is_null($payload)) {
$config['body'] = json_encode($payload);
}

Expand Down
5 changes: 2 additions & 3 deletions src/Manager/IndexManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -60,7 +59,7 @@ private function checkIndexID()
}
}

private function callIndexWebhook($endpoint, $payload = [])
private function callIndexWebhook($endpoint, $payload = null)
{
$this->checkIndexID();

Expand Down
12 changes: 6 additions & 6 deletions tests/Feature/IndexManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 693f044

Please sign in to comment.