Skip to content

Commit

Permalink
Fix integration tests by saving the attendee id or loading it
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 5, 2021
1 parent c32af24 commit fd99482
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 11 deletions.
63 changes: 56 additions & 7 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -90,6 +92,18 @@ public static function getTokenForIdentifier(string $identifier) {
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.
*/
Expand All @@ -107,6 +121,7 @@ public function setUp() {
self::$tokenToIdentifier = [];
self::$sessionIdToUser = [];
self::$userToSessionId = [];
self::$userToAttendeeId = [];
self::$messages = [];

$this->createdUsers = [];
Expand Down Expand Up @@ -378,6 +393,11 @@ public function userSeesAttendeesInRoom(string $user, string $identifier, int $s
$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;
}

Expand All @@ -400,6 +420,27 @@ public function userSeesAttendeesInRoom(string $user, string $identifier, int $s
}
}

/**
* @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'];
Expand Down Expand Up @@ -717,14 +758,20 @@ public function userLeavesRoom(string $user, string $identifier, int $statusCode
* @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);
}
Expand Down Expand Up @@ -963,13 +1010,15 @@ public function userAddAttendeeToRoom(string $user, string $newType, string $new
* @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',
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/features/conversation/one-to-one.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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)
Expand All @@ -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 |
Expand All @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -196,13 +199,13 @@ 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
Given user "participant1" creates room "room" (v4)
| 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)

0 comments on commit fd99482

Please sign in to comment.