mirror of
https://github.com/nextcloud/server.git
synced 2026-06-17 12:42:50 -04:00
test(OCM): Add test that tests the notificationReceived function
Signed-off-by: Micke Nordin <kano@sunet.se>
This commit is contained in:
parent
2beb626995
commit
0f2003ebc8
1 changed files with 42 additions and 0 deletions
|
|
@ -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());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue