summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2023-11-09 18:35:20 +0100
committerGitHub <noreply@github.com>2023-11-09 18:35:20 +0100
commit5183ba2a5b9a45a47a822d86122fece30aec4976 (patch)
tree47bcbb0ec0c815b548a8d0d84c5e89754a1d0840 /tests
parent1aa24c024e207b54df3867f5f7ccd67625ac0492 (diff)
parentab1a1d688df76fb5c10b8bc431b928a2db1675bd (diff)
downloadnextcloud-server-5183ba2a5b9a45a47a822d86122fece30aec4976.tar.gz
nextcloud-server-5183ba2a5b9a45a47a822d86122fece30aec4976.zip
Merge pull request #40653 from nextcloud/feat/ooo-api
feat: Add out-of-office message API
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/User/AvailabilityCoordinatorTest.php164
1 files changed, 164 insertions, 0 deletions
diff --git a/tests/lib/User/AvailabilityCoordinatorTest.php b/tests/lib/User/AvailabilityCoordinatorTest.php
new file mode 100644
index 00000000000..8e847f7e5d5
--- /dev/null
+++ b/tests/lib/User/AvailabilityCoordinatorTest.php
@@ -0,0 +1,164 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud>
+ *
+ * @author Richard Steinmetz <richard@steinmetz.cloud>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\User;
+
+use OC\User\AvailabilityCoordinator;
+use OC\User\OutOfOfficeData;
+use OCA\DAV\Db\Absence;
+use OCA\DAV\Db\AbsenceMapper;
+use OCP\ICache;
+use OCP\ICacheFactory;
+use OCP\IUser;
+use Psr\Log\LoggerInterface;
+use Test\TestCase;
+
+class AvailabilityCoordinatorTest extends TestCase {
+ private AvailabilityCoordinator $availabilityCoordinator;
+ private ICacheFactory $cacheFactory;
+ private ICache $cache;
+ private AbsenceMapper $absenceMapper;
+ private LoggerInterface $logger;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->cacheFactory = $this->createMock(ICacheFactory::class);
+ $this->cache = $this->createMock(ICache::class);
+ $this->absenceMapper = $this->createMock(AbsenceMapper::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+
+ $this->cacheFactory->expects(self::once())
+ ->method('createLocal')
+ ->willReturn($this->cache);
+
+ $this->availabilityCoordinator = new AvailabilityCoordinator(
+ $this->cacheFactory,
+ $this->absenceMapper,
+ $this->logger,
+ );
+ }
+
+ public function testGetOutOfOfficeData(): void {
+ $absence = new Absence();
+ $absence->setId(420);
+ $absence->setUserId('user');
+ $absence->setFirstDay('2023-10-01');
+ $absence->setLastDay('2023-10-08');
+ $absence->setStatus('Vacation');
+ $absence->setMessage('On vacation');
+
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')
+ ->willReturn('user');
+
+ $this->cache->expects(self::once())
+ ->method('get')
+ ->with('user')
+ ->willReturn(null);
+ $this->absenceMapper->expects(self::once())
+ ->method('findByUserId')
+ ->with('user')
+ ->willReturn($absence);
+ $this->cache->expects(self::once())
+ ->method('set')
+ ->with('user', '{"id":"420","startDate":1696118400,"endDate":1696723200,"shortMessage":"Vacation","message":"On vacation"}', 300);
+
+ $expected = new OutOfOfficeData(
+ '420',
+ $user,
+ 1696118400,
+ 1696723200,
+ 'Vacation',
+ 'On vacation',
+ );
+ $actual = $this->availabilityCoordinator->getCurrentOutOfOfficeData($user);
+ self::assertEquals($expected, $actual);
+ }
+
+ public function testGetOutOfOfficeDataWithCachedData(): void {
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')
+ ->willReturn('user');
+
+ $this->cache->expects(self::once())
+ ->method('get')
+ ->with('user')
+ ->willReturn('{"id":"420","startDate":1696118400,"endDate":1696723200,"shortMessage":"Vacation","message":"On vacation"}');
+ $this->absenceMapper->expects(self::never())
+ ->method('findByUserId');
+ $this->cache->expects(self::never())
+ ->method('set');
+
+ $expected = new OutOfOfficeData(
+ '420',
+ $user,
+ 1696118400,
+ 1696723200,
+ 'Vacation',
+ 'On vacation',
+ );
+ $actual = $this->availabilityCoordinator->getCurrentOutOfOfficeData($user);
+ self::assertEquals($expected, $actual);
+ }
+
+ public function testGetOutOfOfficeDataWithInvalidCachedData(): void {
+ $absence = new Absence();
+ $absence->setId(420);
+ $absence->setUserId('user');
+ $absence->setFirstDay('2023-10-01');
+ $absence->setLastDay('2023-10-08');
+ $absence->setStatus('Vacation');
+ $absence->setMessage('On vacation');
+
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')
+ ->willReturn('user');
+
+ $this->cache->expects(self::once())
+ ->method('get')
+ ->with('user')
+ ->willReturn('{"id":"420",}');
+ $this->absenceMapper->expects(self::once())
+ ->method('findByUserId')
+ ->with('user')
+ ->willReturn($absence);
+ $this->cache->expects(self::once())
+ ->method('set')
+ ->with('user', '{"id":"420","startDate":1696118400,"endDate":1696723200,"shortMessage":"Vacation","message":"On vacation"}', 300);
+
+ $expected = new OutOfOfficeData(
+ '420',
+ $user,
+ 1696118400,
+ 1696723200,
+ 'Vacation',
+ 'On vacation',
+ );
+ $actual = $this->availabilityCoordinator->getCurrentOutOfOfficeData($user);
+ self::assertEquals($expected, $actual);
+ }
+}