Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Service/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 40 additions & 0 deletions tests/php/Unit/Service/AccountServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading