Skip to content

Commit

Permalink
feat: added endpoint to find workload by ID (#537)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomáš Lipenský <[email protected]>
  • Loading branch information
ppacz and Tomáš Lipenský authored Sep 16, 2024
1 parent fb62c0e commit e01f543
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ServiceDesk/Request/RequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,26 @@ public function getWorklogById(string $issueIdOrKey, int $workLogId): Worklog
);
}

/**
* @param array<int> $ids
*
* @return array<Worklog>
*/
public function getWorklogsByIds(array $ids): array
{
$ret = $this->client->exec('/worklog/list', json_encode(['ids' => $ids]), 'POST');

$this->logger->debug("getWorklogsByIds res=$ret\n");

$worklogsResponse = json_decode($ret, false, 512, JSON_THROW_ON_ERROR);

$worklogs = array_map(function ($worklog) {
return $this->jsonMapper->map($worklog, new Worklog());
}, $worklogsResponse);

return $worklogs;
}

/**
* add work log to issue.
*
Expand Down
27 changes: 27 additions & 0 deletions tests/ServiceDesk/Request/RequestServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,33 @@ public function testGetWorklogById(): void
self::assertSame($item->timeSpent, $result->timeSpent);
}

public function testGetWorklogsByIds(): void
{
$item1 = new stdClass();
$item1->id = 25;
$item1->timeSpent = '2 hours';

$item2 = new stdClass();
$item2->id = 50;
$item2->timeSpent = '2 hours';


$items = [
$item1,
$item2,
];

$this->client->method('exec')
->with("/worklog/list", json_encode(['ids' => [25, 50]]), 'POST')
->willReturn(json_encode($items));

$result = $this->uut->getWorklogsByIds([25, 50]);

self::assertSame(2, count($result));
self::assertSame($item1->timeSpent, $result[0]->timeSpent);

}

public function testAddWorklog(): void
{
$item = $this->createWorkflow(25, '2 hours');
Expand Down

0 comments on commit e01f543

Please sign in to comment.