Skip to content

Commit 52e74f7

Browse files
committed
fixup! feat: add delegation backend
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
1 parent 1431fc2 commit 52e74f7

14 files changed

Lines changed: 110 additions & 4 deletions

tests/Unit/Controller/AccountApiControllerTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCA\Mail\Db\MailAccount;
1717
use OCA\Mail\Service\AccountService;
1818
use OCA\Mail\Service\AliasesService;
19+
use OCA\Mail\Service\DelegationService;
1920
use OCP\AppFramework\Http;
2021
use OCP\IRequest;
2122
use PHPUnit\Framework\MockObject\MockObject;
@@ -28,20 +29,23 @@ class AccountApiControllerTest extends TestCase {
2829
private IRequest&MockObject $request;
2930
private AccountService&MockObject $accountService;
3031
private AliasesService&MockObject $aliasesService;
32+
private DelegationService&MockObject $delegationService;
3133

3234
protected function setUp(): void {
3335
parent::setUp();
3436

3537
$this->request = $this->createMock(IRequest::class);
3638
$this->accountService = $this->createMock(AccountService::class);
3739
$this->aliasesService = $this->createMock(AliasesService::class);
40+
$this->delegationService = $this->createMock(DelegationService::class);
3841

3942
$this->controller = new AccountApiController(
4043
'mail',
4144
$this->request,
4245
self::USER_ID,
4346
$this->accountService,
4447
$this->aliasesService,
48+
$this->delegationService,
4549
);
4650
}
4751

@@ -52,6 +56,7 @@ public function testListWithoutUser() {
5256
null,
5357
$this->accountService,
5458
$this->aliasesService,
59+
$this->delegationService,
5560
);
5661

5762
$this->accountService->expects(self::never())
@@ -74,6 +79,10 @@ public function testList() {
7479
->method('findByUserId')
7580
->with(self::USER_ID)
7681
->willReturn([$account]);
82+
$this->accountService->expects(self::once())
83+
->method('findDelegatedAccounts')
84+
->with(self::USER_ID)
85+
->willReturn([]);
7786

7887
$alias = new Alias();
7988
$alias->setId(10);
@@ -90,6 +99,7 @@ public function testList() {
9099
[
91100
'id' => 42,
92101
'email' => 'foo@bar.com',
102+
'isDelegated' => false,
93103
'aliases' => [
94104
[
95105
'id' => 10,
@@ -111,6 +121,10 @@ public function testListWithAliasWithoutName() {
111121
->method('findByUserId')
112122
->with(self::USER_ID)
113123
->willReturn([$account]);
124+
$this->accountService->expects(self::once())
125+
->method('findDelegatedAccounts')
126+
->with(self::USER_ID)
127+
->willReturn([]);
114128

115129
$alias = new Alias();
116130
$alias->setId(10);
@@ -127,6 +141,7 @@ public function testListWithAliasWithoutName() {
127141
[
128142
'id' => 42,
129143
'email' => 'foo@bar.com',
144+
'isDelegated' => false,
130145
'aliases' => [
131146
[
132147
'id' => 10,
@@ -148,6 +163,10 @@ public function testListWithoutAliases() {
148163
->method('findByUserId')
149164
->with(self::USER_ID)
150165
->willReturn([$account]);
166+
$this->accountService->expects(self::once())
167+
->method('findDelegatedAccounts')
168+
->with(self::USER_ID)
169+
->willReturn([]);
151170

152171
$this->aliasesService->expects(self::once())
153172
->method('findAll')
@@ -160,6 +179,7 @@ public function testListWithoutAliases() {
160179
[
161180
'id' => 42,
162181
'email' => 'foo@bar.com',
182+
'isDelegated' => false,
163183
'aliases' => [],
164184
]
165185
], $actual->getData());

tests/Unit/Controller/AccountsControllerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ public function testIndex(): void {
143143
->method('findAll')
144144
->with(self::equalTo($this->accountId), self::equalTo($this->userId))
145145
->will(self::returnValue(['a1', 'a2']));
146+
$this->accountService->expects(self::once())
147+
->method('findDelegatedAccounts')
148+
->with(self::equalTo($this->userId))
149+
->willReturn([]);
146150

147151
$response = $this->controller->index();
148152

@@ -153,6 +157,7 @@ public function testIndex(): void {
153157
'a1',
154158
'a2',
155159
],
160+
'isDelegated' => false,
156161
]
157162
]);
158163
self::assertEquals($expectedResponse, $response);

tests/Unit/Controller/AliasesControllerTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCA\Mail\Exception\ClientException;
1616
use OCA\Mail\Exception\NotImplemented;
1717
use OCA\Mail\Service\AliasesService;
18+
use OCA\Mail\Service\DelegationService;
1819
use OCP\AppFramework\Db\DoesNotExistException;
1920
use OCP\AppFramework\Http;
2021
use OCP\AppFramework\Http\JSONResponse;
@@ -35,6 +36,9 @@ class AliasesControllerTest extends TestCase {
3536
/** @var AliasesService */
3637
private $aliasService;
3738

39+
/** @var DelegationService */
40+
private $delegationService;
41+
3842
public function setUp(): void {
3943
parent::setUp();
4044
$this->request = $this->getMockBuilder('OCP\IRequest')
@@ -48,7 +52,12 @@ public function setUp(): void {
4852
$this->mailAccountMapper = $this->createMock(MailAccountMapper::class);
4953

5054
$this->aliasService = new AliasesService($this->aliasMapper, $this->mailAccountMapper);
51-
$this->controller = new AliasesController($this->appName, $this->request, $this->aliasService, $this->userId);
55+
$this->delegationService = $this->createMock(DelegationService::class);
56+
$this->delegationService->method('resolveAccountUserId')
57+
->willReturn($this->userId);
58+
$this->delegationService->method('resolveAliasUserId')
59+
->willReturn($this->userId);
60+
$this->controller = new AliasesController($this->appName, $this->request, $this->aliasService, $this->userId, $this->delegationService);
5261
}
5362

5463
public function testIndex(): void {

tests/Unit/Controller/DraftsControllerTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCA\Mail\Exception\ServiceException;
2020
use OCA\Mail\Http\JsonResponse;
2121
use OCA\Mail\Service\AccountService;
22+
use OCA\Mail\Service\DelegationService;
2223
use OCA\Mail\Service\DraftsService;
2324
use OCA\Mail\Service\SmimeService;
2425
use OCP\AppFramework\Db\DoesNotExistException;
@@ -35,6 +36,7 @@ class DraftsControllerTest extends TestCase {
3536
private AccountService $accountService;
3637
private DraftsController $controller;
3738
private SmimeService $smimeService;
39+
private DelegationService $delegationService;
3840

3941
protected function setUp(): void {
4042
parent::setUp();
@@ -46,6 +48,11 @@ protected function setUp(): void {
4648
$this->accountService = $this->createMock(AccountService::class);
4749
$this->timeFactory = $this->createMock(ITimeFactory::class);
4850
$this->smimeService = $this->createMock(SmimeService::class);
51+
$this->delegationService = $this->createMock(DelegationService::class);
52+
$this->delegationService->method('resolveAccountUserId')
53+
->willReturn($this->userId);
54+
$this->delegationService->method('resolveLocalMessageUserId')
55+
->willReturn($this->userId);
4956

5057
$this->controller = new DraftsController(
5158
$this->appName,
@@ -54,7 +61,8 @@ protected function setUp(): void {
5461
$this->service,
5562
$this->accountService,
5663
$this->timeFactory,
57-
$this->smimeService
64+
$this->smimeService,
65+
$this->delegationService,
5866
);
5967
}
6068

tests/Unit/Controller/ListControllerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ protected function setUp(): void {
3434
$this->serviceMock = $this->createServiceMock(ListController::class, [
3535
'userId' => 'user123',
3636
]);
37+
$this->serviceMock->getParameter('delegationService')
38+
->method('resolveMessageUserId')
39+
->willReturn('user123');
3740
$this->controller = $this->serviceMock->getService();
3841
}
3942

tests/Unit/Controller/MailboxesApiControllerTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCA\Mail\Db\Message as DbMessage;
2020
use OCA\Mail\Folder;
2121
use OCA\Mail\Service\AccountService;
22+
use OCA\Mail\Service\DelegationService;
2223
use OCP\AppFramework\Db\DoesNotExistException;
2324
use OCP\AppFramework\Http;
2425
use OCP\IRequest;
@@ -33,6 +34,7 @@ class MailboxesApiControllerTest extends TestCase {
3334
private IMailManager|MockObject $mailManager;
3435
private AccountService&MockObject $accountService;
3536
private MockObject|IMailSearch $mailSearch;
37+
private DelegationService&MockObject $delegationService;
3638

3739
protected function setUp(): void {
3840
parent::setUp();
@@ -41,6 +43,11 @@ protected function setUp(): void {
4143
$this->accountService = $this->createMock(AccountService::class);
4244
$this->mailManager = $this->createMock(IMailManager::class);
4345
$this->mailSearch = $this->createMock(IMailSearch::class);
46+
$this->delegationService = $this->createMock(DelegationService::class);
47+
$this->delegationService->method('resolveAccountUserId')
48+
->willReturn(self::USER_ID);
49+
$this->delegationService->method('resolveMailboxUserId')
50+
->willReturn(self::USER_ID);
4451

4552
$this->controller = new MailboxesApiController(
4653
'mail',
@@ -49,7 +56,7 @@ protected function setUp(): void {
4956
$this->mailManager,
5057
$this->accountService,
5158
$this->mailSearch,
52-
59+
$this->delegationService,
5360
);
5461
}
5562

@@ -61,6 +68,7 @@ public function testListMailboxesWithoutUser() {
6168
$this->mailManager,
6269
$this->accountService,
6370
$this->mailSearch,
71+
$this->delegationService,
6472
);
6573

6674
$this->accountService->expects(self::never())
@@ -101,6 +109,7 @@ public function testListMessagesWithoutUser() {
101109
$this->mailManager,
102110
$this->accountService,
103111
$this->mailSearch,
112+
$this->delegationService,
104113
);
105114

106115
$this->accountService->expects(self::never())

tests/Unit/Controller/MailboxesControllerTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCA\Mail\Folder;
1919
use OCA\Mail\IMAP\MailboxStats;
2020
use OCA\Mail\Service\AccountService;
21+
use OCA\Mail\Service\DelegationService;
2122
use OCA\Mail\Service\Sync\SyncService;
2223
use OCP\AppFramework\Http\JSONResponse;
2324
use OCP\AppFramework\Utility\ITimeFactory;
@@ -49,6 +50,7 @@ class MailboxesControllerTest extends TestCase {
4950

5051
private IConfig|MockObject $config;
5152
private ITimeFactory|MockObject $timeFactory;
53+
private DelegationService|MockObject $delegationService;
5254

5355
public function setUp(): void {
5456
parent::setUp();
@@ -59,6 +61,9 @@ public function setUp(): void {
5961
$this->syncService = $this->createMock(SyncService::class);
6062
$this->config = $this->createMock(IConfig::class);
6163
$this->timeFactory = $this->createMock(ITimeFactory::class);
64+
$this->delegationService = $this->createMock(DelegationService::class);
65+
$this->delegationService->method('resolveAccountUserId')->willReturn($this->userId);
66+
$this->delegationService->method('resolveMailboxUserId')->willReturn($this->userId);
6267

6368
$this->controller = new MailboxesController(
6469
$this->appName,
@@ -68,7 +73,8 @@ public function setUp(): void {
6873
$this->mailManager,
6974
$this->syncService,
7075
$this->config,
71-
$this->timeFactory
76+
$this->timeFactory,
77+
$this->delegationService,
7278
);
7379
}
7480

tests/Unit/Controller/MessageApiControllerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OCA\Mail\Service\AccountService;
2828
use OCA\Mail\Service\AliasesService;
2929
use OCA\Mail\Service\Attachment\AttachmentService;
30+
use OCA\Mail\Service\DelegationService;
3031
use OCA\Mail\Service\DkimService;
3132
use OCA\Mail\Service\ItineraryService;
3233
use OCA\Mail\Service\MailManager;
@@ -58,6 +59,7 @@ class MessageApiControllerTest extends TestCase {
5859
private DkimService|MockObject $dkimService;
5960
private MockObject|ItineraryService $itineraryService;
6061
private TrustedSenderService|MockObject $trustedSenderService;
62+
private DelegationService|MockObject $delegationService;
6163
private MessageApiController $controller;
6264
private string $fromEmail = 'john@test.com';
6365
private int $accountId = 1;
@@ -84,6 +86,9 @@ protected function setUp(): void {
8486
$this->dkimService = $this->createMock(DkimService::class);
8587
$this->itineraryService = $this->createMock(ItineraryService::class);
8688
$this->trustedSenderService = $this->createMock(TrustedSenderService::class);
89+
$this->delegationService = $this->createMock(DelegationService::class);
90+
$this->delegationService->method('resolveAccountUserId')->willReturn($this->userId);
91+
$this->delegationService->method('resolveMessageUserId')->willReturn($this->userId);
8792

8893
$this->controller = new MessageApiController($this->appName,
8994
$this->userId,
@@ -100,6 +105,7 @@ protected function setUp(): void {
100105
$this->dkimService,
101106
$this->itineraryService,
102107
$this->trustedSenderService,
108+
$this->delegationService,
103109
);
104110

105111
$mailAccount = new MailAccount();

tests/Unit/Controller/MessagesControllerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use OCA\Mail\Model\Message;
3838
use OCA\Mail\Service\AccountService;
3939
use OCA\Mail\Service\AiIntegrations\AiIntegrationsService;
40+
use OCA\Mail\Service\DelegationService;
4041
use OCA\Mail\Service\ItineraryService;
4142
use OCA\Mail\Service\MailManager;
4243
use OCA\Mail\Service\SmimeService;
@@ -134,6 +135,8 @@ class MessagesControllerTest extends TestCase {
134135

135136
private ICacheFactory&MockObject $cacheFactory;
136137

138+
private DelegationService|MockObject $delegationService;
139+
137140
protected function setUp(): void {
138141
parent::setUp();
139142

@@ -164,6 +167,10 @@ protected function setUp(): void {
164167
$this->cacheFactory->method('createDistributed')
165168
->willReturn(new NullCache());
166169

170+
$this->delegationService = $this->createMock(DelegationService::class);
171+
$this->delegationService->method('resolveMessageUserId')->willReturn($this->userId);
172+
$this->delegationService->method('resolveMailboxUserId')->willReturn($this->userId);
173+
167174
$timeFactory = $this->createMocK(ITimeFactory::class);
168175
$timeFactory->expects($this->any())
169176
->method('getTime')
@@ -194,6 +201,7 @@ protected function setUp(): void {
194201
$this->snoozeService,
195202
$this->aiIntegrationsService,
196203
$this->cacheFactory,
204+
$this->delegationService,
197205
);
198206

199207
$this->account = $this->createMock(Account::class);
@@ -1249,6 +1257,7 @@ public function testNeedsTranslationNoUser() {
12491257
$this->snoozeService,
12501258
$this->aiIntegrationsService,
12511259
$this->cacheFactory,
1260+
$this->delegationService,
12521261
);
12531262

12541263
$actualResponse = $controller->needsTranslation(100);
@@ -1421,6 +1430,7 @@ public function testSmartReplyNoUser(): void {
14211430
$this->snoozeService,
14221431
$this->aiIntegrationsService,
14231432
$this->cacheFactory,
1433+
$this->delegationService,
14241434
);
14251435

14261436
$actualResponse = $controller->smartReply(100);

0 commit comments

Comments
 (0)