Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-03-24 09:59:40 +0300
committerJoas Schilling <coding@schilljs.com>2022-03-24 23:50:31 +0300
commit625439702e54eaf36b84f51e90437cb59191a641 (patch)
tree757c4a17cfb7a87d46560b02e68f371e62570cf6 /tests
parentae62e05fdde9e734ee03c8763190dd96fc3531bb (diff)
Allow to delete files and object shares on the API
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php3
-rw-r--r--tests/integration/features/chat/file-share.feature25
-rw-r--r--tests/integration/features/chat/rich-object-share.feature10
-rw-r--r--tests/php/Chat/ChatManagerTest.php200
4 files changed, 238 insertions, 0 deletions
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index 7a60aba3b..1fc24a133 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -1630,6 +1630,9 @@ class FeatureContext implements Context, SnippetAcceptingContext {
// replies; this is needed to get special messages not explicitly
// sent like those for shared files.
self::$messages[$message['message']] = $message['id'];
+ if ($message['message'] === '{file}' && isset($message['messageParameters']['file']['name'])) {
+ self::$messages['shared::file::' . $message['messageParameters']['file']['name']] = $message['id'];
+ }
}
if ($formData === null) {
diff --git a/tests/integration/features/chat/file-share.feature b/tests/integration/features/chat/file-share.feature
new file mode 100644
index 000000000..cb35a4d16
--- /dev/null
+++ b/tests/integration/features/chat/file-share.feature
@@ -0,0 +1,25 @@
+Feature: chat/public
+ Background:
+ Given user "participant1" exists
+
+ Scenario: Share a file to a chat
+ Given user "participant1" creates room "public room" (v4)
+ | roomType | 3 |
+ | roomName | room |
+ When user "participant1" shares "welcome.txt" with room "public room"
+ Then user "participant1" sees the following messages in room "public room" with 200
+ | room | actorType | actorId | actorDisplayName | message | messageParameters |
+ | public room | users | participant1 | participant1-displayname | {file} | "IGNORE" |
+
+ Scenario: Delete share a file message from a chat
+ Given user "participant1" creates room "public room" (v4)
+ | roomType | 3 |
+ | roomName | room |
+ When user "participant1" shares "welcome.txt" with room "public room"
+ Then user "participant1" sees the following messages in room "public room" with 200
+ | room | actorType | actorId | actorDisplayName | message | messageParameters |
+ | public room | users | participant1 | participant1-displayname | {file} | "IGNORE" |
+ And user "participant1" deletes message "shared::file::welcome.txt" from room "public room" with 200
+ Then user "participant1" sees the following messages in room "public room" with 200
+ | room | actorType | actorId | actorDisplayName | message | messageParameters |
+ | public room | users | participant1 | participant1-displayname | Message deleted by you | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} |
diff --git a/tests/integration/features/chat/rich-object-share.feature b/tests/integration/features/chat/rich-object-share.feature
index c5cc64425..3b81ed7ce 100644
--- a/tests/integration/features/chat/rich-object-share.feature
+++ b/tests/integration/features/chat/rich-object-share.feature
@@ -11,6 +11,16 @@ Feature: chat/public
| room | actorType | actorId | actorDisplayName | message | messageParameters |
| public room | users | participant1 | participant1-displayname | {object} | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"object":{"name":"Another room","call-type":"group","type":"call","id":"R4nd0mT0k3n"}} |
+ Scenario: Delete a rich object from a chat
+ Given user "participant1" creates room "public room" (v4)
+ | roomType | 3 |
+ | roomName | room |
+ When user "participant1" shares rich-object "call" "R4nd0mT0k3n" '{"name":"Another room","call-type":"group"}' to room "public room" with 201 (v1)
+ And user "participant1" deletes message "shared::call::R4nd0mT0k3n" from room "public room" with 200
+ Then user "participant1" sees the following messages in room "public room" with 200
+ | room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage |
+ | public room | users | participant1 | participant1-displayname | Message deleted by you | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | |
+
Scenario: Share an invalid rich object to a chat
Given user "participant1" creates room "public room" (v4)
| roomType | 3 |
diff --git a/tests/php/Chat/ChatManagerTest.php b/tests/php/Chat/ChatManagerTest.php
index ad6cbd7c4..78f9cf693 100644
--- a/tests/php/Chat/ChatManagerTest.php
+++ b/tests/php/Chat/ChatManagerTest.php
@@ -28,6 +28,7 @@ use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\CommentsManager;
use OCA\Talk\Chat\Notifier;
use OCA\Talk\Model\Attendee;
+use OCA\Talk\Model\AttendeeMapper;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
@@ -39,6 +40,9 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\ICacheFactory;
use OCP\IUser;
use OCP\Notification\IManager as INotificationManager;
+use OCP\Share\Exceptions\ShareNotFound;
+use OCP\Share\IManager;
+use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -53,6 +57,8 @@ class ChatManagerTest extends TestCase {
protected $dispatcher;
/** @var INotificationManager|MockObject */
protected $notificationManager;
+ /** @var IManager|MockObject */
+ protected $shareManager;
/** @var RoomShareProvider|MockObject */
protected $shareProvider;
/** @var ParticipantService|MockObject */
@@ -70,6 +76,7 @@ class ChatManagerTest extends TestCase {
$this->commentsManager = $this->createMock(CommentsManager::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->notificationManager = $this->createMock(INotificationManager::class);
+ $this->shareManager = $this->createMock(IManager::class);
$this->shareProvider = $this->createMock(RoomShareProvider::class);
$this->participantService = $this->createMock(ParticipantService::class);
$this->notifier = $this->createMock(Notifier::class);
@@ -81,6 +88,7 @@ class ChatManagerTest extends TestCase {
$this->dispatcher,
\OC::$server->getDatabaseConnection(),
$this->notificationManager,
+ $this->shareManager,
$this->shareProvider,
$this->participantService,
$this->notifier,
@@ -103,6 +111,7 @@ class ChatManagerTest extends TestCase {
$this->dispatcher,
\OC::$server->getDatabaseConnection(),
$this->notificationManager,
+ $this->shareManager,
$this->shareProvider,
$this->participantService,
$this->notifier,
@@ -118,6 +127,7 @@ class ChatManagerTest extends TestCase {
$this->dispatcher,
\OC::$server->getDatabaseConnection(),
$this->notificationManager,
+ $this->shareManager,
$this->shareProvider,
$this->participantService,
$this->notifier,
@@ -392,6 +402,196 @@ class ChatManagerTest extends TestCase {
$this->chatManager->deleteMessages($chat);
}
+ public function testDeleteMessage(): void {
+ $mapper = new AttendeeMapper(\OC::$server->getDatabaseConnection());
+ $attendee = $mapper->createAttendeeFromRow([
+ 'a_id' => 1,
+ 'room_id' => 123,
+ 'actor_type' => Attendee::ACTOR_USERS,
+ 'actor_id' => 'user',
+ 'display_name' => 'user-display',
+ 'pin' => '',
+ 'participant_type' => Participant::USER,
+ 'favorite' => true,
+ 'notification_level' => Participant::NOTIFY_MENTION,
+ 'notification_calls' => Participant::NOTIFY_CALLS_ON,
+ 'last_joined_call' => 0,
+ 'last_read_message' => 0,
+ 'last_mention_message' => 0,
+ 'last_mention_direct' => 0,
+ 'read_privacy' => Participant::PRIVACY_PUBLIC,
+ 'permissions' => Attendee::PERMISSIONS_DEFAULT,
+ 'access_token' => '',
+ 'remote_id' => '',
+ ]);
+ $chat = $this->createMock(Room::class);
+ $chat->expects($this->any())
+ ->method('getId')
+ ->willReturn(1234);
+ $participant = new Participant($chat, $attendee, null);
+
+ $date = new \DateTime();
+
+ $comment = $this->createMock(IComment::class);
+ $comment->method('getId')
+ ->willReturn('123456');
+ $comment->method('getVerb')
+ ->willReturn('comment');
+ $comment->expects($this->once())
+ ->method('setMessage');
+ $comment->expects($this->once())
+ ->method('setVerb')
+ ->with('comment_deleted');
+
+ $this->commentsManager->expects($this->once())
+ ->method('save')
+ ->with($comment);
+
+ $systemMessage = $this->createMock(IComment::class);
+
+ $chatManager = $this->getManager(['addSystemMessage']);
+ $chatManager->expects($this->once())
+ ->method('addSystemMessage')
+ ->with($chat, Attendee::ACTOR_USERS, 'user', $this->anything(), $this->anything(), false, null, 123456)
+ ->willReturn($systemMessage);
+
+ $this->assertSame($systemMessage, $chatManager->deleteMessage($chat, $comment, $participant, $date));
+ }
+
+ public function testDeleteMessageFileShare(): void {
+ $mapper = new AttendeeMapper(\OC::$server->getDatabaseConnection());
+ $attendee = $mapper->createAttendeeFromRow([
+ 'a_id' => 1,
+ 'room_id' => 123,
+ 'actor_type' => Attendee::ACTOR_USERS,
+ 'actor_id' => 'user',
+ 'display_name' => 'user-display',
+ 'pin' => '',
+ 'participant_type' => Participant::USER,
+ 'favorite' => true,
+ 'notification_level' => Participant::NOTIFY_MENTION,
+ 'notification_calls' => Participant::NOTIFY_CALLS_ON,
+ 'last_joined_call' => 0,
+ 'last_read_message' => 0,
+ 'last_mention_message' => 0,
+ 'last_mention_direct' => 0,
+ 'read_privacy' => Participant::PRIVACY_PUBLIC,
+ 'permissions' => Attendee::PERMISSIONS_DEFAULT,
+ 'access_token' => '',
+ 'remote_id' => '',
+ ]);
+ $chat = $this->createMock(Room::class);
+ $chat->expects($this->any())
+ ->method('getId')
+ ->willReturn(1234);
+ $chat->expects($this->any())
+ ->method('getToken')
+ ->willReturn('T0k3N');
+ $participant = new Participant($chat, $attendee, null);
+
+ $date = new \DateTime();
+
+ $comment = $this->createMock(IComment::class);
+ $comment->method('getId')
+ ->willReturn('123456');
+ $comment->method('getVerb')
+ ->willReturn('object_shared');
+ $comment->expects($this->once())
+ ->method('getMessage')
+ ->willReturn(json_encode(['message' => 'file_shared', 'parameters' => ['share' => '42']]));
+ $comment->expects($this->once())
+ ->method('setMessage');
+ $comment->expects($this->once())
+ ->method('setVerb')
+ ->with('comment_deleted');
+
+ $share = $this->createMock(IShare::class);
+ $share->method('getShareType')
+ ->willReturn(IShare::TYPE_ROOM);
+ $share->method('getSharedWith')
+ ->willReturn('T0k3N');
+ $share->method('getShareOwner')
+ ->willReturn('user');
+
+ $this->shareManager->method('getShareById')
+ ->with('ocRoomShare:42')
+ ->willReturn($share);
+
+ $this->shareManager->expects($this->once())
+ ->method('deleteShare')
+ ->willReturn($share);
+
+ $this->commentsManager->expects($this->once())
+ ->method('save')
+ ->with($comment);
+
+ $systemMessage = $this->createMock(IComment::class);
+
+ $chatManager = $this->getManager(['addSystemMessage']);
+ $chatManager->expects($this->once())
+ ->method('addSystemMessage')
+ ->with($chat, Attendee::ACTOR_USERS, 'user', $this->anything(), $this->anything(), false, null, 123456)
+ ->willReturn($systemMessage);
+
+ $this->assertSame($systemMessage, $chatManager->deleteMessage($chat, $comment, $participant, $date));
+ }
+
+ public function testDeleteMessageFileShareNotFound(): void {
+ $mapper = new AttendeeMapper(\OC::$server->getDatabaseConnection());
+ $attendee = $mapper->createAttendeeFromRow([
+ 'a_id' => 1,
+ 'room_id' => 123,
+ 'actor_type' => Attendee::ACTOR_USERS,
+ 'actor_id' => 'user',
+ 'display_name' => 'user-display',
+ 'pin' => '',
+ 'participant_type' => Participant::USER,
+ 'favorite' => true,
+ 'notification_level' => Participant::NOTIFY_MENTION,
+ 'notification_calls' => Participant::NOTIFY_CALLS_ON,
+ 'last_joined_call' => 0,
+ 'last_read_message' => 0,
+ 'last_mention_message' => 0,
+ 'last_mention_direct' => 0,
+ 'read_privacy' => Participant::PRIVACY_PUBLIC,
+ 'permissions' => Attendee::PERMISSIONS_DEFAULT,
+ 'access_token' => '',
+ 'remote_id' => '',
+ ]);
+ $chat = $this->createMock(Room::class);
+ $chat->expects($this->any())
+ ->method('getId')
+ ->willReturn(1234);
+ $participant = new Participant($chat, $attendee, null);
+
+ $date = new \DateTime();
+
+ $comment = $this->createMock(IComment::class);
+ $comment->method('getId')
+ ->willReturn('123456');
+ $comment->method('getVerb')
+ ->willReturn('object_shared');
+ $comment->expects($this->once())
+ ->method('getMessage')
+ ->willReturn(json_encode(['message' => 'file_shared', 'parameters' => ['share' => '42']]));
+
+ $this->shareManager->method('getShareById')
+ ->with('ocRoomShare:42')
+ ->willThrowException(new ShareNotFound());
+
+ $this->commentsManager->expects($this->never())
+ ->method('save');
+
+ $systemMessage = $this->createMock(IComment::class);
+
+ $chatManager = $this->getManager(['addSystemMessage']);
+ $chatManager->expects($this->never())
+ ->method('addSystemMessage');
+
+ $this->expectException(ShareNotFound::class);
+ $this->assertSame($systemMessage, $chatManager->deleteMessage($chat, $comment, $participant, $date));
+ }
+
public function testClearHistory(): void {
$chat = $this->createMock(Room::class);
$chat->expects($this->any())