diff options
author | Georg Ehrke <developer@georgehrke.com> | 2020-08-04 20:34:55 +0300 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2020-08-05 14:48:46 +0300 |
commit | 0e0e0d19e8d57f9840348adde5a84d0e690dcebe (patch) | |
tree | bf4842a70cf77cd1bb53a84c1b5c0a53d6cc6b51 /apps/user_status/tests | |
parent | 05813561691aca15116334464a64e8be054ddcbf (diff) |
Provide a PHP Api for UserStatus
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/user_status/tests')
3 files changed, 188 insertions, 0 deletions
diff --git a/apps/user_status/tests/Unit/Connector/UserStatusProviderTest.php b/apps/user_status/tests/Unit/Connector/UserStatusProviderTest.php new file mode 100644 index 00000000000..bc485a5537c --- /dev/null +++ b/apps/user_status/tests/Unit/Connector/UserStatusProviderTest.php @@ -0,0 +1,93 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2020, Georg Ehrke + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\UserStatus\Tests\Connector; + +use OCA\UserStatus\Connector\UserStatusProvider; +use OCA\UserStatus\Db\UserStatus; +use OCA\UserStatus\Service\StatusService; +use Test\TestCase; + +class UserStatusProviderTest extends TestCase { + + /** @var \PHPUnit\Framework\MockObject\MockObject */ + private $service; + + /** @var UserStatusProvider */ + private $provider; + + protected function setUp(): void { + parent::setUp(); + + $this->service = $this->createMock(StatusService::class); + $this->provider = new UserStatusProvider($this->service); + } + + public function testGetUserStatuses(): void { + $userStatus2 = new UserStatus(); + $userStatus2->setUserId('userId2'); + $userStatus2->setStatus('dnd'); + $userStatus2->setStatusTimestamp(5000); + $userStatus2->setIsUserDefined(true); + $userStatus2->setCustomIcon('💩'); + $userStatus2->setCustomMessage('Do not disturb'); + $userStatus2->setClearAt(50000); + + $userStatus3 = new UserStatus(); + $userStatus3->setUserId('userId3'); + $userStatus3->setStatus('away'); + $userStatus3->setStatusTimestamp(5000); + $userStatus3->setIsUserDefined(false); + $userStatus3->setCustomIcon('🏝'); + $userStatus3->setCustomMessage('On vacation'); + $userStatus3->setClearAt(60000); + + $this->service->expects($this->once()) + ->method('findByUserIds') + ->with(['userId1', 'userId2', 'userId3']) + ->willReturn([$userStatus2, $userStatus3]); + + $actual = $this->provider->getUserStatuses(['userId1', 'userId2', 'userId3']); + + $this->assertCount(2, $actual); + $status2 = $actual['userId2']; + $this->assertEquals('userId2', $status2->getUserId()); + $this->assertEquals('dnd', $status2->getStatus()); + $this->assertEquals('Do not disturb', $status2->getMessage()); + $this->assertEquals('💩', $status2->getIcon()); + $dateTime2 = $status2->getClearAt(); + $this->assertInstanceOf(\DateTimeImmutable::class, $dateTime2); + $this->assertEquals('50000', $dateTime2->format('U')); + + $status3 = $actual['userId3']; + $this->assertEquals('userId3', $status3->getUserId()); + $this->assertEquals('away', $status3->getStatus()); + $this->assertEquals('On vacation', $status3->getMessage()); + $this->assertEquals('🏝', $status3->getIcon()); + $dateTime3 = $status3->getClearAt(); + $this->assertInstanceOf(\DateTimeImmutable::class, $dateTime3); + $this->assertEquals('60000', $dateTime3->format('U')); + } +} diff --git a/apps/user_status/tests/Unit/Connector/UserStatusTest.php b/apps/user_status/tests/Unit/Connector/UserStatusTest.php new file mode 100644 index 00000000000..35f79f9958a --- /dev/null +++ b/apps/user_status/tests/Unit/Connector/UserStatusTest.php @@ -0,0 +1,70 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2020, Georg Ehrke + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\UserStatus\Tests\Connector; + +use OCA\UserStatus\Connector\UserStatus; +use Test\TestCase; +use OCA\UserStatus\Db; + +class UserStatusTest extends TestCase { + public function testUserStatus() { + $status = new Db\UserStatus(); + $status->setUserId('user2'); + $status->setStatus('away'); + $status->setStatusTimestamp(5000); + $status->setIsUserDefined(false); + $status->setCustomIcon('🏝'); + $status->setCustomMessage('On vacation'); + $status->setClearAt(60000); + + $userStatus = new UserStatus($status); + $this->assertEquals('user2', $userStatus->getUserId()); + $this->assertEquals('away', $userStatus->getStatus()); + $this->assertEquals('On vacation', $userStatus->getMessage()); + $this->assertEquals('🏝', $userStatus->getIcon()); + + $dateTime = $userStatus->getClearAt(); + $this->assertInstanceOf(\DateTimeImmutable::class, $dateTime); + $this->assertEquals('60000', $dateTime->format('U')); + } + + public function testUserStatusInvisible() { + $status = new Db\UserStatus(); + $status->setUserId('user2'); + $status->setStatus('invisible'); + $status->setStatusTimestamp(5000); + $status->setIsUserDefined(false); + $status->setCustomIcon('🏝'); + $status->setCustomMessage('On vacation'); + $status->setClearAt(60000); + + $userStatus = new UserStatus($status); + $this->assertEquals('user2', $userStatus->getUserId()); + $this->assertEquals('offline', $userStatus->getStatus()); + $this->assertEquals('On vacation', $userStatus->getMessage()); + $this->assertEquals('🏝', $userStatus->getIcon()); + } +} diff --git a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php index 16699d2ae27..42c6f1cfe04 100644 --- a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php +++ b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php @@ -96,6 +96,31 @@ class UserStatusMapperTest extends TestCase { $this->assertEquals(60000, $user2Status->getClearAt()); } + public function testFindByUserIds(): void { + $this->insertSampleStatuses(); + + $statuses = $this->mapper->findByUserIds(['admin', 'user2']); + $this->assertCount(2, $statuses); + + $adminStatus = $statuses[0]; + $this->assertEquals('admin', $adminStatus->getUserId()); + $this->assertEquals('offline', $adminStatus->getStatus()); + $this->assertEquals(0, $adminStatus->getStatusTimestamp()); + $this->assertEquals(false, $adminStatus->getIsUserDefined()); + $this->assertEquals(null, $adminStatus->getCustomIcon()); + $this->assertEquals(null, $adminStatus->getCustomMessage()); + $this->assertEquals(null, $adminStatus->getClearAt()); + + $user2Status = $statuses[1]; + $this->assertEquals('user2', $user2Status->getUserId()); + $this->assertEquals('away', $user2Status->getStatus()); + $this->assertEquals(5000, $user2Status->getStatusTimestamp()); + $this->assertEquals(false, $user2Status->getIsUserDefined()); + $this->assertEquals('🏝', $user2Status->getCustomIcon()); + $this->assertEquals('On vacation', $user2Status->getCustomMessage()); + $this->assertEquals(60000, $user2Status->getClearAt()); + } + public function testUserIdUnique(): void { // Test that inserting a second status for a user is throwing an exception |