diff options
author | Joas Schilling <coding@schilljs.com> | 2020-06-25 14:43:09 +0300 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2020-06-25 17:03:35 +0300 |
commit | d2f2fbb8e903fa07eb447fdc34857707d6e8edbc (patch) | |
tree | be77e21b3982a8a1f0f31ae952550f0a32aae5db /tests | |
parent | e519331919ca71a6316296a9a9c259476f5f937b (diff) |
Sort the users in the participants array before comparing
Signed-off-by: Joas Schilling <coding@schilljs.com>
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 fcd990292..e4dbe10b0 100644 --- a/tests/php/Signaling/BackendNotifierTest.php +++ b/tests/php/Signaling/BackendNotifierTest.php @@ -186,18 +186,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' => [ @@ -215,7 +238,7 @@ class BackendNotifierTest extends \Test\TestCase { 'active-since' => null, ], ], - ], $bodies); + ]); } public function testRoomDisinvite() { @@ -231,11 +254,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' => [ @@ -252,18 +271,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' => [ @@ -277,18 +292,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' => [ @@ -302,18 +313,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' => [ @@ -327,18 +334,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' => [ @@ -352,18 +355,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' => [ @@ -377,7 +376,7 @@ class BackendNotifierTest extends \Test\TestCase { 'active-since' => null, ], ], - ], $bodies); + ]); } public function testRoomDelete() { @@ -387,18 +386,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() { @@ -411,11 +406,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, @@ -438,18 +429,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, @@ -477,16 +464,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, @@ -508,7 +491,7 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); } public function testRoomPropertiesEvent(): void { @@ -524,12 +507,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' => [ @@ -545,7 +523,7 @@ class BackendNotifierTest extends \Test\TestCase { 'room' => $room->getToken(), ], ], - ], $bodies); + ]); } public function testParticipantsTypeChanged() { @@ -558,11 +536,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' => [ @@ -585,18 +559,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' => [ @@ -624,7 +594,7 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); $this->controller->clearRequests(); $notJoinedUserId = 'not-joined-user-id'; @@ -634,11 +604,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' => [ @@ -666,16 +632,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' => [ @@ -711,16 +673,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' => [ @@ -755,6 +713,6 @@ class BackendNotifierTest extends \Test\TestCase { ], ], ], - ], $bodies); + ]); } } |