diff options
author | Anna Larch <anna@nextcloud.com> | 2023-11-24 01:49:30 +0100 |
---|---|---|
committer | Anna Larch <anna@nextcloud.com> | 2023-11-28 15:44:23 +0100 |
commit | e8481e428a91beaf3dd27dc0ec3a25c4ff98a320 (patch) | |
tree | c3e25bf14dda918ab88be1415947c3cc71a3693c /tests | |
parent | e7b1d1f46c576c999ac261b7c48abe1a1a6c9588 (diff) | |
download | nextcloud-server-e8481e428a91beaf3dd27dc0ec3a25c4ff98a320.tar.gz nextcloud-server-e8481e428a91beaf3dd27dc0ec3a25c4ff98a320.zip |
[stable28] enh(userstatus): add OOO automation and remove calendar automation
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/User/AvailabilityCoordinatorTest.php | 90 |
1 files changed, 61 insertions, 29 deletions
diff --git a/tests/lib/User/AvailabilityCoordinatorTest.php b/tests/lib/User/AvailabilityCoordinatorTest.php index 8a0b66181d2..b41b1fbac2a 100644 --- a/tests/lib/User/AvailabilityCoordinatorTest.php +++ b/tests/lib/User/AvailabilityCoordinatorTest.php @@ -30,7 +30,7 @@ use OC\User\AvailabilityCoordinator; use OC\User\OutOfOfficeData; use OCA\DAV\CalDAV\TimezoneService; use OCA\DAV\Db\Absence; -use OCA\DAV\Db\AbsenceMapper; +use OCA\DAV\Service\AbsenceService; use OCP\ICache; use OCP\ICacheFactory; use OCP\IConfig; @@ -44,7 +44,7 @@ class AvailabilityCoordinatorTest extends TestCase { private ICacheFactory $cacheFactory; private ICache $cache; private IConfig|MockObject $config; - private AbsenceMapper $absenceMapper; + private AbsenceService $absenceService; private LoggerInterface $logger; private MockObject|TimezoneService $timezoneService; @@ -53,7 +53,7 @@ class AvailabilityCoordinatorTest extends TestCase { $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cache = $this->createMock(ICache::class); - $this->absenceMapper = $this->createMock(AbsenceMapper::class); + $this->absenceService = $this->createMock(AbsenceService::class); $this->config = $this->createMock(IConfig::class); $this->logger = $this->createMock(LoggerInterface::class); $this->timezoneService = $this->createMock(TimezoneService::class); @@ -64,8 +64,8 @@ class AvailabilityCoordinatorTest extends TestCase { $this->availabilityCoordinator = new AvailabilityCoordinator( $this->cacheFactory, - $this->absenceMapper, $this->config, + $this->absenceService, $this->logger, $this->timezoneService, ); @@ -82,7 +82,7 @@ class AvailabilityCoordinatorTest extends TestCase { self::assertTrue($isEnabled); } - public function testGetOutOfOfficeData(): void { + public function testGetOutOfOfficeDataInEffect(): void { $absence = new Absence(); $absence->setId(420); $absence->setUserId('user'); @@ -96,17 +96,17 @@ class AvailabilityCoordinatorTest extends TestCase { $user->method('getUID') ->willReturn('user'); - $this->cache->expects(self::once()) + $this->cache->expects(self::exactly(2)) ->method('get') - ->with('user') - ->willReturn(null); - $this->absenceMapper->expects(self::once()) - ->method('findByUserId') - ->with('user') + ->willReturnOnConsecutiveCalls(null, null); + $this->absenceService->expects(self::once()) + ->method('getAbsence') + ->with($user->getUID()) ->willReturn($absence); - $this->cache->expects(self::once()) + $this->cache->expects(self::exactly(2)) ->method('set') - ->with('user', '{"id":"420","startDate":1696111200,"endDate":1696802340,"shortMessage":"Vacation","message":"On vacation"}', 300); + ->withConsecutive([$user->getUID() . '_timezone', 'Europe/Berlin', 3600], + [$user->getUID(), '{"id":"420","startDate":1696111200,"endDate":1696802340,"shortMessage":"Vacation","message":"On vacation"}', 300]); $expected = new OutOfOfficeData( '420', @@ -120,25 +120,32 @@ class AvailabilityCoordinatorTest extends TestCase { self::assertEquals($expected, $actual); } - public function testGetOutOfOfficeDataWithCachedData(): void { + public function testGetOutOfOfficeDataCachedAll(): 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()) + $this->cache->expects(self::exactly(2)) ->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()) + ->willReturnOnConsecutiveCalls('UTC', '{"id":"420","startDate":1696118400,"endDate":1696809540,"shortMessage":"Vacation","message":"On vacation"}'); + $this->absenceService->expects(self::never()) + ->method('getAbsence'); + $this->cache->expects(self::exactly(1)) ->method('set'); $expected = new OutOfOfficeData( '420', $user, 1696118400, - 1696723200, + 1696809540, 'Vacation', 'On vacation', ); @@ -146,6 +153,32 @@ class AvailabilityCoordinatorTest extends TestCase { self::assertEquals($expected, $actual); } + public function testGetOutOfOfficeDataNoData(): 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::exactly(2)) + ->method('get') + ->willReturnOnConsecutiveCalls('UTC', null); + $this->absenceService->expects(self::once()) + ->method('getAbsence') + ->willReturn(null); + $this->cache->expects(self::never()) + ->method('set'); + + $actual = $this->availabilityCoordinator->getCurrentOutOfOfficeData($user); + self::assertNull($actual); + } + public function testGetOutOfOfficeDataWithInvalidCachedData(): void { $absence = new Absence(); $absence->setId(420); @@ -160,23 +193,22 @@ class AvailabilityCoordinatorTest extends TestCase { $user->method('getUID') ->willReturn('user'); - $this->cache->expects(self::once()) + $this->cache->expects(self::exactly(2)) ->method('get') - ->with('user') - ->willReturn('{"id":"420",}'); - $this->absenceMapper->expects(self::once()) - ->method('findByUserId') + ->willReturnOnConsecutiveCalls('UTC', '{"id":"420",}'); + $this->absenceService->expects(self::once()) + ->method('getAbsence') ->with('user') ->willReturn($absence); $this->cache->expects(self::once()) ->method('set') - ->with('user', '{"id":"420","startDate":1696111200,"endDate":1696802340,"shortMessage":"Vacation","message":"On vacation"}', 300); + ->with('user', '{"id":"420","startDate":1696118400,"endDate":1696809540,"shortMessage":"Vacation","message":"On vacation"}', 300); $expected = new OutOfOfficeData( '420', $user, - 1696111200, - 1696802340, + 1696118400, + 1696809540, 'Vacation', 'On vacation', ); |