summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-01-02 16:56:03 +0100
committerJoas Schilling <coding@schilljs.com>2023-01-04 17:35:22 +0100
commit05abd198c00c39fe7b51234f46938bcddfea22b7 (patch)
tree178b38012a84ee11c76e2fc602033e524bab7e58 /tests
parent249a34da965a6169b373f4cc4e212711684065e4 (diff)
Allow to apply a new attendee map later on
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php26
-rw-r--r--tests/integration/features/conversation/breakout-rooms.feature53
-rw-r--r--tests/php/Service/BreakoutRoomServiceTest.php108
3 files changed, 187 insertions, 0 deletions
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index 5b46d8403..56c6e6265 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -2420,6 +2420,32 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
+ * @Then /^user "([^"]*)" moves participants into different breakout rooms for "([^"]*)" with (\d+) \((v1)\)$/
+ *
+ * @param string $user
+ * @param string $identifier
+ * @param int $status
+ * @param string $apiVersion
+ * @param TableNode|null $formData
+ */
+ public function userMovesParticipantsInsideBreakoutRooms(string $user, string $identifier, int $status, string $apiVersion, TableNode $formData = null): void {
+ $data = [];
+ if ($formData instanceof TableNode) {
+ $mapArray = [];
+ foreach ($formData->getRowsHash() as $attendee => $roomNumber) {
+ [$type, $id] = explode('::', $attendee);
+ $attendeeId = $this->getAttendeeId($type, $id, $identifier);
+ $mapArray[$attendeeId] = (int) $roomNumber;
+ }
+ $data['attendeeMap'] = json_encode($mapArray, JSON_THROW_ON_ERROR);
+ }
+
+ $this->setCurrentUser($user);
+ $this->sendRequest('POST', '/apps/spreed/api/' . $apiVersion . '/breakout-rooms/' . self::$identifierToToken[$identifier] . '/attendees', $data);
+ $this->assertStatusCode($this->response, $status);
+ }
+
+ /**
* @Then /^user "([^"]*)" broadcasts message "([^"]*)" to room "([^"]*)" with (\d+)(?: \((v1)\))?$/
*
* @param string $user
diff --git a/tests/integration/features/conversation/breakout-rooms.feature b/tests/integration/features/conversation/breakout-rooms.feature
index bf779ee2d..4fe05a9e1 100644
--- a/tests/integration/features/conversation/breakout-rooms.feature
+++ b/tests/integration/features/conversation/breakout-rooms.feature
@@ -701,3 +701,56 @@ Feature: conversation/breakout-rooms
When user "participant1" adds user "participant2" to room "Room 2" with 400 (v4)
# Can not "add" groups
When user "participant1" adds group "group1" to room "Room 2" with 400 (v4)
+
+ Scenario: Teacher applies a new attendee map
+ Given user "participant1" creates room "class room" (v4)
+ | roomType | 2 |
+ | roomName | class room |
+ And user "participant1" adds user "participant2" to room "class room" with 200 (v4)
+ And user "participant1" adds user "participant3" to room "class room" with 200 (v4)
+ And user "participant1" adds user "participant4" to room "class room" with 200 (v4)
+ And user "participant1" sees the following attendees in room "class room" with 200 (v4)
+ | actorType | actorId | participantType |
+ | users | participant1 | 1 |
+ | users | participant2 | 3 |
+ | users | participant3 | 3 |
+ | users | participant4 | 3 |
+ And user "participant1" promotes "participant2" in room "class room" with 200 (v4)
+ And user "participant1" sees the following attendees in room "class room" with 200 (v4)
+ | actorType | actorId | participantType |
+ | users | participant1 | 1 |
+ | users | participant2 | 2 |
+ | users | participant3 | 3 |
+ | users | participant4 | 3 |
+ When user "participant1" creates 3 manual breakout rooms for "class room" with 200 (v1)
+ | users::participant3 | 0 |
+ | users::participant4 | 1 |
+ Then user "participant3" is participant of the following rooms (v4)
+ | type | name |
+ | 2 | class room |
+ | 2 | Room 1 |
+ Then user "participant4" is participant of the following rooms (v4)
+ | type | name |
+ | 2 | class room |
+ | 2 | Room 2 |
+ When user "participant1" moves participants into different breakout rooms for "class room" with 400 (v1)
+ | users::participant2 | 0 |
+ | users::participant3 | 2 |
+ | users::participant4 | 1 |
+ When user "participant1" moves participants into different breakout rooms for "class room" with 400 (v1)
+ | users::participant3 | -2 |
+ | users::participant4 | 1 |
+ When user "participant1" moves participants into different breakout rooms for "class room" with 400 (v1)
+ | users::participant3 | 3 |
+ | users::participant4 | 1 |
+ When user "participant1" moves participants into different breakout rooms for "class room" with 200 (v1)
+ | users::participant3 | 2 |
+ | users::participant4 | 1 |
+ Then user "participant3" is participant of the following rooms (v4)
+ | type | name |
+ | 2 | class room |
+ | 2 | Room 3 |
+ Then user "participant4" is participant of the following rooms (v4)
+ | type | name |
+ | 2 | class room |
+ | 2 | Room 2 |
diff --git a/tests/php/Service/BreakoutRoomServiceTest.php b/tests/php/Service/BreakoutRoomServiceTest.php
new file mode 100644
index 000000000..4292a0547
--- /dev/null
+++ b/tests/php/Service/BreakoutRoomServiceTest.php
@@ -0,0 +1,108 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023, Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Talk\Tests\php\Service;
+
+use OCA\Talk\Chat\ChatManager;
+use OCA\Talk\Config;
+use OCA\Talk\Manager;
+use OCA\Talk\Service\BreakoutRoomService;
+use OCA\Talk\Service\ParticipantService;
+use OCA\Talk\Service\RoomService;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IL10N;
+use OCP\Notification\IManager as INotificationManager;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class BreakoutRoomServiceTest extends TestCase {
+ private BreakoutRoomService $service;
+
+ /** @var Config|MockObject */
+ private $config;
+ /** @var Manager|MockObject */
+ private $manager;
+ /** @var RoomService|MockObject */
+ private $roomService;
+ /** @var ParticipantService|MockObject */
+ private $participantService;
+ /** @var ChatManager|MockObject */
+ private $chatManager;
+ /** @var IEventDispatcher|MockObject */
+ private $dispatcher;
+ /** @var IL10N|MockObject */
+ private $l;
+
+ public function setUp(): void {
+ parent::setUp();
+
+ $this->config = $this->createMock(Config::class);
+ $this->manager = $this->createMock(Manager::class);
+ $this->roomService = $this->createMock(RoomService::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
+ $this->chatManager = $this->createMock(ChatManager::class);
+ $this->notificationManager = $this->createMock(INotificationManager::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
+ $this->l = $this->createMock(IL10N::class);
+ $this->service = new BreakoutRoomService(
+ $this->config,
+ $this->manager,
+ $this->roomService,
+ $this->participantService,
+ $this->chatManager,
+ $this->notificationManager,
+ $this->dispatcher,
+ $this->l
+ );
+ }
+ public function dataParseAttendeeMap(): array {
+ return [
+ 'Empty string means no map' => ['', 3, [], false],
+ 'Empty array means no map' => ['[]', 3, [], false],
+ 'OK' => [json_encode([1 => 1, 13 => 0, 42 => 2]), 3, [1 => 1, 13 => 0, 42 => 2], false],
+ 'Not an array' => ['"hello"', 3, null, true],
+ 'Room above max' => [json_encode([1 => 0, 13 => 1, 42 => 2]), 2, null, true],
+ 'Room below min' => [json_encode([1 => 0, 13 => -1, 42 => 2]), 3, null, true],
+ 'Room not int' => [json_encode([1 => 0, 13 => 'foo', 42 => 2]), 3, null, true],
+ 'Room null' => [json_encode([1 => 0, 13 => null, 42 => 2]), 3, null, true],
+ 'Attendee not int' => [json_encode([1 => 0, 'foo' => 1, 42 => 2]), 3, null, true],
+ 'Attendee negative' => [json_encode([1 => 0, -13 => 1, 42 => 2]), 3, null, true],
+ 'Attendee zero' => [json_encode([1 => 0, 0 => 1, 42 => 2]), 3, null, true],
+ ];
+ }
+
+ /**
+ * @dataProvider dataParseAttendeeMap
+ */
+ public function testParseAttendeeMap(string $json, int $max, ?array $expected, bool $throws): void {
+ if ($throws) {
+ $this->expectException(\InvalidArgumentException::class);
+ }
+
+ $actual = self::invokePrivate($this->service, 'parseAttendeeMap', [$json, $max]);
+ $this->assertEquals($expected, $actual);
+ }
+}