Skip to content

Commit ba385e2

Browse files
authored
Merge pull request #418 from keboola/jv-PST-1724-internal-api-client
[internal-api-client] Add search methods sending raw query
2 parents f0c37e5 + 7f9abe1 commit ba385e2

File tree

4 files changed

+149
-4
lines changed

4 files changed

+149
-4
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
parameters:
22
level: max
3-
checkMissingIterableValueType: false
43
paths:
54
- src
65
- tests
76
ignoreErrors:
7+
- identifier: missingType.iterableValue
88
- '#Cannot call method scalarNode\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.#'
99
- '#Cannot call method arrayNode\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.#'

src/Client.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,13 @@ public function searchJobs(
351351
$query['limit'] = $limit;
352352
}
353353

354-
$request = new Request('GET', 'search/jobs?' . http_build_query($query));
354+
return $this->searchJobsRaw($query);
355+
}
356+
357+
/** @return JobInterface[] */
358+
public function searchJobsRaw(array $rawQuery): array
359+
{
360+
$request = new Request('GET', 'search/jobs?' . http_build_query($rawQuery));
355361
$response = $this->sendRequest($request);
356362

357363
return $this->mapJobsFromSearchResponse($response);
@@ -418,10 +424,22 @@ public function searchJobsGrouped(
418424
$query['limit'] = $limit;
419425
}
420426

427+
return $this->searchJobsGroupedRaw($query);
428+
}
429+
430+
/**
431+
* @return array<int, array{
432+
* group: array<string, string>,
433+
* jobs: JobInterface[]
434+
* }>
435+
*/
436+
public function searchJobsGroupedRaw(array $query): array
437+
{
421438
$request = new Request('GET', 'search/grouped-jobs?' . http_build_query($query));
422-
/** @var array<int, array{
439+
/**
440+
* @var array<int, array{
423441
* group: array<string, string>,
424-
* jobs: array
442+
* jobs: JobInterface[]
425443
* }> $response
426444
*/
427445
$response = $this->sendRequest($request);

tests/ClientFunctionalTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,16 @@ public function testSearchJobs(): void
11431143
$client->searchJobs();
11441144
}
11451145

1146+
public function testSearchJobsRaw(): void
1147+
{
1148+
// real functional tests for search would quite complicate as it would require setting up full internal API
1149+
// with logstash replication + a way to truncate the index between tests
1150+
// instead we test just that endpoint can be called, does not fail and filters are covered by unit test
1151+
1152+
$client = $this->getClient();
1153+
$client->searchJobsRaw([]);
1154+
}
1155+
11461156
public function testSearchJobsGrouped(): void
11471157
{
11481158
// real functional tests for search would quite complicate as it would require setting up full internal API
@@ -1152,4 +1162,14 @@ public function testSearchJobsGrouped(): void
11521162
$client = $this->getClient();
11531163
$client->searchJobsGrouped(groupBy: ['componentId']);
11541164
}
1165+
1166+
public function testSearchJobsGroupedRaw(): void
1167+
{
1168+
// real functional tests for search would quite complicate as it would require setting up full internal API
1169+
// with logstash replication + a way to truncate the index between tests
1170+
// instead we test just that endpoint can be called, does not fail and filters are covered by unit test
1171+
1172+
$client = $this->getClient();
1173+
$client->searchJobsGroupedRaw(['groupBy' => ['componentId']]);
1174+
}
11551175
}

tests/ClientSearchTest.php

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,113 @@ public function testSearchAllJobs(): void
313313
);
314314
}
315315

316+
public function testSearchJobsRawQueryParametersPropagation(): void
317+
{
318+
$requests = [];
319+
$responses = [new Response(body: '[]')];
320+
321+
$client = $this->createClient($requests, $responses);
322+
$client->searchJobsRaw([
323+
'sortBy' => '1',
324+
'sortOrder' => '1',
325+
'offset' => '1',
326+
'limit' => '1',
327+
'filters' => [
328+
'id' => ['1'],
329+
'runId' => ['1'],
330+
'branchId' => ['1'],
331+
'configId' => ['1'],
332+
'configRowIds' => ['1'],
333+
'projectId' => ['1'],
334+
'tokenId' => ['1'],
335+
'tokenDescription' => ['1'],
336+
'componentId' => ['1'],
337+
'status' => ['1'],
338+
'desiredStatus' => ['1'],
339+
'mode' => ['1'],
340+
'tag' => ['1'],
341+
'startTimeFrom' => '1',
342+
'startTimeTo' => '1',
343+
'createdTimeFrom' => '1',
344+
'createdTimeTo' => '1',
345+
'endTimeFrom' => '1',
346+
'endTimeTo' => '1',
347+
'durationSecondsFrom' => '1',
348+
'durationSecondsTo' => '1',
349+
'variableValuesId' => ['1'],
350+
'parentRunId' => ['1'],
351+
'type' => ['1'],
352+
],
353+
]);
354+
355+
self::assertSame(
356+
'sortBy=1&sortOrder=1&offset=1&limit=1&filters%5Bid%5D%5B0%5D=1&' .
357+
'filters%5BrunId%5D%5B0%5D=1&filters%5BbranchId%5D%5B0%5D=1&filters%5BconfigId%5D%5B0%5D=1&' .
358+
'filters%5BconfigRowIds%5D%5B0%5D=1&filters%5BprojectId%5D%5B0%5D=1&filters%5BtokenId%5D%5B0%5D=1&' .
359+
'filters%5BtokenDescription%5D%5B0%5D=1&filters%5BcomponentId%5D%5B0%5D=1&filters%5Bstatus%5D%5B0%5D=1&' .
360+
'filters%5BdesiredStatus%5D%5B0%5D=1&filters%5Bmode%5D%5B0%5D=1&filters%5Btag%5D%5B0%5D=1&' .
361+
'filters%5BstartTimeFrom%5D=1&filters%5BstartTimeTo%5D=1&filters%5BcreatedTimeFrom%5D=1&' .
362+
'filters%5BcreatedTimeTo%5D=1&filters%5BendTimeFrom%5D=1&filters%5BendTimeTo%5D=1&' .
363+
'filters%5BdurationSecondsFrom%5D=1&filters%5BdurationSecondsTo%5D=1&' .
364+
'filters%5BvariableValuesId%5D%5B0%5D=1&filters%5BparentRunId%5D%5B0%5D=1&filters%5Btype%5D%5B0%5D=1',
365+
$requests[0]['request']->getUri()->getQuery(),
366+
);
367+
}
368+
369+
public function testSearchJobsGroupedRawQueryParametersPropagation(): void
370+
{
371+
$requests = [];
372+
$responses = [new Response(body: '[]')];
373+
374+
$client = $this->createClient($requests, $responses);
375+
$client->searchJobsGroupedRaw([
376+
'sortBy' => '1',
377+
'sortOrder' => '1',
378+
'jobsPerGroup' => '1',
379+
'limit' => '1',
380+
'groupBy' => ['1'],
381+
'filters' => [
382+
'id' => ['1'],
383+
'runId' => ['1'],
384+
'branchId' => ['1'],
385+
'configId' => ['1'],
386+
'configRowIds' => ['1'],
387+
'projectId' => ['1'],
388+
'tokenId' => ['1'],
389+
'tokenDescription' => ['1'],
390+
'componentId' => ['1'],
391+
'status' => ['1'],
392+
'desiredStatus' => ['1'],
393+
'mode' => ['1'],
394+
'tag' => ['1'],
395+
'startTimeFrom' => '1',
396+
'startTimeTo' => '1',
397+
'createdTimeFrom' => '1',
398+
'createdTimeTo' => '1',
399+
'endTimeFrom' => '1',
400+
'endTimeTo' => '1',
401+
'durationSecondsFrom' => '1',
402+
'durationSecondsTo' => '1',
403+
'variableValuesId' => ['1'],
404+
'parentRunId' => ['1'],
405+
'type' => ['1'],
406+
],
407+
]);
408+
409+
self::assertSame(
410+
'sortBy=1&sortOrder=1&jobsPerGroup=1&limit=1&groupBy%5B0%5D=1&filters%5Bid%5D%5B0%5D=1&' .
411+
'filters%5BrunId%5D%5B0%5D=1&filters%5BbranchId%5D%5B0%5D=1&filters%5BconfigId%5D%5B0%5D=1&' .
412+
'filters%5BconfigRowIds%5D%5B0%5D=1&filters%5BprojectId%5D%5B0%5D=1&filters%5BtokenId%5D%5B0%5D=1&' .
413+
'filters%5BtokenDescription%5D%5B0%5D=1&filters%5BcomponentId%5D%5B0%5D=1&filters%5Bstatus%5D%5B0%5D=1&' .
414+
'filters%5BdesiredStatus%5D%5B0%5D=1&filters%5Bmode%5D%5B0%5D=1&filters%5Btag%5D%5B0%5D=1&' .
415+
'filters%5BstartTimeFrom%5D=1&filters%5BstartTimeTo%5D=1&filters%5BcreatedTimeFrom%5D=1&' .
416+
'filters%5BcreatedTimeTo%5D=1&filters%5BendTimeFrom%5D=1&filters%5BendTimeTo%5D=1&' .
417+
'filters%5BdurationSecondsFrom%5D=1&filters%5BdurationSecondsTo%5D=1&' .
418+
'filters%5BvariableValuesId%5D%5B0%5D=1&filters%5BparentRunId%5D%5B0%5D=1&filters%5Btype%5D%5B0%5D=1',
419+
$requests[0]['request']->getUri()->getQuery(),
420+
);
421+
}
422+
316423
private function createClient(array &$requests, array $responses): Client
317424
{
318425
$httpHandler = new MockHandler($responses);

0 commit comments

Comments
 (0)