aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status/tests
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2023-11-24 01:49:30 +0100
committerAnna Larch <anna@nextcloud.com>2023-11-28 10:28:06 +0100
commitf19645adab404a9c2642b42ec335bf2830dd8aa7 (patch)
tree3f97f43788aadabce26c1a859c669274639fa695 /apps/user_status/tests
parent53f31498049cf0dcd61c6ef1d840801bd81f055c (diff)
downloadnextcloud-server-f19645adab404a9c2642b42ec335bf2830dd8aa7.tar.gz
nextcloud-server-f19645adab404a9c2642b42ec335bf2830dd8aa7.zip
enh(userstatus): add OOO automation and remove calendar automation
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'apps/user_status/tests')
-rw-r--r--apps/user_status/tests/Unit/Service/StatusServiceTest.php294
1 files changed, 2 insertions, 292 deletions
diff --git a/apps/user_status/tests/Unit/Service/StatusServiceTest.php b/apps/user_status/tests/Unit/Service/StatusServiceTest.php
index 8789a425622..2de041712bd 100644
--- a/apps/user_status/tests/Unit/Service/StatusServiceTest.php
+++ b/apps/user_status/tests/Unit/Service/StatusServiceTest.php
@@ -845,15 +845,13 @@ class StatusServiceTest extends TestCase {
->method('get')
->with($userId)
->willReturn(null);
- $this->mapper->expects(self::never())
- ->method('getAvailabilityFromPropertiesTable');
$this->calendarStatusService->expects(self::never())
->method('processCalendarAvailability');
$this->service->getCalendarStatus($userId);
}
- public function testCalendarAvailabilityNoVavailablility(): void {
+ public function testCalendarAvailabilityNoStatus(): void {
$user = $this->createConfiguredMock(IUser::class, [
'getUID' => 'admin',
'getEMailAddress' => 'test@test.com',
@@ -863,299 +861,11 @@ class StatusServiceTest extends TestCase {
->method('get')
->with($user->getUID())
->willReturn($user);
- $this->mapper->expects(self::once())
- ->method('getAvailabilityFromPropertiesTable')
- ->willReturn('');
$this->calendarStatusService->expects(self::once())
->method('processCalendarAvailability')
- ->with($user, '')
+ ->with($user)
->willReturn(null);
$this->service->getCalendarStatus($user->getUID());
}
-
- public function testCalendarAvailabilityVavailablilityAvailable(): void {
- $user = $this->createConfiguredMock(IUser::class, [
- 'getUID' => 'admin',
- 'getEMailAddress' => 'test@test.com',
- ]);
-
- $vavailability = <<<EOF
-BEGIN:VCALENDAR
-PRODID:Nextcloud DAV app
-BEGIN:VTIMEZONE
-TZID:Europe/Vienna
-BEGIN:STANDARD
-TZNAME:CET
-TZOFFSETFROM:+0200
-TZOFFSETTO:+0100
-DTSTART:19701025T030000
-RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
-END:STANDARD
-BEGIN:DAYLIGHT
-TZNAME:CEST
-TZOFFSETFROM:+0100
-TZOFFSETTO:+0200
-DTSTART:19700329T020000
-RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
-END:DAYLIGHT
-END:VTIMEZONE
-BEGIN:VAVAILABILITY
-BEGIN:AVAILABLE
-DTSTART;TZID=Europe/Vienna:20231025T000000
-DTEND;TZID=Europe/Vienna:20231025T235900
-UID:d866782e-e003-4906-9ece-303f270a2c6b
-RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU
-END:AVAILABLE
-END:VAVAILABILITY
-END:VCALENDAR
-EOF;
- $status = new Status(IUserStatus::AWAY);
- $this->userManager->expects(self::once())
- ->method('get')
- ->with($user->getUID())
- ->willReturn($user);
- $this->mapper->expects(self::once())
- ->method('getAvailabilityFromPropertiesTable')
- ->willReturn($vavailability);
- $this->calendarStatusService->expects(self::once())
- ->method('processCalendarAvailability')
- ->with($user, $vavailability)
- ->willReturn($status);
-
- $this->service->getCalendarStatus($user->getUID());
- }
-
- public function testCalendarAvailabilityVavailablilityUpdate(): void {
- $user = $this->createConfiguredMock(IUser::class, [
- 'getUID' => 'admin',
- 'getEMailAddress' => 'test@test.com',
- ]);
- $calDavStatus = new Status(IUserStatus::BUSY, 'meeting', 'In a meeting');
- $vavailability = <<<EOF
-BEGIN:VCALENDAR
-PRODID:Nextcloud DAV app
-BEGIN:VTIMEZONE
-TZID:Europe/Vienna
-BEGIN:STANDARD
-TZNAME:CET
-TZOFFSETFROM:+0200
-TZOFFSETTO:+0100
-DTSTART:19701025T030000
-RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
-END:STANDARD
-BEGIN:DAYLIGHT
-TZNAME:CEST
-TZOFFSETFROM:+0100
-TZOFFSETTO:+0200
-DTSTART:19700329T020000
-RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
-END:DAYLIGHT
-END:VTIMEZONE
-BEGIN:VAVAILABILITY
-BEGIN:AVAILABLE
-DTSTART;TZID=Europe/Vienna:20231025T000000
-DTEND;TZID=Europe/Vienna:20231025T235900
-UID:d866782e-e003-4906-9ece-303f270a2c6b
-RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU
-END:AVAILABLE
-END:VAVAILABILITY
-END:VCALENDAR
-EOF;
- $this->userManager->expects(self::once())
- ->method('get')
- ->with($user->getUID())
- ->willReturn($user);
- $this->mapper->expects(self::once())
- ->method('getAvailabilityFromPropertiesTable')
- ->willReturn($vavailability);
- $this->calendarStatusService->expects(self::once())
- ->method('processCalendarAvailability')
- ->with($user, $vavailability)
- ->willReturn($calDavStatus);
-
- $this->service->getCalendarStatus($user->getUID());
- }
-
- public function testFindByUserIdUserDefinedAndPersistent(): void {
- $status = new UserStatus();
- $status->setIsUserDefined(true);
- $status->setStatus(IUserStatus::DND);
-
- $this->mapper->expects($this->once())
- ->method('findByUserId')
- ->with('admin')
- ->willReturn($status);
- $this->mapper->expects(self::never())
- ->method('getAvailabilityFromPropertiesTable');
- $this->calendarStatusService->expects(self::never())
- ->method('processCalendarAvailability');
-
- $this->assertEquals($status, $this->service->findByUserId('admin'));
- }
-
- public function testFindByUserIdUserDefinedNoCalStatus(): void {
- $user = $this->createConfiguredMock(IUser::class, [
- 'getUID' => 'admin',
- 'getEMailAddress' => 'test@test.com',
- ]);
- $status = new UserStatus();
- $status->setIsUserDefined(true);
- $status->setStatus(IUserStatus::ONLINE);
-
- $this->mapper->expects($this->once())
- ->method('findByUserId')
- ->with($user->getUID())
- ->willReturn($status);
- $this->userManager->expects(self::once())
- ->method('get')
- ->willReturn($user);
- $this->mapper->expects(self::once())
- ->method('getAvailabilityFromPropertiesTable')
- ->willReturn('');
- $this->calendarStatusService->expects(self::once())
- ->method('processCalendarAvailability')
- ->with($user, '')
- ->willReturn(null);
-
- $this->assertEquals($status, $this->service->findByUserId('admin'));
- }
-
- public function testFindByUserIdUserDefinedCalStatusIdentical(): void {
- $user = $this->createConfiguredMock(IUser::class, [
- 'getUID' => 'admin',
- 'getEMailAddress' => 'test@test.com',
- ]);
- $calDavStatus = new Status(IUserStatus::ONLINE);
- $userStatus = new UserStatus();
- $userStatus->setStatus(IUserStatus::ONLINE);
- $userStatus->setIsUserDefined(true);
- $userStatus->setCustomMessage('Test');
-
- $this->mapper->expects(self::once())
- ->method('findByUserId')
- ->with($user->getUID())
- ->willReturn($userStatus);
- $this->userManager->expects(self::once())
- ->method('get')
- ->willReturn($user);
- $this->mapper->expects(self::once())
- ->method('getAvailabilityFromPropertiesTable')
- ->willReturn('');
- $this->calendarStatusService->expects(self::once())
- ->method('processCalendarAvailability')
- ->with($user, '')
- ->willReturn($calDavStatus);
-
- $this->assertEquals($userStatus, $this->service->findByUserId('admin'));
- }
-
- public function testFindByUserIdUserDefinedCalStatusUpdate(): void {
- $user = $this->createConfiguredMock(IUser::class, [
- 'getUID' => 'admin',
- 'getEMailAddress' => 'test@test.com',
- ]);
- $calDavStatus = new Status(IUserStatus::BUSY, 'meeting', 'In a meeting');
-
- $oldStatus = new UserStatus();
- $oldStatus->setId(42);
- $oldStatus->setUserId($user->getUID());
- $oldStatus->setStatus(IUserStatus::ONLINE);
- $oldStatus->setStatusTimestamp(0);
- $oldStatus->setIsUserDefined(true);
-
- $expected = new UserStatus();
- $expected->setUserId($user->getUID());
- $expected->setStatus(IUserStatus::BUSY);
- $expected->setStatusTimestamp(0);
- $expected->setIsUserDefined(true);
- $expected->setIsBackup(false);
-
- $this->mapper->expects(self::once())
- ->method('findByUserId')
- ->with($user->getUID())
- ->willReturn($oldStatus);
- $this->userManager->expects(self::once())
- ->method('get')
- ->willReturn($user);
- $this->mapper->expects(self::once())
- ->method('getAvailabilityFromPropertiesTable')
- ->willReturn('');
- $this->mapper->expects(self::once())
- ->method('createBackupStatus')
- ->with($user->getUID())
- ->willReturn(true);
- $this->calendarStatusService->expects(self::once())
- ->method('processCalendarAvailability')
- ->with($user, '')
- ->willReturn($calDavStatus);
- $this->predefinedStatusService->expects(self::once())
- ->method('isValidId')
- ->with($calDavStatus->getMessage())
- ->willReturn(true);
- $this->mapper->expects(self::once())
- ->method('insert')
- ->willReturn($expected);
-
- $actual = $this->service->findByUserId('admin');
- $this->assertEquals($expected->getStatus(), $actual->getStatus());
- $this->assertEquals($expected->getCustomMessage(), $actual->getCustomMessage());
- }
-
- public function testFindByUserIdSystemDefined(): void {
- $user = $this->createConfiguredMock(IUser::class, [
- 'getUID' => 'admin',
- 'getEMailAddress' => 'test@test.com',
- ]);
- $status = new UserStatus();
- $status->setIsUserDefined(false);
- $status->setStatus(IUserStatus::ONLINE);
-
- $this->mapper->expects($this->once())
- ->method('findByUserId')
- ->with($user->getUID())
- ->willReturn($status);
- $this->userManager->expects(self::once())
- ->method('get')
- ->willReturn($user);
- $this->mapper->expects(self::once())
- ->method('getAvailabilityFromPropertiesTable')
- ->willReturn('');
- $this->calendarStatusService->expects(self::once())
- ->method('processCalendarAvailability')
- ->with($user, '')
- ->willReturn(null);
-
- $this->assertEquals($status, $this->service->findByUserId('admin'));
- }
-
- public function testSetStatusWithoutMessage(): void {
- $this->predefinedStatusService->expects(self::once())
- ->method('isValidId')
- ->with(IUserStatus::MESSAGE_AVAILABILITY)
- ->willReturn(true);
- $this->timeFactory
- ->method('getTime')
- ->willReturn(1234);
- $status = new UserStatus();
- $status->setUserId('admin');
- $status->setStatusTimestamp(1234);
- $status->setIsUserDefined(true);
- $status->setStatus(IUserStatus::DND);
- $status->setIsBackup(false);
- $status->setMessageId(IUserStatus::MESSAGE_AVAILABILITY);
- $this->mapper->expects(self::once())
- ->method('insert')
- ->with($this->equalTo($status))
- ->willReturnArgument(0);
-
- $result = $this->service->setUserStatus(
- 'admin',
- IUserStatus::DND,
- IUserStatus::MESSAGE_AVAILABILITY,
- true,
- );
-
- self::assertNotNull($result);
- }
}