From e01f5430bd003fcc1b0c19ec510a79f26b90cd04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Lipensk=C3=BD?= <85517608+ppacz@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:10:13 +0200 Subject: [PATCH] feat: added endpoint to find workload by ID (#537) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomáš Lipenský --- src/ServiceDesk/Request/RequestService.php | 20 ++++++++++++++ .../Request/RequestServiceTest.php | 27 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/ServiceDesk/Request/RequestService.php b/src/ServiceDesk/Request/RequestService.php index 37b419a..33cafcf 100644 --- a/src/ServiceDesk/Request/RequestService.php +++ b/src/ServiceDesk/Request/RequestService.php @@ -427,6 +427,26 @@ public function getWorklogById(string $issueIdOrKey, int $workLogId): Worklog ); } + /** + * @param array $ids + * + * @return array + */ + 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. * diff --git a/tests/ServiceDesk/Request/RequestServiceTest.php b/tests/ServiceDesk/Request/RequestServiceTest.php index 2c587ac..76e831d 100644 --- a/tests/ServiceDesk/Request/RequestServiceTest.php +++ b/tests/ServiceDesk/Request/RequestServiceTest.php @@ -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');