diff options
author | Joas Schilling <coding@schilljs.com> | 2021-01-28 16:40:02 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-02-02 18:22:17 +0300 |
commit | 2e100b2c180da4c9649de6aad119b7751a93cc2c (patch) | |
tree | d6bd1fa00db801abdb8216aef86359ada7bcc5bb | |
parent | 4d27b096c5e151fbf2c1d244c008e634ca33ada4 (diff) |
Add a unit test
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | tests/php/Controller/ChatControllerTest.php | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/php/Controller/ChatControllerTest.php b/tests/php/Controller/ChatControllerTest.php index 30086496c..eb3f0f029 100644 --- a/tests/php/Controller/ChatControllerTest.php +++ b/tests/php/Controller/ChatControllerTest.php @@ -47,6 +47,7 @@ use OCP\IL10N; use OCP\IRequest; use OCP\IUser; use OCP\IUserManager; +use OCP\RichObjectStrings\IValidator; use OCP\UserStatus\IManager as IUserStatusManager; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\MockObject\MockObject; @@ -86,6 +87,8 @@ class ChatControllerTest extends TestCase { protected $eventDispatcher; /** @var ITimeFactory|MockObject */ protected $timeFactory; + /** @var IValidator|MockObject */ + protected $richObjectValidator; /** @var IL10N|MockObject */ private $l; @@ -117,6 +120,7 @@ class ChatControllerTest extends TestCase { $this->searchResult = $this->createMock(ISearchResult::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->timeFactory = $this->createMock(ITimeFactory::class); + $this->richObjectValidator = $this->createMock(IValidator::class); $this->l = $this->createMock(IL10N::class); $this->room = $this->createMock(Room::class); @@ -151,6 +155,7 @@ class ChatControllerTest extends TestCase { $this->searchResult, $this->timeFactory, $this->eventDispatcher, + $this->richObjectValidator, $this->l ); } @@ -613,6 +618,94 @@ class ChatControllerTest extends TestCase { $this->assertEquals($expected, $response); } + public function testShareObjectToChatByUser() { + $participant = $this->createMock(Participant::class); + + $richData = [ + 'call-type' => 'one2one', + 'type' => 'call', + 'id' => 'R4nd0mToken', + ]; + + $date = new \DateTime(); + $this->timeFactory->expects($this->once()) + ->method('getDateTime') + ->willReturn($date); + /** @var IComment|MockObject $comment */ + $comment = $this->newComment(42, 'user', $this->userId, $date, 'testMessage'); + $this->chatManager->expects($this->once()) + ->method('addSystemMessage') + ->with($this->room, + 'users', + $this->userId, + json_encode([ + 'message' => 'object_shared', + 'parameters' => [ + 'objectType' => 'call', + 'objectId' => 'R4nd0mToken', + 'metaData' => [ + 'call-type' => 'one2one', + 'type' => 'call', + 'id' => 'R4nd0mToken', + ], + ], + ]), + $this->newMessageDateTimeConstraint + ) + ->willReturn($comment); + + $chatMessage = $this->createMock(Message::class); + $chatMessage->expects($this->once()) + ->method('getVisibility') + ->willReturn(true); + $chatMessage->expects($this->once()) + ->method('toArray') + ->willReturn([ + 'id' => 42, + 'token' => 'testToken', + 'actorType' => 'users', + 'actorId' => $this->userId, + 'actorDisplayName' => 'displayName', + 'timestamp' => $date->getTimestamp(), + 'message' => '{object}', + 'messageParameters' => $richData, + 'systemMessage' => '', + 'messageType' => 'comment', + 'isReplyable' => true, + 'referenceId' => '', + ]); + + $this->messageParser->expects($this->once()) + ->method('createMessage') + ->with($this->room, $participant, $comment, $this->l) + ->willReturn($chatMessage); + + $this->messageParser->expects($this->once()) + ->method('parseMessage') + ->with($chatMessage); + + $this->controller->setRoom($this->room); + $this->controller->setParticipant($participant); + $response = $this->controller->shareObjectToChat($richData['type'], $richData['id'], json_encode(['call-type' => $richData['call-type']])); + $expected = new DataResponse([ + 'id' => 42, + 'token' => 'testToken', + 'actorType' => 'users', + 'actorId' => $this->userId, + 'actorDisplayName' => 'displayName', + 'timestamp' => $date->getTimestamp(), + 'message' => '{object}', + 'messageParameters' => $richData, + 'systemMessage' => '', + 'messageType' => 'comment', + 'isReplyable' => true, + 'referenceId' => '', + ], Http::STATUS_CREATED); + + $this->assertEquals($expected->getStatus(), $response->getStatus()); + $this->assertEquals($expected->getData(), $response->getData()); + } + public function testReceiveHistoryByUser() { $offset = 23; $limit = 4; |