Skip to content

Commit 89b4183

Browse files
committed
test: cover detailed file sizes in file list service
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 4e3fe60 commit 89b4183

1 file changed

Lines changed: 59 additions & 1 deletion

File tree

tests/php/Unit/Service/File/FileListServiceTest.php

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use OCA\Libresign\Service\FileElementService;
1818
use OCA\Libresign\Service\IdentifyMethodService;
1919
use OCA\Libresign\Tests\Unit\TestCase;
20+
use OCP\Files\File as NodeFile;
21+
use OCP\Files\Folder;
22+
use OCP\Files\IRootFolder;
2023
use OCP\IAppConfig;
2124
use OCP\IL10N;
2225
use OCP\IURLGenerator;
@@ -34,6 +37,8 @@ final class FileListServiceTest extends TestCase {
3437
private IAppConfig&MockObject $appConfig;
3538
private IL10N&MockObject $l10n;
3639
private IUserManager&MockObject $userManager;
40+
private IRootFolder&MockObject $rootFolder;
41+
private Folder&MockObject $userFolder;
3742
private IUser&MockObject $user;
3843

3944
public function setUp(): void {
@@ -47,8 +52,11 @@ public function setUp(): void {
4752
$this->appConfig = $this->createMock(IAppConfig::class);
4853
$this->l10n = $this->createMock(IL10N::class);
4954
$this->userManager = $this->createMock(IUserManager::class);
55+
$this->rootFolder = $this->createMock(IRootFolder::class);
56+
$this->userFolder = $this->createMock(Folder::class);
5057

5158
$this->user = $this->createMock(IUser::class);
59+
$this->rootFolder->method('getUserFolder')->willReturn($this->userFolder);
5260
}
5361

5462
private function getService(): FileListService {
@@ -60,7 +68,8 @@ private function getService(): FileListService {
6068
$this->urlGenerator,
6169
$this->appConfig,
6270
$this->l10n,
63-
$this->userManager
71+
$this->userManager,
72+
$this->rootFolder,
6473
);
6574
}
6675

@@ -492,6 +501,55 @@ public function testDocMdpLevelIncludedInChildFilesResponse(): void {
492501
$this->assertEquals(2, $result['files'][0]['docmdpLevel']);
493502
}
494503

504+
public function testDetailedFileIncludesSize(): void {
505+
$file = self::createFileEntity(1, 'file', 'doc.pdf');
506+
507+
$this->signRequestMapper->method('getByMultipleFileId')->willReturn([]);
508+
$this->signRequestMapper->method('getIdentifyMethodsFromSigners')->willReturn([]);
509+
$this->signRequestMapper->method('getVisibleElementsFromSigners')->willReturn([]);
510+
511+
$fileNode = $this->createMock(NodeFile::class);
512+
$fileNode->method('getSize')->willReturn(4096);
513+
$this->userFolder->method('getFirstNodeById')->with(100)->willReturn($fileNode);
514+
515+
$service = $this->getService();
516+
$result = $service->formatSingleFile($this->user, $file);
517+
518+
$this->assertSame(4096, $result['size']);
519+
$this->assertSame(4096, $result['files'][0]['size']);
520+
}
521+
522+
public function testEnvelopeDetailedFileIncludesAggregateSize(): void {
523+
$main = self::createFileEntity(1, 'envelope', 'envelope.pdf', ['filesCount' => 2]);
524+
$childA = self::createFileEntity(2, 'file', 'child-a.pdf');
525+
$childB = self::createFileEntity(3, 'file', 'child-b.pdf');
526+
527+
$this->signRequestMapper->method('getByFileId')->with(1)->willReturn([]);
528+
$this->signRequestMapper->method('getByMultipleFileId')->with([2, 3])->willReturn([]);
529+
$this->signRequestMapper->method('getIdentifyMethodsFromSigners')->willReturn([]);
530+
$this->fileMapper->method('getTextOfStatus')->willReturn('Draft');
531+
532+
$fileNodeA = $this->createMock(NodeFile::class);
533+
$fileNodeA->method('getSize')->willReturn(1024);
534+
$fileNodeB = $this->createMock(NodeFile::class);
535+
$fileNodeB->method('getSize')->willReturn(2048);
536+
$this->userFolder->method('getFirstNodeById')->willReturnMap([
537+
[200, $fileNodeA],
538+
[300, $fileNodeB],
539+
]);
540+
541+
$mockUser = $this->createMock(IUser::class);
542+
$mockUser->method('getDisplayName')->willReturn('Requester');
543+
$this->userManager->method('get')->willReturn($mockUser);
544+
545+
$service = $this->getService();
546+
$result = $service->formatFileWithChildren($main, [$childA, $childB], $this->user);
547+
548+
$this->assertSame(3072, $result['size']);
549+
$this->assertSame(1024, $result['files'][0]['size']);
550+
$this->assertSame(2048, $result['files'][1]['size']);
551+
}
552+
495553
private static function createFileEntity(
496554
int $id,
497555
string $nodeType,

0 commit comments

Comments
 (0)