diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-09-21 17:05:06 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-09-29 09:55:19 +0200 |
commit | fbdf733be0df1bf00f8903a98ccabdf519db55d2 (patch) | |
tree | d0e4fdeaa14319452d1d24938fb5c355dd30e82e /apps/user_status/tests | |
parent | f8f437072ac13a4556dea18219d55f11466497e5 (diff) | |
download | nextcloud-server-fbdf733be0df1bf00f8903a98ccabdf519db55d2.tar.gz nextcloud-server-fbdf733be0df1bf00f8903a98ccabdf519db55d2.zip |
fix(userstatus): Track message timestamp too
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/user_status/tests')
-rw-r--r-- | apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php | 134 | ||||
-rw-r--r-- | apps/user_status/tests/Unit/Db/UserStatusMapperTest.php | 2 |
2 files changed, 136 insertions, 0 deletions
diff --git a/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php b/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php new file mode 100644 index 00000000000..798e591f975 --- /dev/null +++ b/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php @@ -0,0 +1,134 @@ +<?php + +declare(strict_types=1); + +/* + * @copyright 2023 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2023 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +namespace OCA\UserStatus\Tests\Integration\BackgroundJob; + +use OCA\UserStatus\Service\StatusService; +use OCP\AppFramework\Db\DoesNotExistException; +use OCP\IDBConnection; +use OCP\Server; +use OCP\UserStatus\IUserStatus; +use Test\TestCase; +use function sleep; +use function time; + +/** + * @group DB + */ +class StatusServiceIntegrationTest extends TestCase { + + private StatusService $service; + + protected function setUp(): void { + parent::setUp(); + + $this->service = Server::get(StatusService::class); + + $db = Server::get(IDBConnection::class); + $qb = $db->getQueryBuilder(); + $qb->delete('user_status')->executeStatement(); + } + + public function testNoStatusYet(): void { + $this->expectException(DoesNotExistException::class); + + $this->service->findByUserId('test123'); + } + + public function testCustomStatusMessageTimestamp(): void { + $this->service->setCustomMessage( + 'test123', + '🍕', + 'Lunch', + null, + ); + + $status = $this->service->findByUserId('test123'); + + self::assertSame('Lunch', $status->getCustomMessage()); + self::assertGreaterThanOrEqual(time(), $status->getStatusMessageTimestamp()); + } + + public function testOnlineStatusKeepsMessageTimestamp(): void { + $this->service->setStatus( + 'test123', + IUserStatus::OFFLINE, + time() + 1000, + false, + ); + $this->service->setCustomMessage( + 'test123', + '🍕', + 'Lunch', + null, + ); + $timeAfterInsert = time(); + sleep(1); + $this->service->setStatus( + 'test123', + IUserStatus::ONLINE, + time() + 2000, + false, + ); + $status = $this->service->findByUserId('test123'); + + self::assertSame('Lunch', $status->getCustomMessage()); + self::assertLessThanOrEqual($timeAfterInsert, $status->getStatusMessageTimestamp()); + } + + public function testCreateRestoreBackupAutomatically(): void { + $this->service->setStatus( + 'test123', + IUserStatus::ONLINE, + null, + false, + ); + $this->service->setUserStatus( + 'test123', + IUserStatus::DND, + 'meeting', + true, + ); + self::assertSame( + 'meeting', + $this->service->findByUserId('test123')->getMessageId(), + ); + + $this->service->revertUserStatus( + 'test123', + 'meeting', + ); + self::assertSame( + IUserStatus::ONLINE, + $this->service->findByUserId('test123')->getStatus(), + ); + } + + public function testCi(): void { + // TODO: remove if CI turns red + self::assertTrue(false); + } + +} diff --git a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php index 577277cfd61..38913e5f8f5 100644 --- a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php +++ b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php @@ -228,6 +228,7 @@ class UserStatusMapperTest extends TestCase { $userStatus2->setUserId('user1'); $userStatus2->setStatus('dnd'); $userStatus2->setStatusTimestamp(5000); + $userStatus2->setStatusMessageTimestamp(5000); $userStatus2->setIsUserDefined(true); $userStatus2->setCustomIcon('💩'); $userStatus2->setCustomMessage('Do not disturb'); @@ -237,6 +238,7 @@ class UserStatusMapperTest extends TestCase { $userStatus3->setUserId('user2'); $userStatus3->setStatus('away'); $userStatus3->setStatusTimestamp(6000); + $userStatus3->setStatusMessageTimestamp(6000); $userStatus3->setIsUserDefined(false); $userStatus3->setCustomIcon('🏝'); $userStatus3->setCustomMessage('On vacation'); |