Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Endpoints/Indexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ public function delete(): array

public function getTask($uid): array
{
return $this->http->get(self::PATH.'/'.$this->uid.'/tasks'.'/'.$uid);
return $this->http->get('/tasks/'.$uid, ['indexUid' => $this->uid]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the general issue it specified the following point:

Remove GET /indexes/:indexUid/tasks/:taskUid. Use GET /tasks/:taskUid instead.

So shouldn't it be something like

Suggested change
return $this->http->get('/tasks/'.$uid, ['indexUid' => $this->uid]);
return $this->http->get('/tasks'.'/'.$uid);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better you can use the one from the client maybe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alallema is there any particular reason to suggest:

('/tasks'.'/'.$uid);

instead of:

('/tasks/'.$uid);

}

public function getTasks(): array
{
return $this->http->get(self::PATH.'/'.$this->uid.'/tasks');
return $this->http->get('/tasks', ['indexUid' => $this->uid]);
}

// Search
Expand Down
8 changes: 4 additions & 4 deletions tests/Endpoints/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function testUpdateIndex(): void
$this->createEmptyIndex('indexA');

$response = $this->client->updateIndex('indexA', ['primaryKey' => 'id']);
$this->client->waitForTask($response['uid']);
$this->client->waitForTask($response['taskUid']);
$index = $this->client->getIndex($response['indexUid']);

$this->assertSame($index->getPrimaryKey(), 'id');
Expand All @@ -147,7 +147,7 @@ public function testDeleteIndex(): void
$this->assertCount(1, $response);

$response = $this->client->deleteIndex('index');
$this->client->waitForTask($response['uid']);
$this->client->waitForTask($response['taskUid']);

$this->expectException(ApiException::class);
$index = $this->client->getIndex('index');
Expand All @@ -170,7 +170,7 @@ public function testDeleteAllIndexes(): void
$res = $this->client->deleteAllIndexes();

$taskUids = array_map(function ($task) {
return $task['uid'];
return $task['uid'] ?? $task['taskUid'];
}, $res);
$res = $this->client->waitForTasks($taskUids);

Expand All @@ -186,7 +186,7 @@ public function testDeleteAllIndexesWhenThereAreNoIndexes(): void

$res = $this->client->deleteAllIndexes();
$taskUids = array_map(function ($task) {
return $task['uid'];
return $task['uid'] ?? $task['taskUid'];
}, $res);
$this->client->waitForTasks($taskUids);

Expand Down
62 changes: 31 additions & 31 deletions tests/Endpoints/DocumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testAddDocuments(): void

$this->assertIsValidPromise($promise);

$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);

$response = $index->getDocuments();
$this->assertCount(\count(self::DOCUMENTS), $response);
Expand All @@ -33,7 +33,7 @@ public function testAddDocumentsInBatches(): void

foreach ($promises as $promise) {
$this->assertIsValidPromise($promise);
$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);
}

$response = $index->getDocuments();
Expand All @@ -52,7 +52,7 @@ public function testAddDocumentWithSpecialChars(): void
$promise = $index->addDocuments($documents);

$this->assertIsValidPromise($promise);
$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);

$response = $index->getDocuments();
$this->assertCount(\count($documents), $response);
Expand All @@ -75,7 +75,7 @@ public function testAddDocumentsCsv(): void

$this->assertIsValidPromise($promise);

$update = $index->waitForTask($promise['uid']);
$update = $index->waitForTask($promise['taskUid']);

$this->assertEquals($update['status'], 'succeeded');
$this->assertNotEquals($update['details']['receivedDocuments'], 0);
Expand All @@ -96,7 +96,7 @@ public function testAddDocumentsJson(): void

$this->assertIsValidPromise($promise);

$update = $index->waitForTask($promise['uid']);
$update = $index->waitForTask($promise['taskUid']);

$this->assertEquals($update['status'], 'succeeded');
$this->assertNotEquals($update['details']['receivedDocuments'], 0);
Expand All @@ -117,7 +117,7 @@ public function testAddDocumentsNdJson(): void

$this->assertIsValidPromise($promise);

$update = $index->waitForTask($promise['uid']);
$update = $index->waitForTask($promise['taskUid']);

$this->assertEquals($update['status'], 'succeeded');
$this->assertNotEquals($update['details']['receivedDocuments'], 0);
Expand All @@ -141,7 +141,7 @@ public function testGetSingleDocumentWithIntegerDocumentId(): void
{
$index = $this->createEmptyIndex('documents');
$response = $index->addDocuments(self::DOCUMENTS);
$index->waitForTask($response['uid']);
$index->waitForTask($response['taskUid']);
$doc = $this->findDocumentWithId(self::DOCUMENTS, 4);
$response = $index->getDocument($doc['id']);

Expand All @@ -155,7 +155,7 @@ public function testGetSingleDocumentWithStringDocumentId(): void
$stringDocumentId = 'myUniqueId';
$index = $this->createEmptyIndex('documents');
$addDocumentResponse = $index->addDocuments([['id' => $stringDocumentId]]);
$index->waitForTask($addDocumentResponse['uid']);
$index->waitForTask($addDocumentResponse['taskUid']);
$response = $index->getDocument($stringDocumentId);

$this->assertIsArray($response);
Expand All @@ -166,7 +166,7 @@ public function testReplaceDocuments(): void
{
$index = $this->createEmptyIndex('documents');
$response = $index->addDocuments(self::DOCUMENTS);
$index->waitForTask($response['uid']);
$index->waitForTask($response['taskUid']);
$replacement = [
'id' => 2,
'title' => 'The Red And The Black',
Expand All @@ -175,7 +175,7 @@ public function testReplaceDocuments(): void

$this->assertIsValidPromise($response);

$index->waitForTask($response['uid']);
$index->waitForTask($response['taskUid']);
$response = $index->getDocument($replacement['id']);

$this->assertSame($replacement['id'], $response['id']);
Expand All @@ -189,7 +189,7 @@ public function testUpdateDocuments(): void
{
$index = $this->createEmptyIndex('documents');
$promise = $index->addDocuments(self::DOCUMENTS);
$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);
$replacement = [
'id' => 456,
'title' => 'The Little Prince',
Expand All @@ -198,7 +198,7 @@ public function testUpdateDocuments(): void

$this->assertIsValidPromise($promise);

$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);
$response = $index->getDocument($replacement['id']);

$this->assertSame($replacement['id'], $response['id']);
Expand All @@ -214,7 +214,7 @@ public function testUpdateDocumentsInBatches(): void
{
$index = $this->createEmptyIndex('documents');
$documentPromise = $index->addDocuments(self::DOCUMENTS);
$index->waitForTask($documentPromise['uid']);
$index->waitForTask($documentPromise['taskUid']);

$replacements = [
['id' => 1, 'title' => 'Alice Outside Wonderland'],
Expand All @@ -229,7 +229,7 @@ public function testUpdateDocumentsInBatches(): void

foreach ($promises as $promise) {
$this->assertIsValidPromise($promise);
$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);
}

foreach ($replacements as $replacement) {
Expand All @@ -247,7 +247,7 @@ public function testAddWithUpdateDocuments(): void
{
$index = $this->createEmptyIndex('documents');
$response = $index->addDocuments(self::DOCUMENTS);
$index->waitForTask($response['uid']);
$index->waitForTask($response['taskUid']);
$document = [
'id' => 9,
'title' => '1984',
Expand All @@ -256,7 +256,7 @@ public function testAddWithUpdateDocuments(): void

$this->assertIsValidPromise($promise);

$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);
$response = $index->getDocument($document['id']);

$this->assertSame($document['id'], $response['id']);
Expand All @@ -272,14 +272,14 @@ public function testDeleteNonExistingDocument(): void
{
$index = $this->createEmptyIndex('documents');
$response = $index->addDocuments(self::DOCUMENTS);
$index->waitForTask($response['uid']);
$index->waitForTask($response['taskUid']);

$documentId = 9;
$promise = $index->deleteDocument($documentId);

$this->assertIsValidPromise($promise);

$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);
$response = $index->getDocuments();

$this->assertCount(\count(self::DOCUMENTS), $response);
Expand All @@ -290,14 +290,14 @@ public function testDeleteSingleExistingDocumentWithDocumentIdAsInteger(): void
{
$index = $this->createEmptyIndex('documents');
$response = $index->addDocuments(self::DOCUMENTS);
$index->waitForTask($response['uid']);
$index->waitForTask($response['taskUid']);

$documentId = 123;
$promise = $index->deleteDocument($documentId);

$this->assertIsValidPromise($promise);

$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);
$response = $index->getDocuments();

$this->assertCount(\count(self::DOCUMENTS) - 1, $response);
Expand All @@ -309,10 +309,10 @@ public function testDeleteSingleExistingDocumentWithDocumentIdAsString(): void
$stringDocumentId = 'myUniqueId';
$index = $this->createEmptyIndex('documents');
$addDocumentResponse = $index->addDocuments([['id' => $stringDocumentId]]);
$index->waitForTask($addDocumentResponse['uid']);
$index->waitForTask($addDocumentResponse['taskUid']);

$promise = $index->deleteDocument($stringDocumentId);
$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);

$response = $index->getDocuments();

Expand All @@ -323,13 +323,13 @@ public function testDeleteMultipleDocumentsWithDocumentIdAsInteger(): void
{
$index = $this->createEmptyIndex('documents');
$response = $index->addDocuments(self::DOCUMENTS);
$index->waitForTask($response['uid']);
$index->waitForTask($response['taskUid']);
$documentIds = [1, 2];
$promise = $index->deleteDocuments($documentIds);

$this->assertIsValidPromise($promise);

$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);
$response = $index->getDocuments();

$this->assertCount(\count(self::DOCUMENTS) - 2, $response);
Expand All @@ -346,10 +346,10 @@ public function testDeleteMultipleDocumentsWithDocumentIdAsString(): void
];
$index = $this->createEmptyIndex('documents');
$addDocumentResponse = $index->addDocuments($documents);
$index->waitForTask($addDocumentResponse['uid']);
$index->waitForTask($addDocumentResponse['taskUid']);

$promise = $index->deleteDocuments(['myUniqueId1', 'myUniqueId3']);
$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);

$response = $index->getDocuments();
$this->assertCount(1, $response);
Expand All @@ -360,12 +360,12 @@ public function testDeleteAllDocuments(): void
{
$index = $this->createEmptyIndex('documents');
$response = $index->addDocuments(self::DOCUMENTS);
$index->waitForTask($response['uid']);
$index->waitForTask($response['taskUid']);
$promise = $index->deleteAllDocuments();

$this->assertIsValidPromise($promise);

$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);
$response = $index->getDocuments();

$this->assertCount(0, $response);
Expand All @@ -392,8 +392,8 @@ public function testAddDocumentWithPrimaryKey(): void
$index = $this->createEmptyIndex('an-index');
$response = $index->addDocuments($documents, 'unique');

$this->assertArrayHasKey('uid', $response);
$index->waitForTask($response['uid']);
$this->assertArrayHasKey('taskUid', $response);
$index->waitForTask($response['taskUid']);

$this->assertSame('unique', $index->fetchPrimaryKey());
$this->assertCount(1, $index->getDocuments());
Expand All @@ -413,7 +413,7 @@ public function testUpdateDocumentWithPrimaryKey(): void

$this->assertIsValidPromise($promise);

$index->waitForTask($promise['uid']);
$index->waitForTask($promise['taskUid']);

$this->assertSame('unique', $index->fetchPrimaryKey());
$this->assertCount(1, $index->getDocuments());
Expand Down
14 changes: 7 additions & 7 deletions tests/Endpoints/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function testPrimaryKeyUpdate(): void
$primaryKey = 'id';

$response = $this->index->update(['primaryKey' => $primaryKey]);
$this->client->waitForTask($response['uid']);
$this->client->waitForTask($response['taskUid']);
$index = $this->client->getIndex($response['indexUid']);

$this->assertSame($index->getPrimaryKey(), $primaryKey);
Expand Down Expand Up @@ -171,12 +171,12 @@ public function testWaitForTaskDefault(): void
{
$promise = $this->index->addDocuments([['id' => 1, 'title' => 'Pride and Prejudice']]);

$response = $this->index->waitForTask($promise['uid']);
$response = $this->index->waitForTask($promise['taskUid']);

/* @phpstan-ignore-next-line */
$this->assertIsArray($response);
$this->assertSame($response['status'], 'succeeded');
$this->assertSame($response['uid'], $promise['uid']);
$this->assertSame($response['uid'], $promise['taskUid']);
$this->assertArrayHasKey('type', $response);
$this->assertSame($response['type'], 'documentAddition');
$this->assertArrayHasKey('duration', $response);
Expand All @@ -187,10 +187,10 @@ public function testWaitForTaskDefault(): void
public function testWaitForTaskWithTimeoutAndInterval(): void
{
$promise = $this->index->addDocuments([['id' => 1, 'title' => 'Pride and Prejudice']]);
$response = $this->index->waitForTask($promise['uid'], 100, 20);
$response = $this->index->waitForTask($promise['taskUid'], 100, 20);

$this->assertSame($response['status'], 'succeeded');
$this->assertSame($response['uid'], $promise['uid']);
$this->assertSame($response['uid'], $promise['taskUid']);
$this->assertArrayHasKey('type', $response);
$this->assertSame($response['type'], 'documentAddition');
$this->assertArrayHasKey('duration', $response);
Expand All @@ -202,10 +202,10 @@ public function testWaitForTaskWithTimeoutAndInterval(): void
public function testWaitForTaskWithTimeout(): void
{
$promise = $this->index->addDocuments([['id' => 1, 'title' => 'Pride and Prejudice']]);
$response = $this->index->waitForTask($promise['uid'], 100);
$response = $this->index->waitForTask($promise['taskUid'], 100);

$this->assertSame($response['status'], 'succeeded');
$this->assertSame($response['uid'], $promise['uid']);
$this->assertSame($response['uid'], $promise['taskUid']);
$this->assertArrayHasKey('type', $response);
$this->assertSame($response['type'], 'documentAddition');
$this->assertArrayHasKey('duration', $response);
Expand Down
Loading