diff options
author | Joas Schilling <coding@schilljs.com> | 2021-06-04 12:03:16 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-06-07 09:32:00 +0200 |
commit | 55c44580c26aed3185f10eec5e943b8e82166d04 (patch) | |
tree | 2219edefe0bbd65b5829c334b088484132af579e /apps/user_status/tests | |
parent | 46dbc8fa988176e4a431cafcbae6674fb613c899 (diff) | |
download | nextcloud-server-55c44580c26aed3185f10eec5e943b8e82166d04.tar.gz nextcloud-server-55c44580c26aed3185f10eec5e943b8e82166d04.zip |
Don't update statuses to offline again and again
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/user_status/tests')
-rw-r--r-- | apps/user_status/tests/Unit/Db/UserStatusMapperTest.php | 1 | ||||
-rw-r--r-- | apps/user_status/tests/Unit/Service/StatusServiceTest.php | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php index 8cdaa5fd829..fbd41ac51dc 100644 --- a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php +++ b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php @@ -187,6 +187,7 @@ class UserStatusMapperTest extends TestCase { public function clearStatusesOlderThanDataProvider(): array { return [ + ['offline', false, 6000, false], ['online', true, 6000, false], ['online', true, 4000, true], ['online', false, 6000, false], diff --git a/apps/user_status/tests/Unit/Service/StatusServiceTest.php b/apps/user_status/tests/Unit/Service/StatusServiceTest.php index 1e61f5b09ca..77209b70f48 100644 --- a/apps/user_status/tests/Unit/Service/StatusServiceTest.php +++ b/apps/user_status/tests/Unit/Service/StatusServiceTest.php @@ -37,6 +37,7 @@ use OCA\UserStatus\Service\PredefinedStatusService; use OCA\UserStatus\Service\StatusService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\UserStatus\IUserStatus; use Test\TestCase; class StatusServiceTest extends TestCase { @@ -623,4 +624,44 @@ class StatusServiceTest extends TestCase { $actual = $this->service->removeUserStatus('john.doe'); $this->assertFalse($actual); } + + public function testCleanStatusAutomaticOnline(): void { + $status = new UserStatus(); + $status->setStatus(IUserStatus::ONLINE); + $status->setStatusTimestamp(1337); + $status->setIsUserDefined(false); + + $this->mapper->expects(self::once()) + ->method('update') + ->with($status); + + parent::invokePrivate($this->service, 'cleanStatus', [$status]); + } + + public function testCleanStatusCustomOffline(): void { + $status = new UserStatus(); + $status->setStatus(IUserStatus::OFFLINE); + $status->setStatusTimestamp(1337); + $status->setIsUserDefined(true); + + $this->mapper->expects(self::once()) + ->method('update') + ->with($status); + + parent::invokePrivate($this->service, 'cleanStatus', [$status]); + } + + public function testCleanStatusCleanedAlready(): void { + $status = new UserStatus(); + $status->setStatus(IUserStatus::OFFLINE); + $status->setStatusTimestamp(1337); + $status->setIsUserDefined(false); + + // Don't update the status again and again when no value changed + $this->mapper->expects(self::never()) + ->method('update') + ->with($status); + + parent::invokePrivate($this->service, 'cleanStatus', [$status]); + } } |