diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2020-06-25 16:54:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-25 16:54:41 +0300 |
commit | 3db091877df64e8fdb7667ebe1269ae6587f056a (patch) | |
tree | a6a2263e2e0e1057f011c199fbb024bed49f3ada /tests | |
parent | fa2c4d99fbf93cb9519e246586b662d50a4566c2 (diff) | |
parent | 4cee716e878038b1f341facc3f68176cf71c9a76 (diff) |
Merge pull request #3845 from nextcloud/bugfix/noid/enable-fixed-postgres-tests-again
Enable fixed postgres tests again
Diffstat (limited to 'tests')
-rw-r--r-- | tests/php/Signaling/BackendNotifierTest.php | 166 |
1 files changed, 62 insertions, 104 deletions
diff --git a/tests/php/Signaling/BackendNotifierTest.php b/tests/php/Signaling/BackendNotifierTest.php index a78bf2c40..38ef8286a 100644 --- a/tests/php/Signaling/BackendNotifierTest.php +++ b/tests/php/Signaling/BackendNotifierTest.php @@ -177,18 +177,41 @@ class BackendNotifierTest extends \Test\TestCase { return $body; } + private function assertMessageWasSent(Room $room, array $message): void { + $requests = $this->controller->getRequests(); + $bodies = array_map(function ($request) use ($room) { + return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); + }, $requests); + + $bodies = array_filter($bodies, function (array $body) use ($message) { + return $body['type'] === $message['type']; + }); + + $bodies = array_map([$this, 'sortParticipantUsers'], $bodies); + $message = $this->sortParticipantUsers($message); + $this->assertContains($message, $bodies); + } + + private function sortParticipantUsers(array $message): array { + if ($message['type'] === 'participants') { + usort($message['participants']['users'], static function ($a, $b) { + return + [$a['userId'] ?? '', $a['participantType'], $a['sessionId'], $a['lastPing']] + <=> + [$b['userId'] ?? '', $b['participantType'], $b['sessionId'], $b['lastPing']] + ; + }); + } + return $message; + } + public function testRoomInvite() { $room = $this->manager->createPublicRoom(); $room->addUsers([ 'userId' => $this->userId, ]); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'invite', 'invite' => [ 'userids' => [ @@ -206,7 +229,7 @@ class BackendNotifierTest extends \Test\TestCase { 'active-since' => null, ], ], - ], $bodies); + ]); } public function testRoomDisinvite() { @@ -222,11 +245,7 @@ class BackendNotifierTest extends \Test\TestCase { ->willReturn($this->userId); $room->removeUser($testUser, Room::PARTICIPANT_REMOVED); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'disinvite', 'disinvite' => [ 'userids' => [ @@ -243,18 +262,14 @@ class BackendNotifierTest extends \Test\TestCase { 'active-since' => null, ], ], - ], $bodies); + ]); } public function testRoomNameChanged() { $room = $this->manager->createPublicRoom(); $room->setName('Test room'); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'update', 'update' => [ 'userids' => [ @@ -268,18 +283,14 @@ class BackendNotifierTest extends \Test\TestCase { 'active-since' => null, ], ], - ], $bodies); + ]); } public function testRoomPasswordChanged() { $room = $this->manager->createPublicRoom(); $room->setPassword('password'); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'update', 'update' => [ 'userids' => [ @@ -293,18 +304,14 @@ class BackendNotifierTest extends \Test\TestCase { 'active-since' => null, ], ], - ], $bodies); + ]); } public function testRoomTypeChanged() { $room = $this->manager->createPublicRoom(); $room->setType(Room::GROUP_CALL); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'update', 'update' => [ 'userids' => [ @@ -318,18 +325,14 @@ class BackendNotifierTest extends \Test\TestCase { 'active-since' => null, ], ], - ], $bodies); + ]); } public function testRoomReadOnlyChanged() { $room = $this->manager->createPublicRoom(); $room->setReadOnly(Room::READ_ONLY); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'update', 'update' => [ 'userids' => [ @@ -343,18 +346,14 @@ class BackendNotifierTest extends \Test\TestCase { 'active-since' => null, ], ], - ], $bodies); + ]); } public function testRoomLobbyStateChanged() { $room = $this->manager->createPublicRoom(); $room->setLobby(Webinary::LOBBY_NON_MODERATORS, null); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'update', 'update' => [ 'userids' => [ @@ -368,7 +367,7 @@ class BackendNotifierTest extends \Test\TestCase { 'active-since' => null, ], ], - ], $bodies); + ]); } public function testRoomDelete() { @@ -378,18 +377,14 @@ class BackendNotifierTest extends \Test\TestCase { ]); $room->deleteRoom(); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'delete', 'delete' => [ 'userids' => [ $this->userId, ], ], - ], $bodies); + ]); } public function testRoomInCallChanged() { @@ -402,11 +397,7 @@ class BackendNotifierTest extends \Test\TestCase { $participant = $room->getParticipantBySession($userSession); $room->changeInCall($participant, Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'incall', 'incall' => [ 'incall' => 7, @@ -429,18 +420,14 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); $this->controller->clearRequests(); $guestSession = $room->joinRoomGuest(''); $guestParticipant = $room->getParticipantBySession($guestSession); $room->changeInCall($guestParticipant, Participant::FLAG_IN_CALL); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'incall', 'incall' => [ 'incall' => 1, @@ -468,16 +455,12 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); $this->controller->clearRequests(); $room->changeInCall($participant, Participant::FLAG_DISCONNECTED); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'incall', 'incall' => [ 'incall' => 0, @@ -499,7 +482,7 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); } public function testRoomPropertiesEvent(): void { @@ -515,12 +498,7 @@ class BackendNotifierTest extends \Test\TestCase { $this->controller->clearRequests(); $room->setName('Test room'); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'update', 'update' => [ 'userids' => [ @@ -536,7 +514,7 @@ class BackendNotifierTest extends \Test\TestCase { 'room' => $room->getToken(), ], ], - ], $bodies); + ]); } public function testParticipantsTypeChanged() { @@ -549,11 +527,7 @@ class BackendNotifierTest extends \Test\TestCase { $participant = $room->getParticipantBySession($userSession); $room->setParticipantType($participant, Participant::MODERATOR); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'participants', 'participants' => [ 'changed' => [ @@ -576,18 +550,14 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); $this->controller->clearRequests(); $guestSession = $room->joinRoomGuest(''); $guestParticipant = $room->getParticipantBySession($guestSession); $room->setParticipantType($guestParticipant, Participant::GUEST_MODERATOR); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'participants', 'participants' => [ 'changed' => [ @@ -615,7 +585,7 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); $this->controller->clearRequests(); $notJoinedUserId = 'not-joined-user-id'; @@ -625,11 +595,7 @@ class BackendNotifierTest extends \Test\TestCase { $notJoinedParticipant = $room->getParticipant($notJoinedUserId); $room->setParticipantType($notJoinedParticipant, Participant::MODERATOR); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'participants', 'participants' => [ 'changed' => [ @@ -657,16 +623,12 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); $this->controller->clearRequests(); $room->setParticipantType($participant, Participant::USER); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'participants', 'participants' => [ 'changed' => [ @@ -702,16 +664,12 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); $this->controller->clearRequests(); $room->setParticipantType($guestParticipant, Participant::GUEST); - $requests = $this->controller->getRequests(); - $bodies = array_map(function ($request) use ($room) { - return json_decode($this->validateBackendRequest($this->baseUrl . '/api/v1/room/' . $room->getToken(), $request), true); - }, $requests); - $this->assertContains([ + $this->assertMessageWasSent($room, [ 'type' => 'participants', 'participants' => [ 'changed' => [ @@ -746,6 +704,6 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); } } |