diff --git a/tests/integration/config/behat.yml b/tests/integration/config/behat.yml index 6ef85a656..877ead239 100644 --- a/tests/integration/config/behat.yml +++ b/tests/integration/config/behat.yml @@ -11,3 +11,4 @@ default: - CommentContext - AttachmentContext - SearchContext + - SessionContext diff --git a/tests/integration/features/bootstrap/BoardContext.php b/tests/integration/features/bootstrap/BoardContext.php index 420a7d410..acb796c2f 100644 --- a/tests/integration/features/bootstrap/BoardContext.php +++ b/tests/integration/features/bootstrap/BoardContext.php @@ -32,6 +32,10 @@ class BoardContext implements Context { return $this->card; } + public function getLastUsedBoard() { + return $this->board; + } + /** * @Given /^creates a board with example content$/ */ @@ -57,7 +61,21 @@ class BoardContext implements Context { * @When /^fetches the board named "([^"]*)"$/ */ public function fetchesTheBoardNamed($boardName) { - $this->requestContext->sendJSONrequest('GET', '/index.php/apps/deck/boards/' . $this->board['id'], []); + $id = null; + if (!$this->board || $boardName != $this->board['title']) { + $this->requestContext->sendJSONrequest('GET', '/index.php/apps/deck/boards', []); + $boards = json_decode((string)$this->getResponse()->getBody(), true); + foreach ($boards as $board) { + if ($board['title'] == $boardName) { + $id = $board['id']; + break; + } + } + Assert::assertNotNull($id, "Could not find board named ".$boardName); + } else { + $id = $this->board['id']; + } + $this->requestContext->sendJSONrequest('GET', '/index.php/apps/deck/boards/' . $id, []); $this->getResponse()->getBody()->seek(0); $this->board = json_decode((string)$this->getResponse()->getBody(), true); } diff --git a/tests/integration/features/bootstrap/ServerContext.php b/tests/integration/features/bootstrap/ServerContext.php index 87b068ec8..6880f764c 100644 --- a/tests/integration/features/bootstrap/ServerContext.php +++ b/tests/integration/features/bootstrap/ServerContext.php @@ -47,4 +47,8 @@ class ServerContext implements Context { public function getReqestToken(): string { return $this->requestToken; } + + public function getCurrentUser(): string { + return $this->currentUser; + } } diff --git a/tests/integration/features/bootstrap/SessionContext.php b/tests/integration/features/bootstrap/SessionContext.php new file mode 100644 index 000000000..b5c0d494c --- /dev/null +++ b/tests/integration/features/bootstrap/SessionContext.php @@ -0,0 +1,80 @@ +getEnvironment(); + + $this->serverContext = $environment->getContext('ServerContext'); + $this->boardContext = $environment->getContext('BoardContext'); + } + + /** + * @Given user opens the board named :name + */ + public function opensTheBoardNamed($name) { + $this->boardContext->fetchesTheBoardNamed($name); + + $board = $this->boardContext->getLastUsedBoard(); + $this->requestContext->sendJSONrequest('PUT', '/index.php/apps/deck/session/create', [ + 'boardId' => $board['id'], + ]); + $res = json_decode((string)$this->getResponse()->getBody(), true); + Assert::assertArrayHasKey('token', $res, "session creation did not respond with a token"); + + // store token + $user = $this->serverContext->getCurrentUser(); + $this->token[$user] = $res['token']; + } + + /** + * @Then the response should have a list of active sessions with the length :length + */ + public function theResponseShouldHaveActiveSessions($length) { + $board = $this->boardContext->getLastUsedBoard(); + Assert::assertEquals($length, count($board['activeSessions']), "unexpected count of active sessions"); + } + + /** + * @Then the user :user should be in the list of active sessions + */ + public function theUserShouldBeInTheListOfActiveSessions($user) { + $board = $this->boardContext->getLastUsedBoard(); + Assert::assertContains($user, $board['activeSessions'], "user is not found in the list of active sessions"); + } + + /** + * @When user closes the board named :name + */ + public function closingTheBoardNamed($name) { + $board = $this->boardContext->getLastUsedBoard(); + if (!$board || $board['title'] != $name) { + $this->boardContext->fetchesTheBoardNamed($name); + $board = $this->boardContext->getLastUsedBoard(); + } + + $user = $this->serverContext->getCurrentUser(); + $token = $this->token[$user]; + Assert::assertNotEmpty($token, "no token for the user found"); + $this->requestContext->sendJSONrequest('POST', '/index.php/apps/deck/session/close', [ + 'boardId' => $board['id'], + 'token' => $token + ]); + } +} diff --git a/tests/integration/features/sessions.feature b/tests/integration/features/sessions.feature new file mode 100644 index 000000000..e210f1d2b --- /dev/null +++ b/tests/integration/features/sessions.feature @@ -0,0 +1,33 @@ +Feature: Sessions + + Background: + Given user "admin" exists + And user "user0" exists + And user "user1" exists + Given acting as user "user0" + And creates a board named "Shared board" with color "fafafa" + And shares the board with user "user1" + + + Scenario: Open a board with multiple users + Given acting as user "user0" + And user opens the board named "Shared board" + When fetches the board named "Shared board" + Then the response should have a status code "200" + And the response should have a list of active sessions with the length 1 + And the user "user0" should be in the list of active sessions + + Given acting as user "user1" + And user opens the board named "Shared board" + When fetches the board named "Shared board" + Then the response should have a status code "200" + And the response should have a list of active sessions with the length 2 + And the user "user0" should be in the list of active sessions + And the user "user1" should be in the list of active sessions + + When user closes the board named "Shared board" + And fetches the board named "Shared board" + Then the response should have a status code "200" + And the response should have a list of active sessions with the length 1 + And the user "user0" should be in the list of active sessions +