test: check that UserStatusAutomation is cleaned up

Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
pull/53418/head
Salvatore Martire 2025-06-30 18:10:45 +07:00
parent 125696bfbc
commit 289b7ab684
1 changed files with 27 additions and 0 deletions

@ -10,12 +10,14 @@ declare(strict_types=1);
namespace OCA\DAV\Tests\unit\DAV\Listener;
use OCA\DAV\BackgroundJob\UserStatusAutomation;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\SyncService;
use OCA\DAV\Listener\UserEventsListener;
use OCA\DAV\Service\ExampleContactService;
use OCA\DAV\Service\ExampleEventService;
use OCP\BackgroundJob\IJobList;
use OCP\Defaults;
use OCP\IUser;
use OCP\IUserManager;
@ -46,6 +48,7 @@ class UserEventsListenerTest extends TestCase {
$this->exampleContactService = $this->createMock(ExampleContactService::class);
$this->exampleEventService = $this->createMock(ExampleEventService::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->jobList = $this->createMock(IJobList::class);
$this->userEventsListener = new UserEventsListener(
$this->userManager,
@ -56,6 +59,7 @@ class UserEventsListenerTest extends TestCase {
$this->exampleContactService,
$this->exampleEventService,
$this->logger,
$this->jobList,
);
}
@ -153,4 +157,27 @@ class UserEventsListenerTest extends TestCase {
$this->userEventsListener->preDeleteUser($user);
$this->userEventsListener->postDeleteUser('newUser');
}
public function testDeleteUserAutomationEvent(): void {
$user = $this->createMock(IUser::class);
$user->expects($this->once())->method('getUID')->willReturn('newUser');
$this->syncService->expects($this->once())
->method('deleteUser');
$this->calDavBackend->expects($this->once())->method('getUsersOwnCalendars')->willReturn([
['id' => []]
]);
$this->calDavBackend->expects($this->once())->method('getSubscriptionsForUser')->willReturn([
['id' => []]
]);
$this->cardDavBackend->expects($this->once())->method('getUsersOwnAddressBooks')->willReturn([
['id' => []]
]);
$this->jobList->expects(self::once())->method('remove')->with(UserStatusAutomation::class, ['userId' => 'newUser']);
$this->userEventsListener->preDeleteUser($user);
$this->userEventsListener->postDeleteUser('newUser');
}
}