Skip to content

Commit 6504e83

Browse files
committed
Add filtering by batchUid for getTasks
1 parent f1ca121 commit 6504e83

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/Contracts/TasksQuery.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class TasksQuery
2222
*/
2323
private ?array $canceledBy = null;
2424

25+
26+
/**
27+
* @var int|null
28+
*/
29+
private ?int $batchUid = null;
30+
2531
/**
2632
* @return $this
2733
*/
@@ -54,6 +60,16 @@ public function setLimit(int $limit): self
5460
return $this;
5561
}
5662

63+
/**
64+
* @return $this
65+
*/
66+
public function setBatchUid(int $batchUid): self
67+
{
68+
$this->batchUid = $batchUid;
69+
70+
return $this;
71+
}
72+
5773
public function toArray(): array
5874
{
5975
return array_filter(
@@ -63,8 +79,12 @@ public function toArray(): array
6379
'from' => $this->from,
6480
'limit' => $this->limit,
6581
'canceledBy' => $this->formatArray($this->canceledBy),
82+
'batchUid' => $this->batchUid,
6683
]
67-
), static function ($item) { return null !== $item; }
84+
),
85+
static function ($item) {
86+
return null !== $item;
87+
}
6888
);
6989
}
7090
}

tests/Endpoints/TasksTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ public function testGetAllTasksByIndexWithFilter(): void
126126
self::assertGreaterThan(0, $response->getTotal());
127127
}
128128

129+
public function getAllTasksByBatchFilter(): void
130+
{
131+
[$promise, $response] = $this->seedIndex();
132+
133+
self::assertIsArray($promise);
134+
$task = $this->client->getTask($promise['taskUid']);
135+
136+
$response = $this->client->getTasks((new TasksQuery())
137+
->setBatchUid($task['uid'])
138+
);
139+
140+
self::assertIsArray($response->getResults());
141+
}
142+
129143
public function testCancelTasksWithFilter(): void
130144
{
131145
$date = new \DateTime('yesterday');
@@ -135,7 +149,7 @@ public function testCancelTasksWithFilter(): void
135149
self::assertSame('taskCancelation', $promise['type']);
136150
$response = $this->client->waitForTask($promise['taskUid']);
137151

138-
self::assertSame('?'.$query, $response['details']['originalFilter']);
152+
self::assertSame('?' . $query, $response['details']['originalFilter']);
139153
self::assertSame('taskCancelation', $response['type']);
140154
self::assertSame('succeeded', $response['status']);
141155
}

0 commit comments

Comments
 (0)