diff --git a/src/Contracts/DeleteTasksQuery.php b/src/Contracts/DeleteTasksQuery.php new file mode 100644 index 000000000..d9416f6c7 --- /dev/null +++ b/src/Contracts/DeleteTasksQuery.php @@ -0,0 +1,12 @@ +tasks->deleteTasks($options); + } + public function cancelTasks(CancelTasksQuery $options = null): array { return $this->tasks->cancelTasks($options); diff --git a/src/Endpoints/Tasks.php b/src/Endpoints/Tasks.php index 2b98cd53a..aa52e2e18 100644 --- a/src/Endpoints/Tasks.php +++ b/src/Endpoints/Tasks.php @@ -5,6 +5,7 @@ namespace MeiliSearch\Endpoints; use MeiliSearch\Contracts\CancelTasksQuery; +use MeiliSearch\Contracts\DeleteTasksQuery; use MeiliSearch\Contracts\Endpoint; use MeiliSearch\Exceptions\TimeOutException; @@ -30,6 +31,14 @@ public function cancelTasks(?CancelTasksQuery $options): array return $response; } + public function deleteTasks(?DeleteTasksQuery $options): array + { + $options = $options ?? new DeleteTasksQuery(); + $response = $this->http->delete(self::PATH, $options->toArray()); + + return $response; + } + /** * @throws TimeOutException */ diff --git a/tests/Contracts/DeleteTasksQueryTest.php b/tests/Contracts/DeleteTasksQueryTest.php new file mode 100644 index 000000000..e5f6c0eee --- /dev/null +++ b/tests/Contracts/DeleteTasksQueryTest.php @@ -0,0 +1,49 @@ +setTypes(['abc', 'xyz']); + + $this->assertEquals($data->toArray(), ['types' => 'abc,xyz']); + } + + public function testSetNext(): void + { + $data = (new TasksQuery())->setNext(99); + + $this->assertEquals($data->toArray(), ['next' => 99]); + } + + public function testSetAnyDateFilter(): void + { + $date = new \DateTime(); + $data = (new TasksQuery())->setBeforeEnqueuedAt($date); + + $this->assertEquals($data->toArray(), ['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)]); + } + + public function testToArrayWithSetNextWithZero(): void + { + $data = (new TasksQuery())->setNext(0); + + $this->assertEquals($data->toArray(), ['next' => 0]); + } + + public function testToArrayWithDifferentSets(): void + { + $data = (new TasksQuery())->setFrom(10)->setLimit(9)->setNext(99)->setStatuses(['enqueued']); + + $this->assertEquals($data->toArray(), [ + 'limit' => 9, 'next' => 99, 'from' => 10, 'statuses' => 'enqueued', + ]); + } +} diff --git a/tests/Endpoints/IndexTest.php b/tests/Endpoints/IndexTest.php index ae60deba2..d91b53730 100644 --- a/tests/Endpoints/IndexTest.php +++ b/tests/Endpoints/IndexTest.php @@ -4,6 +4,7 @@ namespace Tests\Endpoints; +use MeiliSearch\Contracts\DeleteTasksQuery; use MeiliSearch\Contracts\TasksQuery; use MeiliSearch\Endpoints\Indexes; use MeiliSearch\Exceptions\TimeOutException; @@ -276,6 +277,15 @@ public function testSwapIndexes(): void $this->assertSame($response['details']['swaps'], [['indexes' => ['indexA', 'indexB']], ['indexes' => ['indexC', 'indexD']]]); } + public function testDeleteTasks(): void + { + $promise = $this->client->deleteTasks((new DeleteTasksQuery())->setUids([1, 2])); + $response = $this->client->waitForTask($promise['taskUid']); + + $this->assertSame($response['details']['originalFilter'], '?uids=1%2C2'); + $this->assertIsNumeric($response['details']['matchedTasks']); + } + public function testParseDate(): void { $date = '2021-01-01T01:23:45.123456Z';