-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathIdentifyServiceTest.php
More file actions
152 lines (131 loc) · 5.13 KB
/
IdentifyServiceTest.php
File metadata and controls
152 lines (131 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Tests\Unit\Service\IdentifyMethod;
use OCA\Libresign\Db\File;
use OCA\Libresign\Db\FileMapper;
use OCA\Libresign\Db\IdentifyMethod;
use OCA\Libresign\Db\IdentifyMethodMapper;
use OCA\Libresign\Db\SignRequest;
use OCA\Libresign\Db\SignRequestMapper;
use OCA\Libresign\Service\IdentifyMethod\IdentifyService;
use OCA\Libresign\Service\SessionService;
use OCA\Libresign\Tests\Unit\TestCase;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Security\IHasher;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
final class IdentifyServiceTest extends TestCase {
private IdentifyMethodMapper&MockObject $identifyMethodMapper;
private SessionService&MockObject $sessionService;
private ITimeFactory&MockObject $timeFactory;
private IEventDispatcher&MockObject $eventDispatcher;
private IRootFolder&MockObject $rootFolder;
private IAppConfig&MockObject $appConfig;
private SignRequestMapper&MockObject $signRequestMapper;
private IL10N&MockObject $l10n;
private FileMapper&MockObject $fileMapper;
private IHasher&MockObject $hasher;
private IUserManager&MockObject $userManager;
private IURLGenerator&MockObject $urlGenerator;
private LoggerInterface&MockObject $logger;
private IdentifyService $service;
public function setUp(): void {
parent::setUp();
$this->identifyMethodMapper = $this->createMock(IdentifyMethodMapper::class);
$this->sessionService = $this->createMock(SessionService::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->signRequestMapper = $this->createMock(SignRequestMapper::class);
$this->l10n = $this->createMock(IL10N::class);
$this->fileMapper = $this->createMock(FileMapper::class);
$this->hasher = $this->createMock(IHasher::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->service = new IdentifyService(
$this->identifyMethodMapper,
$this->sessionService,
$this->timeFactory,
$this->eventDispatcher,
$this->rootFolder,
$this->appConfig,
$this->signRequestMapper,
$this->l10n,
$this->fileMapper,
$this->hasher,
$this->userManager,
$this->urlGenerator,
$this->logger,
);
}
public function testPropagateIdentifiedDateSkipsCurrentRequestAndUpdatesSiblings(): void {
$identifyMethod = new IdentifyMethod();
$identifyMethod->setSignRequestId(1);
$identifyMethod->setIdentifierKey('email');
$identifyMethod->setIdentifierValue('[email protected]');
$identifyMethod->setIdentifiedAtDate('2024-01-01T00:00:00Z');
$parentEnvelopeId = 99;
$currentFile = new File();
$currentFile->setId(10);
$currentFile->setParentFileId($parentEnvelopeId);
$currentSignRequest = new SignRequest();
$currentSignRequest->setId(1);
$currentSignRequest->setFileId($currentFile->getId());
$siblingFile = new File();
$siblingFile->setId(11);
$siblingFile->setParentFileId($parentEnvelopeId);
$siblingSignRequest = new SignRequest();
$siblingSignRequest->setId(2);
$siblingSignRequest->setFileId($siblingFile->getId());
$this->signRequestMapper
->expects($this->once())
->method('getById')
->with($identifyMethod->getSignRequestId())
->willReturn($currentSignRequest);
$this->fileMapper
->expects($this->once())
->method('getById')
->with($currentFile->getId())
->willReturn($currentFile);
$this->signRequestMapper
->expects($this->once())
->method('getByEnvelopeChildrenAndIdentifyMethod')
->with($parentEnvelopeId, $currentSignRequest->getId())
->willReturn([$currentSignRequest, $siblingSignRequest]);
$siblingIdentifyMethod = new IdentifyMethod();
$siblingIdentifyMethod->setSignRequestId($siblingSignRequest->getId());
$siblingIdentifyMethod->setIdentifierKey($identifyMethod->getIdentifierKey());
$siblingIdentifyMethod->setIdentifierValue($identifyMethod->getIdentifierValue());
$this->identifyMethodMapper
->expects($this->exactly(2))
->method('getIdentifyMethodsFromSignRequestId')
->willReturnMap([
[$identifyMethod->getSignRequestId(), []],
[$siblingSignRequest->getId(), [$siblingIdentifyMethod]],
]);
$this->identifyMethodMapper
->expects($this->once())
->method('insertOrUpdate')
->with($identifyMethod);
$this->identifyMethodMapper
->expects($this->once())
->method('update')
->with($this->callback(function (IdentifyMethod $updated) use ($siblingIdentifyMethod, $identifyMethod) {
return $updated->getSignRequestId() === $siblingIdentifyMethod->getSignRequestId()
&& $updated->getIdentifiedAtDate() == $identifyMethod->getIdentifiedAtDate();
}));
$this->service->save($identifyMethod);
}
}