2626use OCA \Mail \Service \AccountService ;
2727use OCA \Mail \Service \ContextChat \TaskService ;
2828use OCA \Mail \Service \MailManager ;
29+ use OCP \AppFramework \Db \DoesNotExistException ;
2930use OCP \AppFramework \Utility \ITimeFactory ;
3031use OCP \BackgroundJob \IJobList ;
3132use OCP \ContextChat \IContentManager ;
@@ -142,6 +143,13 @@ public function testRunWithContextChat(): void {
142143 0 ,
143144 // returned on first message
144145 0 ,
146+ 0 ,
147+ 0 ,
148+ 0 ,
149+ 0 ,
150+ 0 ,
151+ 0 ,
152+ 0 ,
145153 );
146154 $ this ->messageMapper ->expects ($ this ->once ())->method ('findIdsAfter ' )
147155 ->with ($ mailbox , 0 , 0 , ContextChatProvider::CONTEXT_CHAT_IMPORT_MAX_ITEMS )->willReturn ([2 ]);
@@ -191,6 +199,10 @@ public function testRunWithContextChatWithNoMessagesToProcess(): void {
191199 12 * 60 * 60 ,
192200 12 * 60 * 60 ,
193201 // returned when filtering messages
202+ ContextChatProvider::CONTEXT_CHAT_MESSAGE_MAX_AGE ,
203+ ContextChatProvider::CONTEXT_CHAT_MESSAGE_MAX_AGE ,
204+ ContextChatProvider::CONTEXT_CHAT_MESSAGE_MAX_AGE ,
205+ ContextChatProvider::CONTEXT_CHAT_MESSAGE_MAX_AGE ,
194206 ContextChatProvider::CONTEXT_CHAT_MESSAGE_MAX_AGE
195207 );
196208 $ this ->messageMapper ->expects ($ this ->once ())->method ('findIdsAfter ' )
@@ -225,7 +237,12 @@ public function testRunWithContextChatWithTimeout(): void {
225237 // returned before processing messages
226238 0 ,
227239 // returned on first message -- will prevent message from being processed
228- ContextChatProvider::CONTEXT_CHAT_JOB_INTERVAL + 100 );
240+ ContextChatProvider::CONTEXT_CHAT_JOB_INTERVAL + 100 ,
241+ ContextChatProvider::CONTEXT_CHAT_JOB_INTERVAL + 100 ,
242+ ContextChatProvider::CONTEXT_CHAT_JOB_INTERVAL + 100 ,
243+ ContextChatProvider::CONTEXT_CHAT_JOB_INTERVAL + 100 ,
244+ ContextChatProvider::CONTEXT_CHAT_JOB_INTERVAL + 100
245+ );
229246 $ this ->messageMapper ->expects ($ this ->once ())->method ('findIdsAfter ' )
230247 ->with ($ mailbox , 0 , 0 , ContextChatProvider::CONTEXT_CHAT_IMPORT_MAX_ITEMS )->willReturn ([1 ]);
231248 $ account = $ this ->createMock (Account::class);
@@ -266,6 +283,9 @@ public function testRunWithContextChatWithEncryptedMessage(): void {
266283 0 ,
267284 // returned on first message
268285 0 ,
286+ 0 ,
287+ 0 ,
288+ 0 ,
269289 );
270290 $ this ->messageMapper ->expects ($ this ->once ())->method ('findIdsAfter ' )
271291 ->with ($ mailbox , 0 , 0 , ContextChatProvider::CONTEXT_CHAT_IMPORT_MAX_ITEMS )->willReturn ([1 ]);
@@ -287,4 +307,80 @@ public function testRunWithContextChatWithEncryptedMessage(): void {
287307 $ this ->submitContentJob ->setLastRun (0 );
288308 $ this ->submitContentJob ->start ($ this ->createMock (IJobList::class));
289309 }
310+
311+ public function testRunWithContextChatWithFindNextTaskException (): void {
312+ $ this ->contentManager ->expects ($ this ->once ())
313+ ->method ('isContextChatAvailable ' )
314+ ->willReturn (true );
315+
316+ $ this ->time ->expects ($ this ->any ())->method ('getTime ' )->willReturn (60 * 60 * 12 );
317+
318+ $ this ->taskService ->expects ($ this ->once ())->method ('findNext ' )->willThrowException (new \OCP \DB \Exception ('An error ' ));
319+ $ this ->contentManager ->expects ($ this ->never ())->method ('submitContent ' );
320+ $ this ->imapClientFactory ->expects ($ this ->never ())->method ('getClient ' );
321+
322+ $ this ->submitContentJob ->setLastRun (0 );
323+ $ this ->submitContentJob ->start ($ this ->createMock (IJobList::class));
324+ }
325+
326+ public function testRunWithContextChatWithFindNextTaskException2 (): void {
327+ $ this ->contentManager ->expects ($ this ->once ())
328+ ->method ('isContextChatAvailable ' )
329+ ->willReturn (true );
330+
331+ $ this ->time ->expects ($ this ->any ())->method ('getTime ' )->willReturn (60 * 60 * 12 );
332+
333+ $ this ->taskService ->expects ($ this ->once ())->method ('findNext ' )->willThrowException (new DoesNotExistException ('ERROR ' ));
334+ $ this ->contentManager ->expects ($ this ->never ())->method ('submitContent ' );
335+ $ this ->imapClientFactory ->expects ($ this ->never ())->method ('getClient ' );
336+
337+ $ this ->submitContentJob ->setLastRun (0 );
338+ $ this ->submitContentJob ->start ($ this ->createMock (IJobList::class));
339+ }
340+
341+ public function testRunWithContextChatWithFindByIdException1 (): void {
342+ $ this ->contentManager ->expects ($ this ->once ())
343+ ->method ('isContextChatAvailable ' )
344+ ->willReturn (true );
345+
346+ $ this ->time ->expects ($ this ->any ())->method ('getTime ' )->willReturn (60 * 60 * 12 );
347+
348+ $ task = new Task ();
349+ $ task ->setLastMessageId (0 );
350+ $ task ->setMailboxId (1 );
351+ $ task ->setId (1 );
352+ $ this ->taskService ->expects ($ this ->once ())->method ('findNext ' )->willReturn ($ task );
353+ $ mailbox = new Mailbox ();
354+ $ mailbox ->setId (1 );
355+ $ mailbox ->setAccountId (5 );
356+ $ this ->mailboxMapper ->expects ($ this ->once ())->method ('findById ' )->willThrowException (new \OCA \Mail \Exception \ServiceException ());
357+ $ this ->contentManager ->expects ($ this ->never ())->method ('submitContent ' );
358+ $ this ->imapClientFactory ->expects ($ this ->never ())->method ('getClient ' );
359+
360+ $ this ->submitContentJob ->setLastRun (0 );
361+ $ this ->submitContentJob ->start ($ this ->createMock (IJobList::class));
362+ }
363+
364+ public function testRunWithContextChatWithFindByIdException2 (): void {
365+ $ this ->contentManager ->expects ($ this ->once ())
366+ ->method ('isContextChatAvailable ' )
367+ ->willReturn (true );
368+
369+ $ this ->time ->expects ($ this ->any ())->method ('getTime ' )->willReturn (60 * 60 * 12 );
370+
371+ $ task = new Task ();
372+ $ task ->setLastMessageId (0 );
373+ $ task ->setMailboxId (1 );
374+ $ task ->setId (1 );
375+ $ this ->taskService ->expects ($ this ->once ())->method ('findNext ' )->willReturn ($ task );
376+ $ mailbox = new Mailbox ();
377+ $ mailbox ->setId (1 );
378+ $ mailbox ->setAccountId (5 );
379+ $ this ->mailboxMapper ->expects ($ this ->once ())->method ('findById ' )->willThrowException (new DoesNotExistException ('ERROR ' ));
380+ $ this ->contentManager ->expects ($ this ->never ())->method ('submitContent ' );
381+ $ this ->imapClientFactory ->expects ($ this ->never ())->method ('getClient ' );
382+
383+ $ this ->submitContentJob ->setLastRun (0 );
384+ $ this ->submitContentJob ->start ($ this ->createMock (IJobList::class));
385+ }
290386}
0 commit comments