aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status/tests
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2023-12-15 14:51:01 +0100
committerAnna Larch <anna@nextcloud.com>2023-12-19 14:59:00 +0100
commit4c6eff975f1ea07e0250d0eff921b5ee54eeab3b (patch)
treeda53d6b2fc6ce2818276d60b176fb18147c11d00 /apps/user_status/tests
parent2f647aacc50f949eccbaaa49a30698776e8205bb (diff)
downloadnextcloud-server-4c6eff975f1ea07e0250d0eff921b5ee54eeab3b.tar.gz
nextcloud-server-4c6eff975f1ea07e0250d0eff921b5ee54eeab3b.zip
fix(userstatus): set user status to 'In a meeting' if calendar is busy
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'apps/user_status/tests')
-rw-r--r--apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php49
-rw-r--r--apps/user_status/tests/Unit/Listener/UserLiveStatusListenerTest.php19
-rw-r--r--apps/user_status/tests/Unit/Service/StatusServiceTest.php49
3 files changed, 50 insertions, 67 deletions
diff --git a/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php b/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php
index cabcc63b291..6161eb100ec 100644
--- a/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php
+++ b/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php
@@ -26,6 +26,7 @@ declare(strict_types=1);
*/
namespace OCA\UserStatus\Tests\Controller;
+use OCA\DAV\CalDAV\Status\StatusService as CalendarStatusService;
use OCA\UserStatus\Controller\UserStatusController;
use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Exception\InvalidClearAtException;
@@ -47,7 +48,10 @@ class UserStatusControllerTest extends TestCase {
private $logger;
/** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
- private $service;
+ private $statusService;
+
+ /** @var CalendarStatusService|\PHPUnit\Framework\MockObject\MockObject $calendarStatusService */
+ private $calendarStatusService;
/** @var UserStatusController */
private $controller;
@@ -58,15 +62,23 @@ class UserStatusControllerTest extends TestCase {
$request = $this->createMock(IRequest::class);
$userId = 'john.doe';
$this->logger = $this->createMock(LoggerInterface::class);
- $this->service = $this->createMock(StatusService::class);
-
- $this->controller = new UserStatusController('user_status', $request, $userId, $this->logger, $this->service);
+ $this->statusService = $this->createMock(StatusService::class);
+ $this->calendarStatusService = $this->createMock(CalendarStatusService::class);
+
+ $this->controller = new UserStatusController(
+ 'user_status',
+ $request,
+ $userId,
+ $this->logger,
+ $this->statusService,
+ $this->calendarStatusService,
+ );
}
public function testGetStatus(): void {
$userStatus = $this->getUserStatus();
- $this->service->expects($this->once())
+ $this->statusService->expects($this->once())
->method('findByUserId')
->with('john.doe')
->willReturn($userStatus);
@@ -85,7 +97,10 @@ class UserStatusControllerTest extends TestCase {
}
public function testGetStatusDoesNotExist(): void {
- $this->service->expects($this->once())
+ $this->calendarStatusService->expects(self::once())
+ ->method('processCalendarStatus')
+ ->with('john.doe');
+ $this->statusService->expects($this->once())
->method('findByUserId')
->with('john.doe')
->willThrowException(new DoesNotExistException(''));
@@ -121,12 +136,12 @@ class UserStatusControllerTest extends TestCase {
$userStatus = $this->getUserStatus();
if ($expectException) {
- $this->service->expects($this->once())
+ $this->statusService->expects($this->once())
->method('setStatus')
->with('john.doe', $statusType, null, true)
->willThrowException($exception);
} else {
- $this->service->expects($this->once())
+ $this->statusService->expects($this->once())
->method('setStatus')
->with('john.doe', $statusType, null, true)
->willReturn($userStatus);
@@ -187,12 +202,12 @@ class UserStatusControllerTest extends TestCase {
$userStatus = $this->getUserStatus();
if ($expectException) {
- $this->service->expects($this->once())
+ $this->statusService->expects($this->once())
->method('setPredefinedMessage')
->with('john.doe', $messageId, $clearAt)
->willThrowException($exception);
} else {
- $this->service->expects($this->once())
+ $this->statusService->expects($this->once())
->method('setPredefinedMessage')
->with('john.doe', $messageId, $clearAt)
->willReturn($userStatus);
@@ -259,28 +274,28 @@ class UserStatusControllerTest extends TestCase {
$userStatus = $this->getUserStatus();
if ($expectException) {
- $this->service->expects($this->once())
+ $this->statusService->expects($this->once())
->method('setCustomMessage')
->with('john.doe', $statusIcon, $message, $clearAt)
->willThrowException($exception);
} else {
if ($expectSuccessAsReset) {
- $this->service->expects($this->never())
+ $this->statusService->expects($this->never())
->method('setCustomMessage');
- $this->service->expects($this->once())
+ $this->statusService->expects($this->once())
->method('clearMessage')
->with('john.doe');
- $this->service->expects($this->once())
+ $this->statusService->expects($this->once())
->method('findByUserId')
->with('john.doe')
->willReturn($userStatus);
} else {
- $this->service->expects($this->once())
+ $this->statusService->expects($this->once())
->method('setCustomMessage')
->with('john.doe', $statusIcon, $message, $clearAt)
->willReturn($userStatus);
- $this->service->expects($this->never())
+ $this->statusService->expects($this->never())
->method('clearMessage');
}
}
@@ -326,7 +341,7 @@ class UserStatusControllerTest extends TestCase {
}
public function testClearMessage(): void {
- $this->service->expects($this->once())
+ $this->statusService->expects($this->once())
->method('clearMessage')
->with('john.doe');
diff --git a/apps/user_status/tests/Unit/Listener/UserLiveStatusListenerTest.php b/apps/user_status/tests/Unit/Listener/UserLiveStatusListenerTest.php
index 5bc60ca71f9..0f637b75411 100644
--- a/apps/user_status/tests/Unit/Listener/UserLiveStatusListenerTest.php
+++ b/apps/user_status/tests/Unit/Listener/UserLiveStatusListenerTest.php
@@ -26,6 +26,7 @@ declare(strict_types=1);
*/
namespace OCA\UserStatus\Tests\Listener;
+use OCA\DAV\CalDAV\Status\StatusService as CalendarStatusService;
use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Db\UserStatusMapper;
use OCA\UserStatus\Listener\UserDeletedListener;
@@ -36,27 +37,37 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\GenericEvent;
use OCP\IUser;
use OCP\User\Events\UserLiveStatusEvent;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UserLiveStatusListenerTest extends TestCase {
- /** @var UserStatusMapper|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var UserStatusMapper|MockObject */
private $mapper;
- /** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var StatusService|MockObject */
private $statusService;
- /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ITimeFactory|MockObject */
private $timeFactory;
/** @var UserDeletedListener */
private $listener;
+ private CalendarStatusService|MockObject $calendarStatusService;
+
protected function setUp(): void {
parent::setUp();
$this->mapper = $this->createMock(UserStatusMapper::class);
$this->statusService = $this->createMock(StatusService::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
- $this->listener = new UserLiveStatusListener($this->mapper, $this->statusService, $this->timeFactory);
+ $this->calendarStatusService = $this->createMock(CalendarStatusService::class);
+
+ $this->listener = new UserLiveStatusListener(
+ $this->mapper,
+ $this->statusService,
+ $this->timeFactory,
+ $this->calendarStatusService,
+ );
}
/**
diff --git a/apps/user_status/tests/Unit/Service/StatusServiceTest.php b/apps/user_status/tests/Unit/Service/StatusServiceTest.php
index 2de041712bd..da11ec0943b 100644
--- a/apps/user_status/tests/Unit/Service/StatusServiceTest.php
+++ b/apps/user_status/tests/Unit/Service/StatusServiceTest.php
@@ -28,9 +28,6 @@ namespace OCA\UserStatus\Tests\Service;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OC\DB\Exceptions\DbalException;
-use OC\User\User;
-use OCA\DAV\CalDAV\Status\Status;
-use OCA\DAV\CalDAV\Status\StatusService as CalendarStatusService;
use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Db\UserStatusMapper;
use OCA\UserStatus\Exception\InvalidClearAtException;
@@ -45,7 +42,6 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\IConfig;
use OCP\IEmojiHelper;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\UserStatus\IUserStatus;
use PHPUnit\Framework\MockObject\MockObject;
@@ -71,9 +67,6 @@ class StatusServiceTest extends TestCase {
/** @var IUserManager|MockObject */
private $userManager;
- /** @var CalendarStatusService|MockObject */
- private $calendarStatusService;
-
private StatusService $service;
protected function setUp(): void {
@@ -84,8 +77,6 @@ class StatusServiceTest extends TestCase {
$this->predefinedStatusService = $this->createMock(PredefinedStatusService::class);
$this->emojiHelper = $this->createMock(IEmojiHelper::class);
$this->userManager = $this->createMock(IUserManager::class);
- $this->calendarStatusService = $this->createMock(CalendarStatusService::class);
-
$this->config = $this->createMock(IConfig::class);
$this->config->method('getAppValue')
@@ -99,8 +90,7 @@ class StatusServiceTest extends TestCase {
$this->predefinedStatusService,
$this->emojiHelper,
$this->config,
- $this->userManager,
- $this->calendarStatusService,
+ $this->userManager
);
}
@@ -156,8 +146,7 @@ class StatusServiceTest extends TestCase {
$this->predefinedStatusService,
$this->emojiHelper,
$this->config,
- $this->userManager,
- $this->calendarStatusService,
+ $this->userManager
);
$this->assertEquals([], $this->service->findAllRecentStatusChanges(20, 50));
@@ -176,8 +165,7 @@ class StatusServiceTest extends TestCase {
$this->predefinedStatusService,
$this->emojiHelper,
$this->config,
- $this->userManager,
- $this->calendarStatusService,
+ $this->userManager
);
$this->assertEquals([], $this->service->findAllRecentStatusChanges(20, 50));
@@ -837,35 +825,4 @@ class StatusServiceTest extends TestCase {
$this->service->revertMultipleUserStatus(['john', 'nobackup', 'backuponly', 'nobackupanddnd'], 'call');
}
-
- public function testCalendarAvailabilityNoUser(): void {
- $userId = 'admin';
-
- $this->userManager->expects(self::once())
- ->method('get')
- ->with($userId)
- ->willReturn(null);
- $this->calendarStatusService->expects(self::never())
- ->method('processCalendarAvailability');
-
- $this->service->getCalendarStatus($userId);
- }
-
- public function testCalendarAvailabilityNoStatus(): void {
- $user = $this->createConfiguredMock(IUser::class, [
- 'getUID' => 'admin',
- 'getEMailAddress' => 'test@test.com',
- ]);
-
- $this->userManager->expects(self::once())
- ->method('get')
- ->with($user->getUID())
- ->willReturn($user);
- $this->calendarStatusService->expects(self::once())
- ->method('processCalendarAvailability')
- ->with($user)
- ->willReturn(null);
-
- $this->service->getCalendarStatus($user->getUID());
- }
}