Skip to content
Next Next commit
Make possible to verify room data also for single rooms
Until now it was possible to verify the room data when getting the full
room list with the "user is participant of the following rooms" step.
Now the same can be optionally done when using "user is participant of
room XXX" too.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Dec 18, 2020
commit 62559fc5bfee24a5774a23469d6881101f9ed512
31 changes: 28 additions & 3 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ public function userIsParticipantOfRooms($user, TableNode $formData = null) {
return;
}

$this->assertRooms($rooms, $formData);
}

/**
* @param array $rooms
* @param TableNode $formData
*/
private function assertRooms($rooms, TableNode $formData) {
Assert::assertCount(count($formData->getHash()), $rooms, 'Room count does not match');
Assert::assertEquals($formData->getHash(), array_map(function ($room, $expectedRoom) {
$participantNames = array_map(function ($participant) {
Expand Down Expand Up @@ -204,10 +212,11 @@ public function userIsParticipantOfRooms($user, TableNode $formData = null) {
* @param string $user
* @param string $isOrNotParticipant
* @param string $identifier
* @param TableNode|null $formData
*/
public function userIsParticipantOfRoom($user, $isOrNotParticipant, $identifier) {
public function userIsParticipantOfRoom($user, $isOrNotParticipant, $identifier, TableNode $formData = null) {
if (strpos($user, 'guest') === 0) {
$this->guestIsParticipantOfRoom($user, $isOrNotParticipant, $identifier);
$this->guestIsParticipantOfRoom($user, $isOrNotParticipant, $identifier, $formData);

return;
}
Expand All @@ -231,6 +240,15 @@ public function userIsParticipantOfRoom($user, $isOrNotParticipant, $identifier)
foreach ($rooms as $room) {
if (self::$tokenToIdentifier[$room['token']] === $identifier) {
Assert::assertEquals($isParticipant, true, 'Room ' . $identifier . ' found in user´s room list');

if ($formData) {
$this->sendRequest('GET', '/apps/spreed/api/v1/room/' . self::$identifierToToken[$identifier]);

$rooms = [$this->getDataFromResponse($this->response)];

$this->assertRooms($rooms, $formData);
}

return;
}
}
Expand All @@ -242,15 +260,22 @@ public function userIsParticipantOfRoom($user, $isOrNotParticipant, $identifier)
* @param string $guest
* @param string $isOrNotParticipant
* @param string $identifier
* @param TableNode|null $formData
*/
private function guestIsParticipantOfRoom($guest, $isOrNotParticipant, $identifier) {
private function guestIsParticipantOfRoom($guest, $isOrNotParticipant, $identifier, TableNode $formData = null) {
$this->setCurrentUser($guest);
$this->sendRequest('GET', '/apps/spreed/api/v1/room/' . self::$identifierToToken[$identifier]);

$response = $this->getDataFromResponse($this->response);

$isParticipant = $isOrNotParticipant === 'is';

if ($formData) {
$rooms = [$response];

$this->assertRooms($rooms, $formData);
}

if ($isParticipant) {
$this->assertStatusCode($this->response, 200);
Assert::assertEquals(self::$userToSessionId[$guest], $response['sessionId']);
Expand Down