diff options
author | Carl Schwan <carl@carlschwan.eu> | 2021-08-11 10:36:24 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2021-10-18 20:31:37 +0200 |
commit | 2cb48f484bd134dd4f9af355365ac6a86f0b81d0 (patch) | |
tree | e4b664986dbf5c889d15de94327081b8b7c5b566 /apps/user_status/tests | |
parent | 643e85cfe81ac079bd2e5bcf1a344a20319f48db (diff) | |
download | nextcloud-server-2cb48f484bd134dd4f9af355365ac6a86f0b81d0.tar.gz nextcloud-server-2cb48f484bd134dd4f9af355365ac6a86f0b81d0.zip |
Add an API to set and rollback the user status
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/user_status/tests')
-rw-r--r-- | apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php | 29 | ||||
-rw-r--r-- | apps/user_status/tests/Unit/Service/StatusServiceTest.php | 49 |
2 files changed, 70 insertions, 8 deletions
diff --git a/apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php b/apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php index 1ca9d11c0fd..0a65256bfac 100644 --- a/apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php +++ b/apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php @@ -47,14 +47,15 @@ class PredefinedStatusServiceTest extends TestCase { } public function testGetDefaultStatuses(): void { - $this->l10n->expects($this->exactly(5)) + $this->l10n->expects($this->exactly(6)) ->method('t') ->withConsecutive( ['In a meeting'], ['Commuting'], ['Working remotely'], ['Out sick'], - ['Vacationing'] + ['Vacationing'], + ['In a call'], ) ->willReturnArgument(0); @@ -102,6 +103,13 @@ class PredefinedStatusServiceTest extends TestCase { 'message' => 'Vacationing', 'clearAt' => null, ], + [ + 'id' => 'call', + 'icon' => '💬', + 'message' => 'In a call', + 'clearAt' => null, + 'visible' => false, + ], ], $actual); } @@ -126,6 +134,7 @@ class PredefinedStatusServiceTest extends TestCase { ['sick-leave', '🤒'], ['vacationing', '🌴'], ['remote-work', '🏡'], + ['call', '💬'], ['unknown-id', null], ]; } @@ -154,6 +163,7 @@ class PredefinedStatusServiceTest extends TestCase { ['sick-leave', 'Out sick'], ['vacationing', 'Vacationing'], ['remote-work', 'Working remotely'], + ['call', 'In a call'], ['unknown-id', null], ]; } @@ -179,28 +189,31 @@ class PredefinedStatusServiceTest extends TestCase { ['sick-leave', true], ['vacationing', true], ['remote-work', true], + ['call', true], ['unknown-id', false], ]; } public function testGetDefaultStatusById(): void { - $this->l10n->expects($this->exactly(5)) + $this->l10n->expects($this->exactly(6)) ->method('t') ->withConsecutive( ['In a meeting'], ['Commuting'], ['Working remotely'], ['Out sick'], - ['Vacationing'] + ['Vacationing'], + ['In a call'], ) ->willReturnArgument(0); $this->assertEquals([ - 'id' => 'vacationing', - 'icon' => '🌴', - 'message' => 'Vacationing', + 'id' => 'call', + 'icon' => '💬', + 'message' => 'In a call', 'clearAt' => null, - ], $this->service->getDefaultStatusById('vacationing')); + 'visible' => false, + ], $this->service->getDefaultStatusById('call')); } public function testGetDefaultStatusByUnknownId(): void { diff --git a/apps/user_status/tests/Unit/Service/StatusServiceTest.php b/apps/user_status/tests/Unit/Service/StatusServiceTest.php index b4215778a99..d8ce866c5c1 100644 --- a/apps/user_status/tests/Unit/Service/StatusServiceTest.php +++ b/apps/user_status/tests/Unit/Service/StatusServiceTest.php @@ -665,4 +665,53 @@ class StatusServiceTest extends TestCase { parent::invokePrivate($this->service, 'cleanStatus', [$status]); } + + public function testBackupWorkingHasBackupAlready() { + $status = new UserStatus(); + $status->setStatus(IUserStatus::ONLINE); + $status->setStatusTimestamp(1337); + $status->setIsUserDefined(true); + $status->setMessageId('meeting'); + $status->setUserId('john'); + $status->setIsBackup(true); + + $this->mapper->expects($this->once()) + ->method('findByUserId') + ->with('john', true) + ->willReturn($status); + + $this->service->backupCurrentStatus('john'); + } + + public function testBackup() { + $currentStatus = new UserStatus(); + $currentStatus->setStatus(IUserStatus::ONLINE); + $currentStatus->setStatusTimestamp(1337); + $currentStatus->setIsUserDefined(true); + $currentStatus->setMessageId('meeting'); + $currentStatus->setUserId('john'); + + $this->mapper->expects($this->at(0)) + ->method('findByUserId') + ->with('john', true) + ->willThrowException(new DoesNotExistException('')); + $this->mapper->expects($this->at(1)) + ->method('findByUserId') + ->with('john', false) + ->willReturn($currentStatus); + + $newBackupStatus = new UserStatus(); + $newBackupStatus->setStatus(IUserStatus::ONLINE); + $newBackupStatus->setStatusTimestamp(1337); + $newBackupStatus->setIsUserDefined(true); + $newBackupStatus->setMessageId('meeting'); + $newBackupStatus->setUserId('_john'); + $newBackupStatus->setIsBackup(true); + + $this->mapper->expects($this->once()) + ->method('update') + ->with($newBackupStatus); + + $this->service->backupCurrentStatus('john'); + } } |