From 370a9d77ea0aadd736d42741623cf98729797d8b Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 22 May 2024 09:10:24 +0200 Subject: feat(dav): Add an API for upcoming events Signed-off-by: Christoph Wurst --- .../Controller/UpcomingEventsControllerTest.php | 74 ++++++++++++++++++ .../unit/Service/UpcomingEventsServiceTest.php | 89 ++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 apps/dav/tests/unit/Controller/UpcomingEventsControllerTest.php create mode 100644 apps/dav/tests/unit/Service/UpcomingEventsServiceTest.php (limited to 'apps/dav/tests/unit') diff --git a/apps/dav/tests/unit/Controller/UpcomingEventsControllerTest.php b/apps/dav/tests/unit/Controller/UpcomingEventsControllerTest.php new file mode 100644 index 00000000000..9e5c03bb245 --- /dev/null +++ b/apps/dav/tests/unit/Controller/UpcomingEventsControllerTest.php @@ -0,0 +1,74 @@ +request = $this->createMock(IRequest::class); + $this->service = $this->createMock(UpcomingEventsService::class); + } + + public function testGetEventsAnonymously() { + $controller = new UpcomingEventsController( + $this->request, + null, + $this->service, + ); + + $response = $controller->getEvents('https://cloud.example.com/call/123'); + + self::assertNull($response->getData()); + self::assertSame(401, $response->getStatus()); + } + + public function testGetEventsByLocation() { + $controller = new UpcomingEventsController( + $this->request, + 'u1', + $this->service, + ); + $this->service->expects(self::once()) + ->method('getEvents') + ->with('u1', 'https://cloud.example.com/call/123') + ->willReturn([ + new UpcomingEvent( + 'abc-123', + null, + 'personal', + 123, + 'Test', + 'https://cloud.example.com/call/123', + null, + ), + ]); + + $response = $controller->getEvents('https://cloud.example.com/call/123'); + + self::assertNotNull($response->getData()); + self::assertIsArray($response->getData()); + self::assertCount(1, $response->getData()['events']); + self::assertSame(200, $response->getStatus()); + $event1 = $response->getData()['events'][0]; + self::assertEquals('abc-123', $event1['uri']); + } +} diff --git a/apps/dav/tests/unit/Service/UpcomingEventsServiceTest.php b/apps/dav/tests/unit/Service/UpcomingEventsServiceTest.php new file mode 100644 index 00000000000..ecb0268c8c2 --- /dev/null +++ b/apps/dav/tests/unit/Service/UpcomingEventsServiceTest.php @@ -0,0 +1,89 @@ +calendarManager = $this->createMock(IManager::class); + $this->timeFactory = $this->createMock(ITimeFactory::class); + $this->userManager = $this->createMock(IUserManager::class); + $this->appManager = $this->createMock(IAppManager::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + + $this->service = new UpcomingEventsService( + $this->calendarManager, + $this->timeFactory, + $this->userManager, + $this->appManager, + $this->urlGenerator, + ); + } + + public function testGetEventsByLocation(): void { + $now = new DateTimeImmutable('2024-07-08T18:20:20Z'); + $this->timeFactory->method('now') + ->willReturn($now); + $query = $this->createMock(ICalendarQuery::class); + $this->appManager->method('isEnabledForUser')->willReturn(false); + $this->calendarManager->method('newQuery') + ->with('principals/users/user1') + ->willReturn($query); + $query->expects(self::once()) + ->method('addSearchProperty') + ->with('LOCATION'); + $query->expects(self::once()) + ->method('setSearchPattern') + ->with('https://cloud.example.com/call/123'); + $this->calendarManager->expects(self::once()) + ->method('searchForPrincipal') + ->with($query) + ->willReturn([ + [ + 'uri' => 'ev1', + 'calendar-key' => '1', + 'calendar-uri' => 'personal', + 'objects' => [ + 0 => [ + 'DTSTART' => [ + new DateTimeImmutable('now'), + ], + ], + ], + ], + ]); + + $events = $this->service->getEvents('user1', 'https://cloud.example.com/call/123'); + + self::assertCount(1, $events); + $event1 = $events[0]; + self::assertEquals('ev1', $event1->getUri()); + } +} -- cgit v1.2.3