Skip to content

Commit

Permalink
fixup! feat(dav): dispatch out-of-office started and ended events
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Nov 23, 2023
1 parent 780d4c8 commit ea0dbb4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OCA\DAV\Tests\unit\BackgroundJob;

use OCA\DAV\BackgroundJob\OutOfOfficeEventDispatcherJob;
use OCA\DAV\CalDAV\TimezoneService;
use OCA\DAV\Db\Absence;
use OCA\DAV\Db\AbsenceMapper;
use OCP\AppFramework\Utility\ITimeFactory;
Expand Down Expand Up @@ -56,6 +57,7 @@ class OutOfOfficeEventDispatcherJobTest extends TestCase {

/** @var MockObject|IUserManager */
private $userManager;
private MockObject|TimezoneService $timezoneService;

protected function setUp(): void {
parent::setUp();
Expand All @@ -65,17 +67,21 @@ protected function setUp(): void {
$this->logger = $this->createMock(LoggerInterface::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->timezoneService = $this->createMock(TimezoneService::class);

$this->job = new OutOfOfficeEventDispatcherJob(
$this->timeFactory,
$this->absenceMapper,
$this->logger,
$this->eventDispatcher,
$this->userManager,
$this->timezoneService,
);
}

public function testDispatchStartEvent() {
$this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin');

$absence = new Absence();
$absence->setId(200);
$absence->setUserId('user');
Expand Down Expand Up @@ -106,6 +112,8 @@ public function testDispatchStartEvent() {
}

public function testDispatchStopEvent() {
$this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin');

$absence = new Absence();
$absence->setId(200);
$absence->setUserId('user');
Expand Down Expand Up @@ -136,6 +144,8 @@ public function testDispatchStopEvent() {
}

public function testDoesntDispatchUnknownEvent() {
$this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin');

$absence = new Absence();
$absence->setId(100);
$absence->setUserId('user');
Expand Down
18 changes: 12 additions & 6 deletions tests/lib/User/AvailabilityCoordinatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 OCP\ICache;
Expand All @@ -45,6 +46,7 @@ class AvailabilityCoordinatorTest extends TestCase {
private IConfig|MockObject $config;
private AbsenceMapper $absenceMapper;
private LoggerInterface $logger;
private MockObject|TimezoneService $timezoneService;

protected function setUp(): void {
parent::setUp();
Expand All @@ -54,6 +56,7 @@ protected function setUp(): void {
$this->absenceMapper = $this->createMock(AbsenceMapper::class);
$this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->timezoneService = $this->createMock(TimezoneService::class);

$this->cacheFactory->expects(self::once())
->method('createLocal')
Expand All @@ -64,6 +67,7 @@ protected function setUp(): void {
$this->absenceMapper,
$this->config,
$this->logger,
$this->timezoneService,
);
}

Expand All @@ -86,6 +90,7 @@ public function testGetOutOfOfficeData(): void {
$absence->setLastDay('2023-10-08');
$absence->setStatus('Vacation');
$absence->setMessage('On vacation');
$this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin');

$user = $this->createMock(IUser::class);
$user->method('getUID')
Expand All @@ -101,13 +106,13 @@ public function testGetOutOfOfficeData(): void {
->willReturn($absence);
$this->cache->expects(self::once())
->method('set')
->with('user', '{"id":"420","startDate":1696118400,"endDate":1696723200,"shortMessage":"Vacation","message":"On vacation"}', 300);
->with('user', '{"id":"420","startDate":1696111200,"endDate":1696802340,"shortMessage":"Vacation","message":"On vacation"}', 300);

$expected = new OutOfOfficeData(
'420',
$user,
1696118400,
1696723200,
1696111200,
1696802340,
'Vacation',
'On vacation',
);
Expand Down Expand Up @@ -149,6 +154,7 @@ public function testGetOutOfOfficeDataWithInvalidCachedData(): void {
$absence->setLastDay('2023-10-08');
$absence->setStatus('Vacation');
$absence->setMessage('On vacation');
$this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin');

$user = $this->createMock(IUser::class);
$user->method('getUID')
Expand All @@ -164,13 +170,13 @@ public function testGetOutOfOfficeDataWithInvalidCachedData(): void {
->willReturn($absence);
$this->cache->expects(self::once())
->method('set')
->with('user', '{"id":"420","startDate":1696118400,"endDate":1696723200,"shortMessage":"Vacation","message":"On vacation"}', 300);
->with('user', '{"id":"420","startDate":1696111200,"endDate":1696802340,"shortMessage":"Vacation","message":"On vacation"}', 300);

$expected = new OutOfOfficeData(
'420',
$user,
1696118400,
1696723200,
1696111200,
1696802340,
'Vacation',
'On vacation',
);
Expand Down

0 comments on commit ea0dbb4

Please sign in to comment.