diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php index f721938150..13f2974e55 100644 --- a/lib/Service/AccountService.php +++ b/lib/Service/AccountService.php @@ -342,7 +342,11 @@ public function getPdfByUuid(string $uuid): File { $userId = $this->fileMapper->getStorageUserIdByUuid($uuid); $this->folderService->setUserId($userId); - return $this->folderService->getFileByNodeId($nodeId); + try { + return $this->folderService->getFileByNodeId($nodeId); + } catch (NotFoundException) { + throw new DoesNotExistException('Not found'); + } } public function getFileByNodeId(int $nodeId): File { diff --git a/tests/php/Unit/Service/AccountServiceTest.php b/tests/php/Unit/Service/AccountServiceTest.php index 040ac709f2..a33c12a397 100644 --- a/tests/php/Unit/Service/AccountServiceTest.php +++ b/tests/php/Unit/Service/AccountServiceTest.php @@ -307,6 +307,46 @@ public function testGetPdfByUuidWithSuccessAndUnignedFile():void { $this->assertInstanceOf(\OCP\Files\File::class, $actual); } + public function testGetPdfByUuidThrowsDoesNotExistWhenNodeNotFound(): void { + $libresignFile = $this->createMock(\OCA\Libresign\Db\File::class); + $libresignFile->method('__call') + ->willReturnCallback(fn ($method) + => match ($method) { + 'getSignedNodeId' => null, + 'getNodeId' => 123, + 'getStatus' => \OCA\Libresign\Enum\FileStatus::DRAFT->value, + } + ); + + $this->fileMapper + ->expects($this->once()) + ->method('getByUuid') + ->with('uuid') + ->willReturn($libresignFile); + + $this->fileMapper + ->expects($this->once()) + ->method('getStorageUserIdByUuid') + ->with('uuid') + ->willReturn('guest-user'); + + $this->folderService + ->expects($this->once()) + ->method('setUserId') + ->with('guest-user'); + + $this->folderService + ->expects($this->once()) + ->method('getFileByNodeId') + ->with(123) + ->willThrowException(new NotFoundException('Invalid node')); + + $this->expectException(DoesNotExistException::class); + $this->expectExceptionMessage('Not found'); + + $this->getService()->getPdfByUuid('uuid'); + } + public function testCanRequestSignWithUnexistentUser():void { $actual = $this->getService()->canRequestSign(); $this->assertFalse($actual);