Skip to content

Commit ef54fbe

Browse files
committed
[internal-api-client] Fix search grouped jobs response structure
1 parent c3e49b7 commit ef54fbe

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/Client.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,10 @@ public function searchAllJobs(
386386
* @param "asc"|"desc"|null $sortOrder
387387
* @param int<1, 500>|null $jobsPerGroup
388388
* @param int<1, 500>|null $limit
389-
* @return array<JobInterface>
389+
* @return array<int, array{
390+
* group: array<string, string>,
391+
* jobs: JobInterface[]
392+
* }>
390393
*/
391394
public function searchJobsGrouped(
392395
array $groupBy,
@@ -416,9 +419,20 @@ public function searchJobsGrouped(
416419
}
417420

418421
$request = new Request('GET', 'search/grouped-jobs?' . http_build_query($query));
422+
/** @var array<int, array{
423+
* group: array<string, string>,
424+
* jobs: array
425+
* }> $response
426+
*/
419427
$response = $this->sendRequest($request);
420428

421-
return $this->mapJobsFromSearchResponse($response);
429+
return array_map(
430+
function (array $group): array {
431+
$group['jobs'] = $this->mapJobsFromSearchResponse($group['jobs']);
432+
return $group;
433+
},
434+
$response,
435+
);
422436
}
423437

424438
/** @return JobInterface[] */

tests/ClientSearchTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,28 @@ public function testSearchJobsGrouped(
231231
$requests = [];
232232
$responses = [
233233
new Response(200, body: (string) json_encode([
234-
$this->createJobData(1),
235-
$this->createJobData(2),
234+
[
235+
'group' => array_fill_keys($groupBy, true),
236+
'jobs' => [
237+
$this->createJobData(1),
238+
$this->createJobData(2),
239+
],
240+
],
236241
])),
237242
];
238243

239244
$client = $this->createClient($requests, $responses);
240-
$jobs = $client->searchJobsGrouped($groupBy, $filters, $sortBy, $sortOrder, $jobsPerGroup, $limit);
245+
$jobsGrouped = $client->searchJobsGrouped($groupBy, $filters, $sortBy, $sortOrder, $jobsPerGroup, $limit);
241246

247+
$jobs = $jobsGrouped[0]['jobs'];
242248
self::assertCount(2, $jobs);
243249
self::assertSame('1', $jobs[0]->getId());
244250
self::assertSame('2', $jobs[1]->getId());
245251

252+
$groups = $jobsGrouped[0]['group'];
253+
self::assertCount(count($groupBy), $groups);
254+
self::assertSame($groupBy, array_keys($groups));
255+
246256
self::assertCount(1, $requests);
247257
$request = $requests[0]['request'];
248258

0 commit comments

Comments
 (0)