From 0f2003ebc86902ba26b62da1b1759c19e450df90 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Thu, 11 Jun 2026 12:18:32 +0200 Subject: [PATCH] test(OCM): Add test that tests the notificationReceived function Signed-off-by: Micke Nordin --- .../tests/RequestHandlerControllerTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/apps/cloud_federation_api/tests/RequestHandlerControllerTest.php b/apps/cloud_federation_api/tests/RequestHandlerControllerTest.php index 326da930d9c..195057d2e42 100644 --- a/apps/cloud_federation_api/tests/RequestHandlerControllerTest.php +++ b/apps/cloud_federation_api/tests/RequestHandlerControllerTest.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace OCA\CloudFederationApi\Tests; +use OC\Federation\CloudFederationNotification; use OCA\CloudFederationAPI\Config; use OCA\CloudFederationAPI\Controller\RequestHandlerController; use OCA\CloudFederationAPI\Db\FederatedInvite; @@ -18,6 +19,7 @@ use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Utility\ITimeFactory; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; +use OCP\Federation\ICloudFederationProvider; use OCP\Federation\ICloudFederationProviderManager; use OCP\Federation\ICloudIdManager; use OCP\IAppConfig; @@ -26,6 +28,7 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; +use OCP\OCM\Events\OCMNotificationReceivedEvent; use OCP\OCM\IOCMDiscoveryService; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -126,4 +129,43 @@ class RequestHandlerControllerTest extends TestCase { $this->assertEquals($json, $this->requestHandlerController->inviteAccepted($recipientProvider, $token, $recipientId, $recipientEmail, $recipientName)); } + + public function testNotificationReceived(): void { + $notificationType = 'SHARE_ACCEPTED'; + $resourceType = 'file'; + $providerId = '1337'; + $notification = ['sharedSecret' => 'secret']; + $notificationObject = new CloudFederationNotification(); + + $this->appConfig->method('getValueBool')->willReturn(true); + $provider = $this->createMock(ICloudFederationProvider::class); + $provider->method('notificationReceived')->willReturn([]); + $this->cloudFederationFactory->method('getCloudFederationNotification') + ->willReturn($notificationObject); + $this->cloudFederationProviderManager->method('getCloudFederationProvider') + ->willReturn($provider); + + $this->eventDispatcher->expects(self::once()) + ->method('dispatchTyped') + ->with(self::callback( + fn ( + OCMNotificationReceivedEvent $event) + => $event->getNotification() === $notificationObject + ) + ); + $response = $this->requestHandlerController->receiveNotification( + $notificationType, + $resourceType, + $providerId, + $notification + ); + self::assertEquals(Http::STATUS_CREATED, $response->getStatus()); + self::assertEquals([ + 'notificationType' => $notificationType, + 'resourceType' => $resourceType, + 'providerId' => $providerId, + 'notification' => $notification, + ], $notificationObject->getMessage()); + + } }