diff options
author | Georg Ehrke <developer@georgehrke.com> | 2020-09-02 12:25:02 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2020-09-07 09:22:38 +0200 |
commit | 7fedd33825dc9eb2f3f9bddbc1b3f4301859206f (patch) | |
tree | 2a9bb8c11f53d3bfdb8911a25d03cc5ae88d01ee /apps/user_status/tests | |
parent | 10df7198fe5a1318afaaf6396b64627f70245070 (diff) | |
download | nextcloud-server-7fedd33825dc9eb2f3f9bddbc1b3f4301859206f.tar.gz nextcloud-server-7fedd33825dc9eb2f3f9bddbc1b3f4301859206f.zip |
Better cleanup routine for statuses
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/user_status/tests')
3 files changed, 75 insertions, 3 deletions
diff --git a/apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php b/apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php index a89d0e270fa..ccb649ecce3 100644 --- a/apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php +++ b/apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php @@ -54,6 +54,9 @@ class ClearOldStatusesBackgroundJobTest extends TestCase { $this->mapper->expects($this->once()) ->method('clearMessagesOlderThan') ->with(1337); + $this->mapper->expects($this->once()) + ->method('clearStatusesOlderThan') + ->with(1037, 1337); $this->time->method('getTime') ->willReturn(1337); diff --git a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php index de05d62c227..44ffa75c440 100644 --- a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php +++ b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php @@ -152,7 +152,57 @@ class UserStatusMapperTest extends TestCase { $this->mapper->insert($userStatus2); } - public function testClearOlderThan(): void { + /** + * @param string $status + * @param bool $isUserDefined + * @param int $timestamp + * @param bool $expectsClean + * + * @dataProvider clearStatusesOlderThanDataProvider + */ + public function testClearStatusesOlderThan(string $status, bool $isUserDefined, int $timestamp, bool $expectsClean): void { + $oldStatus = UserStatus::fromParams([ + 'userId' => 'john.doe', + 'status' => $status, + 'isUserDefined' => $isUserDefined, + 'statusTimestamp' => $timestamp, + ]); + + $this->mapper->insert($oldStatus); + + $this->mapper->clearStatusesOlderThan(5000, 8000); + + $updatedStatus = $this->mapper->findAll()[0]; + + if ($expectsClean) { + $this->assertEquals('offline', $updatedStatus->getStatus()); + $this->assertFalse($updatedStatus->getIsUserDefined()); + $this->assertEquals(8000, $updatedStatus->getStatusTimestamp()); + } else { + $this->assertEquals($status, $updatedStatus->getStatus()); + $this->assertEquals($isUserDefined, $updatedStatus->getIsUserDefined()); + $this->assertEquals($timestamp, $updatedStatus->getStatusTimestamp()); + } + } + + public function clearStatusesOlderThanDataProvider(): array { + return [ + ['online', true, 6000, false], + ['online', true, 4000, true], + ['online', false, 6000, false], + ['online', false, 4000, true], + ['away', true, 6000, false], + ['away', true, 4000, false], + ['away', false, 6000, false], + ['away', false, 4000, true], + ['dnd', true, 6000, false], + ['dnd', true, 4000, false], + ['invisible', true, 6000, false], + ['invisible', true, 4000, false], + ]; + } + + public function testClearMessagesOlderThan(): void { $this->insertSampleStatuses(); $this->mapper->clearMessagesOlderThan(55000); diff --git a/apps/user_status/tests/Unit/Service/StatusServiceTest.php b/apps/user_status/tests/Unit/Service/StatusServiceTest.php index d9d0b84750f..4f47070e7c1 100644 --- a/apps/user_status/tests/Unit/Service/StatusServiceTest.php +++ b/apps/user_status/tests/Unit/Service/StatusServiceTest.php @@ -147,11 +147,30 @@ class StatusServiceTest extends TestCase { public function testFindAllClearStatus(): void { $status = new UserStatus(); + $status->setStatus('online'); + $status->setStatusTimestamp(1000); + $status->setIsUserDefined(true); + + $this->timeFactory->method('getTime') + ->willReturn(1400); + $this->mapper->expects($this->once()) + ->method('findByUserId') + ->with('john.doe') + ->willReturn($status); + + $this->assertEquals($status, $this->service->findByUserId('john.doe')); + $this->assertEquals('offline', $status->getStatus()); + $this->assertEquals(1400, $status->getStatusTimestamp()); + $this->assertFalse($status->getIsUserDefined()); + } + + public function testFindAllClearMessage(): void { + $status = new UserStatus(); $status->setClearAt(50); $status->setMessageId('commuting'); + $status->setStatusTimestamp(60); - $this->timeFactory->expects($this->once()) - ->method('getTime') + $this->timeFactory->method('getTime') ->willReturn(60); $this->predefinedStatusService->expects($this->never()) ->method('getDefaultStatusById'); |