diff options
author | Joas Schilling <coding@schilljs.com> | 2021-03-05 11:32:17 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-03-08 13:56:21 +0300 |
commit | 1dd9297864a925f36db88bd3bfd59af41a1e2f3d (patch) | |
tree | dc777ee2e530c038efad019d8271acca37038f76 /tests | |
parent | 5f29407deef7710d997354148a21eea4d496f83b (diff) |
Fix integration tests by saving the attendee id or loading it
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
4 files changed, 72 insertions, 11 deletions
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index f9dea21f4..45001b263 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -46,6 +46,8 @@ class FeatureContext implements Context, SnippetAcceptingContext { /** @var array[] */ protected static $userToSessionId; /** @var array[] */ + protected static $userToAttendeeId; + /** @var array[] */ protected static $messages; /** @var string */ @@ -90,6 +92,18 @@ class FeatureContext implements Context, SnippetAcceptingContext { return self::$identifierToToken[$identifier]; } + public function getAttendeeId(string $type, string $id, string $room, string $user = null) { + if (!isset(self::$userToAttendeeId[$type][$id])) { + if ($user !== null) { + $this->userLoadsAttendeeIdsInRoom($user, $room, 'v4'); + } else { + throw new \Exception('Attendee id unknown, please call userLoadsAttendeeIdsInRoom with a user that has access before'); + } + } + + return self::$userToAttendeeId[$type][$id]; + } + /** * FeatureContext constructor. */ @@ -107,6 +121,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { self::$tokenToIdentifier = []; self::$sessionIdToUser = []; self::$userToSessionId = []; + self::$userToAttendeeId = []; self::$messages = []; $this->createdUsers = []; @@ -378,6 +393,11 @@ class FeatureContext implements Context, SnippetAcceptingContext { $data['attendeePin'] = $attendee['attendeePin'] ? '**PIN**' : ''; } + if (!isset(self::$userToAttendeeId[$attendee['actorType']])) { + self::$userToAttendeeId[$attendee['actorType']] = []; + } + self::$userToAttendeeId[$attendee['actorType']][$attendee['actorId']] = $attendee['attendeeId']; + $result[] = $data; } @@ -400,6 +420,27 @@ class FeatureContext implements Context, SnippetAcceptingContext { } } + /** + * @Then /^user "([^"]*)" loads attendees attendee ids in room "([^"]*)" \((v4)\)$/ + * + * @param string $user + * @param string $identifier + * @param string $apiVersion + */ + public function userLoadsAttendeeIdsInRoom(string $user, string $identifier, string $apiVersion, TableNode $formData = null): void { + $this->setCurrentUser($user); + $this->sendRequest('GET', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier] . '/participants'); + $this->assertStatusCode($this->response, 200); + $attendees = $this->getDataFromResponse($this->response); + + foreach ($attendees as $attendee) { + if (!isset(self::$userToAttendeeId[$attendee['actorType']])) { + self::$userToAttendeeId[$attendee['actorType']] = []; + } + self::$userToAttendeeId[$attendee['actorType']][$attendee['actorId']] = $attendee['attendeeId']; + } + } + protected function sortAttendees(array $a1, array $a2): int { if ($a1['participantType'] !== $a2['participantType']) { return $a1['participantType'] <=> $a2['participantType']; @@ -717,14 +758,20 @@ class FeatureContext implements Context, SnippetAcceptingContext { * @param string $user * @param string $toRemove * @param string $identifier - * @param string $statusCode + * @param int $statusCode * @param string $apiVersion */ public function userRemovesUserFromRoom(string $user, string $toRemove, string $identifier, int $statusCode, string$apiVersion): void { + if ($toRemove === 'stranger') { + $attendeeId = 123456789; + } else { + $attendeeId = $this->getAttendeeId('users', $toRemove, $identifier, $statusCode === 200 ? $user : null); + } + $this->setCurrentUser($user); $this->sendRequest( - 'DELETE', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier] . '/participants', - new TableNode([['participant', $toRemove]]) + 'DELETE', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier] . '/attendees', + new TableNode([['attendeeId', $attendeeId]]) ); $this->assertStatusCode($this->response, $statusCode); } @@ -963,13 +1010,15 @@ class FeatureContext implements Context, SnippetAcceptingContext { * @param string $apiVersion */ public function userPromoteDemoteInRoom(string $user, string $isPromotion, string $participant, string $identifier, int $statusCode, string $apiVersion): void { - $requestParameters = [['participant', $participant]]; - - if (substr($participant, 0, strlen('guest')) === 'guest') { + if (strpos($participant, 'guest') === 0) { $sessionId = self::$userToSessionId[$participant]; - $requestParameters = [['sessionId', $sessionId]]; + $attendeeId = $this->getAttendeeId('guests', sha1($sessionId), $identifier, $statusCode === 200 ? $user : null); + } else { + $attendeeId = $this->getAttendeeId('users', $participant, $identifier, $statusCode === 200 ? $user : null); } + $requestParameters = [['attendeeId', $attendeeId]]; + $this->setCurrentUser($user); $this->sendRequest( $isPromotion === 'promotes' ? 'POST' : 'DELETE', diff --git a/tests/integration/features/conversation/one-to-one.feature b/tests/integration/features/conversation/one-to-one.feature index 21023ae62..d32c55ffc 100644 --- a/tests/integration/features/conversation/one-to-one.feature +++ b/tests/integration/features/conversation/one-to-one.feature @@ -62,6 +62,7 @@ Feature: one-to-one | invite | participant2 | Then user "participant1" is participant of room "room4" (v4) And user "participant2" is participant of room "room4" (v4) + And user "participant1" loads attendees attendee ids in room "room4" (v4) When user "participant1" removes "participant2" from room "room4" with 400 (v4) Then user "participant1" is participant of room "room4" (v4) And user "participant2" is participant of room "room4" (v4) @@ -105,6 +106,7 @@ Feature: one-to-one | invite | participant2 | And user "participant1" is participant of room "room8" (v4) And user "participant2" is participant of room "room8" (v4) + And user "participant1" loads attendees attendee ids in room "room8" (v4) When user "participant1" promotes "participant2" in room "room8" with 400 (v4) Scenario: User1 invites user2 to a one2one room and demote user2 to moderator @@ -113,6 +115,7 @@ Feature: one-to-one | invite | participant2 | And user "participant1" is participant of room "room9" (v4) And user "participant2" is participant of room "room9" (v4) + And user "participant1" loads attendees attendee ids in room "room9" (v4) When user "participant1" demotes "participant2" in room "room9" with 400 (v4) Scenario: User1 invites user2 to a one2one room and promote non-invited user @@ -121,6 +124,7 @@ Feature: one-to-one | invite | participant2 | And user "participant1" is participant of room "room10" (v4) And user "participant3" is not participant of room "room10" (v4) + And user "participant1" loads attendees attendee ids in room "room10" (v4) When user "participant1" promotes "participant3" in room "room10" with 404 (v4) Scenario: User1 invites user2 to a one2one room and demote non-invited user @@ -129,6 +133,7 @@ Feature: one-to-one | invite | participant2 | And user "participant1" is participant of room "room11" (v4) And user "participant3" is not participant of room "room11" (v4) + And user "participant1" loads attendees attendee ids in room "room11" (v4) When user "participant1" demotes "participant3" in room "room11" with 404 (v4) Scenario: User1 invites user2 to a one2one room twice, it's the same room diff --git a/tests/integration/features/conversation/promotion-demotion.feature b/tests/integration/features/conversation/promotion-demotion.feature index 53cd04882..d9623c550 100644 --- a/tests/integration/features/conversation/promotion-demotion.feature +++ b/tests/integration/features/conversation/promotion-demotion.feature @@ -12,6 +12,7 @@ Feature: public And user "participant2" is participant of the following rooms (v4) | id | type | participantType | | room | 3 | 3 | + And user "participant1" loads attendees attendee ids in room "room" (v4) When user "participant1" promotes "participant2" in room "room" with 200 (v4) And user "participant2" is participant of the following rooms (v4) | id | type | participantType | @@ -30,6 +31,7 @@ Feature: public And user "participant3" is participant of the following rooms (v4) | id | type | participantType | | room | 3 | 3 | + And user "participant1" loads attendees attendee ids in room "room" (v4) And user "participant1" promotes "participant2" in room "room" with 200 (v4) When user "participant2" promotes "participant3" in room "room" with 200 (v4) Then user "participant3" is participant of the following rooms (v4) @@ -49,6 +51,7 @@ Feature: public And user "participant3" is participant of the following rooms (v4) | id | type | participantType | | room | 3 | 3 | + And user "participant1" loads attendees attendee ids in room "room" (v4) When user "participant2" promotes "participant3" in room "room" with 403 (v4) Then user "participant3" is participant of the following rooms (v4) | id | type | participantType | @@ -70,6 +73,7 @@ Feature: public And user "participant3" is participant of the following rooms (v4) | id | type | participantType | | room | 3 | 3 | + And user "participant1" loads attendees attendee ids in room "room" (v4) When user "participant2" promotes "participant3" in room "room" with 404 (v4) Then user "participant3" is participant of the following rooms (v4) | id | type | participantType | diff --git a/tests/integration/features/conversation/remove-participant.feature b/tests/integration/features/conversation/remove-participant.feature index 92acd327d..54dc25c24 100644 --- a/tests/integration/features/conversation/remove-participant.feature +++ b/tests/integration/features/conversation/remove-participant.feature @@ -22,6 +22,7 @@ Feature: public And user "participant1" adds user "participant2" to room "room" with 200 (v4) And user "participant1" is participant of room "room" (v4) And user "participant2" is participant of room "room" (v4) + And user "participant1" loads attendees attendee ids in room "room" (v4) When user "participant1" removes "participant1" from room "room" with 400 (v4) Then user "participant1" is participant of room "room" (v4) And user "participant2" is participant of room "room" (v4) @@ -157,6 +158,7 @@ Feature: public And user "participant1" adds user "participant2" to room "room" with 200 (v4) And user "participant1" adds user "participant3" to room "room" with 200 (v4) And user "participant3" is participant of room "room" (v4) + And user "participant1" loads attendees attendee ids in room "room" (v4) When user "participant2" removes "participant3" from room "room" with 403 (v4) Then user "participant3" is participant of room "room" (v4) @@ -166,6 +168,7 @@ Feature: public | roomName | room | And user "participant1" adds user "participant3" to room "room" with 200 (v4) And user "participant3" is participant of room "room" (v4) + And user "participant1" loads attendees attendee ids in room "room" (v4) When user "participant2" removes "participant3" from room "room" with 404 (v4) Then user "participant3" is participant of room "room" (v4) @@ -177,7 +180,7 @@ Feature: public | roomType | 3 | | roomName | room | And user "participant3" is not participant of room "room" (v4) - When user "participant1" removes "participant3" from room "room" with 404 (v4) + When user "participant1" removes "stranger" from room "room" with 404 (v4) Then user "participant3" is not participant of room "room" (v4) Scenario: Moderator removes stranger @@ -187,7 +190,7 @@ Feature: public And user "participant1" adds user "participant2" to room "room" with 200 (v4) When user "participant1" promotes "participant2" in room "room" with 200 (v4) And user "participant3" is not participant of room "room" (v4) - When user "participant2" removes "participant3" from room "room" with 404 (v4) + When user "participant2" removes "stranger" from room "room" with 404 (v4) Then user "participant3" is not participant of room "room" (v4) Scenario: User removes stranger @@ -196,7 +199,7 @@ Feature: public | roomName | room | And user "participant1" adds user "participant2" to room "room" with 200 (v4) And user "participant3" is not participant of room "room" (v4) - When user "participant2" removes "participant3" from room "room" with 403 (v4) + When user "participant2" removes "stranger" from room "room" with 403 (v4) And user "participant3" is not participant of room "room" (v4) Scenario: Stranger removes stranger @@ -204,5 +207,5 @@ Feature: public | roomType | 3 | | roomName | room | And user "participant3" is not participant of room "room" (v4) - When user "participant2" removes "participant3" from room "room" with 404 (v4) + When user "participant2" removes "stranger" from room "room" with 404 (v4) And user "participant3" is not participant of room "room" (v4) |