Add integration tests for CallController

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-07-17 12:58:42 +02:00
Родитель 1bfe3c847d
Коммит b4355a7ab5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E166FD8976B3BAC8
2 изменённых файлов: 161 добавлений и 57 удалений

Просмотреть файл

@ -65,7 +65,7 @@ class FeatureContext implements Context, SnippetAcceptingContext {
* @param string $user
* @param \Behat\Gherkin\Node\TableNode|null $formData
*/
public function userHasRooms($user, \Behat\Gherkin\Node\TableNode $formData = null) {
public function userIsParticipantOfRooms($user, \Behat\Gherkin\Node\TableNode $formData = null) {
$this->setCurrentUser($user);
$this->sendingTo('GET', '/apps/spreed/api/v1/room');
$this->assertStatusCode($this->response, 200);
@ -90,6 +90,36 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}, $rooms));
}
/**
* @Then /^user "([^"]*)" (is|is not) participant of room "([^"]*)"$/
*
* @param string $user
* @param string $isParticipant
* @param string $identifier
*/
public function userIsParticipantOfRoom($user, $isParticipant, $identifier) {
$this->setCurrentUser($user);
$this->sendingTo('GET', '/apps/spreed/api/v1/room');
$this->assertStatusCode($this->response, 200);
$isParticipant = $isParticipant === 'is';
$rooms = $this->getDataFromResponse($this->response);
if ($isParticipant) {
PHPUnit_Framework_Assert::assertNotEmpty($rooms);
}
foreach ($rooms as $room) {
if (self::$tokenToIdentifier[$room['token']] === $identifier) {
PHPUnit_Framework_Assert::assertEquals($isParticipant, true, 'Room ' . $identifier . ' found in user´s room list');
return;
}
}
PHPUnit_Framework_Assert::assertEquals($isParticipant, false, 'Room ' . $identifier . ' not found in user´s room list');
}
/**
* @Then /^user "([^"]*)" creates room "([^"]*)"$/
*
@ -108,54 +138,102 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
* @Then /^user "([^"]*)" leaves room "([^"]*)"$/
* @Then /^user "([^"]*)" leaves room "([^"]*)" with (\d+)$/
*
* @param string $user
* @param string $identifier
*/
public function userLeavesRoom($user, $identifier) {
public function userLeavesRoom($user, $identifier, $statusCode) {
$this->setCurrentUser($user);
$this->sendingToWith('DELETE', '/apps/spreed/api/v1/room/' . self::$identifierToToken[$identifier] . '/participants/self');
$this->assertStatusCode($this->response, 200);
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Then /^user "([^"]*)" removes "([^"]*)" from room "([^"]*)"$/
* @Then /^user "([^"]*)" removes "([^"]*)" from room "([^"]*)" with (\d+)$/
*
* @param string $user
* @param string $identifier
*/
public function userRemovesUserfromRoom($user, $toRemove, $identifier) {
public function userRemovesUserFromRoom($user, $toRemove, $identifier, $statusCode) {
$this->setCurrentUser($user);
$this->sendingToWith(
'DELETE', '/apps/spreed/api/v1/room/' . self::$identifierToToken[$identifier] . '/participants',
new \Behat\Gherkin\Node\TableNode([['participant' => $toRemove]])
);
$this->assertStatusCode($this->response, 200);
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Then /^user "([^"]*)" deletes room "([^"]*)"$/
* @Then /^user "([^"]*)" deletes room "([^"]*)" with (\d+)$/
*
* @param string $user
* @param string $identifier
*/
public function userDeletesRoom($user, $identifier) {
public function userDeletesRoom($user, $identifier, $statusCode) {
$this->setCurrentUser($user);
$this->sendingToWith('DELETE', '/apps/spreed/api/v1/room/' . self::$identifierToToken[$identifier]);
$this->assertStatusCode($this->response, 200);
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Then /^user "([^"]*)" pings room "([^"]*)" (unsuccessfully|successfully)$/
* @Then /^user "([^"]*)" pings call "([^"]*)" with (\d+)$/
*
* @param string $user
* @param string $identifier
* @param string $statusCode
*/
public function userPingsRoom($user, $identifier) {
public function userPingsCall($user, $identifier, $statusCode) {
$this->setCurrentUser($user);
$this->sendingToWith('DELETE', '/apps/spreed/api/v1/room/' . self::$identifierToToken[$identifier]);
$this->assertStatusCode($this->response, 200);
$this->sendingToWith('POST', '/apps/spreed/api/v1/call/' . self::$identifierToToken[$identifier] . '/ping');
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Then /^user "([^"]*)" joins call "([^"]*)" with (\d+)$/
*
* @param string $user
* @param string $identifier
* @param string $statusCode
*/
public function userJoinsCall($user, $identifier, $statusCode) {
$this->setCurrentUser($user);
$this->sendingToWith('POST', '/apps/spreed/api/v1/call/' . self::$identifierToToken[$identifier]);
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Then /^user "([^"]*)" leaves call "([^"]*)" with (\d+)$/
*
* @param string $user
* @param string $identifier
* @param string $statusCode
*/
public function userLeavesCall($user, $identifier, $statusCode) {
$this->setCurrentUser($user);
$this->sendingToWith('DELETE', '/apps/spreed/api/v1/call/' . self::$identifierToToken[$identifier]);
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Then /^user "([^"]*)" sees (\d+) peers in call "([^"]*)" with (\d+)$/
*
* @param string $user
* @param string $numPeers
* @param string $identifier
* @param string $statusCode
*/
public function userSeesPeersInCall($user, $numPeers, $identifier, $statusCode) {
$this->setCurrentUser($user);
$this->sendingToWith('GET', '/apps/spreed/api/v1/call/' . self::$identifierToToken[$identifier]);
$this->assertStatusCode($this->response, $statusCode);
if ($statusCode === '200') {
$response = $this->getDataFromResponse($this->response);
PHPUnit_Framework_Assert::assertCount((int) $numPeers, $response);
} else {
PHPUnit_Framework_Assert::assertEquals((int) $numPeers, 0);
}
}
/**
@ -177,10 +255,10 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
* @BeforeSuite
* @AfterSuite
* @BeforeScenario
* @AfterScenario
*/
public static function resetSpreedAppData() {
public function resetSpreedAppData() {
$client = new Client();
$options = [
'auth' => ['admin', 'admin'],

Просмотреть файл

@ -9,64 +9,90 @@ Feature: one-to-one
Then user "participant2" is participant of the following rooms
Then user "participant3" is participant of the following rooms
Scenario: User1 invites user2 to a one2one room and leaves it
Scenario: User1 invites user2 to a one2one room and user3 is not part of it
When user "participant1" creates room "room1"
| roomType | 1 |
| invite | participant2 |
And user "participant1" is participant of the following rooms
Then user "participant1" is participant of the following rooms
| id | type | participantType | participants |
| room1 | 1 | 1 | participant1, participant2 |
And user "participant2" is participant of the following rooms
| id | type | participantType | participants |
| room1 | 1 | 1 | participant1, participant2 |
And user "participant3" is participant of the following rooms
And user "participant1" leaves room "room1"
Then user "participant1" is participant of the following rooms
And user "participant2" is participant of the following rooms
And user "participant1" is participant of room "room1"
And user "participant2" is participant of room "room1"
And user "participant3" is not participant of room "room1"
Scenario: User1 invites user2 to a one2one room and deletes it
Scenario: User1 invites user2 to a one2one room and leaves it
When user "participant1" creates room "room2"
| roomType | 1 |
| invite | participant2 |
And user "participant1" is participant of the following rooms
| id | type | participantType | participants |
| room2 | 1 | 1 | participant1, participant2 |
And user "participant2" is participant of the following rooms
| id | type | participantType | participants |
| room2 | 1 | 1 | participant1, participant2 |
And user "participant3" is participant of the following rooms
And user "participant1" deletes room "room2"
Then user "participant1" is participant of the following rooms
And user "participant2" is participant of the following rooms
And user "participant1" is participant of room "room2"
And user "participant2" is participant of room "room2"
And user "participant1" leaves room "room2" with 200
Then user "participant1" is not participant of room "room2"
And user "participant2" is not participant of room "room2"
Scenario: User1 invites user2 to a one2one room and removes user2
Scenario: User1 invites user2 to a one2one room and deletes it
When user "participant1" creates room "room3"
| roomType | 1 |
| invite | participant2 |
And user "participant1" is participant of the following rooms
| id | type | participantType | participants |
| room3 | 1 | 1 | participant1, participant2 |
And user "participant2" is participant of the following rooms
| id | type | participantType | participants |
| room3 | 1 | 1 | participant1, participant2 |
And user "participant3" is participant of the following rooms
And user "participant1" removes "participant2" from room "room3"
Then user "participant1" is participant of the following rooms
And user "participant2" is participant of the following rooms
Then user "participant1" is participant of room "room3"
And user "participant2" is participant of room "room3"
And user "participant1" deletes room "room3" with 200
Then user "participant1" is not participant of room "room3"
And user "participant2" is not participant of room "room3"
Scenario: User1 invites user2 to a one2one room and they ping it
Scenario: User1 invites user2 to a one2one room and removes user2
When user "participant1" creates room "room4"
| roomType | 1 |
| invite | participant2 |
And user "participant1" is participant of the following rooms
| id | type | participantType | participants |
| room4 | 1 | 1 | participant1, participant2 |
And user "participant2" is participant of the following rooms
| id | type | participantType | participants |
| room4 | 1 | 1 | participant1, participant2 |
And user "participant3" is participant of the following rooms
Then user "participant1" pings room "room4" successfully
And user "participant2" pings room "room4" successfully
And user "participant3" pings room "room4" unsuccessfully
And user "participant1" deletes room "room4"
Then user "participant1" is participant of room "room4"
And user "participant2" is participant of room "room4"
And user "participant1" removes "participant2" from room "room4" with 200
Then user "participant1" is not participant of room "room4"
And user "participant2" is not participant of room "room4"
Scenario: User1 invites user2 to a one2one room and they get-peers/join/ping/leave
When user "participant1" creates room "room5"
| roomType | 1 |
| invite | participant2 |
Then user "participant1" is participant of room "room5"
And user "participant2" is participant of room "room5"
Then user "participant1" sees 0 peers in call "room5" with 200
And user "participant2" sees 0 peers in call "room5" with 200
Then user "participant1" joins call "room5" with 200
Then user "participant1" sees 1 peers in call "room5" with 200
And user "participant2" sees 1 peers in call "room5" with 200
And user "participant2" joins call "room5" with 200
Then user "participant1" sees 2 peers in call "room5" with 200
And user "participant2" sees 2 peers in call "room5" with 200
Then user "participant1" pings call "room5" with 200
And user "participant2" pings call "room5" with 200
Then user "participant1" leaves call "room5" with 200
Then user "participant1" sees 1 peers in call "room5" with 200
And user "participant2" sees 1 peers in call "room5" with 200
Scenario: User1 invites user2 to a one2one room and user3 can not get-peers/join/ping
When user "participant1" creates room "room6"
| roomType | 1 |
| invite | participant2 |
Then user "participant1" is participant of room "room6"
Then user "participant3" is not participant of room "room6"
Then user "participant1" sees 0 peers in call "room6" with 200
And user "participant3" sees 0 peers in call "room6" with 404
Then user "participant1" joins call "room6" with 200
Then user "participant1" sees 1 peers in call "room6" with 200
And user "participant3" sees 0 peers in call "room6" with 404
And user "participant3" joins call "room6" with 404
Then user "participant1" sees 1 peers in call "room6" with 200
And user "participant3" sees 0 peers in call "room6" with 404
Then user "participant1" pings call "room6" with 200
And user "participant3" pings call "room6" with 404
Then user "participant3" leaves call "room6" with 200
Then user "participant1" sees 1 peers in call "room6" with 200
And user "participant3" sees 0 peers in call "room6" with 404
Then user "participant1" leaves call "room6" with 200
Then user "participant1" sees 0 peers in call "room6" with 200
And user "participant3" sees 0 peers in call "room6" with 404