From f5c763cbec31059af703248dc9bd13ecbe781409 Mon Sep 17 00:00:00 2001 From: ScharfViktor Date: Fri, 19 Nov 2021 18:24:43 +0100 Subject: [PATCH] add tests change space --- .../features/apiSpaces/changeSpaces.feature | 36 +++++++ .../features/bootstrap/SpacesContext.php | 100 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 tests/acceptance/features/apiSpaces/changeSpaces.feature diff --git a/tests/acceptance/features/apiSpaces/changeSpaces.feature b/tests/acceptance/features/apiSpaces/changeSpaces.feature new file mode 100644 index 0000000000..97c2e7f59a --- /dev/null +++ b/tests/acceptance/features/apiSpaces/changeSpaces.feature @@ -0,0 +1,36 @@ +@api @skipOnOcV10 +Feature: Change data of space + As a user + I want to be able to change the data of the created space(increase the quota, change name, etc.) + + Note - this feature is run in CI with ACCOUNTS_HASH_DIFFICULTY set to the default for production + See https://github.com/owncloud/ocis/issues/1542 and https://github.com/owncloud/ocis/pull/839 + + Background: + Given user "Alice" has been created with default attributes and without skeleton files + And the administrator gives "Alice" the role "Admin" using the settings api + + Scenario: Alice changes a name of the space via the Graph api, she expects a 204 code and checks that the space name has changed + When user "Alice" creates a space "Project Jupiter" of type "project" with quota "20" using the GraphApi + And user "Alice" lists all available spaces via the GraphApi + And user "Alice" changes the name of the "Project Jupiter" space to "Project Death Star" + Then the HTTP status code should be "204" + When user "Alice" lists all available spaces via the GraphApi + Then the json responded should contain a space "Project Death Star" with these key and value pairs: + | key | value | + | driveType | project | + | name | Project Death Star | + | quota@@@total | 20 | + | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | + + Scenario: Alice increases quota of the space via the Graph api, she expects a 204 code and checks that the quota has changed + When user "Alice" creates a space "Project Earth" of type "project" with quota "20" using the GraphApi + And user "Alice" lists all available spaces via the GraphApi + And user "Alice" changes the quota of the "Project Earth" space to "100" + Then the HTTP status code should be "204" + When user "Alice" lists all available spaces via the GraphApi + Then the json responded should contain a space "Project Earth" with these key and value pairs: + | key | value | + | name | Project Earth | + | quota@@@total | 100 | + \ No newline at end of file diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index aafa3871c0..7868e82c97 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -874,4 +874,104 @@ class SpacesContext implements Context { return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers); } + + /** + * @When /^user "([^"]*)" changes the name of the "([^"]*)" space to "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * @param string $newName + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function updateSpaceName( + string $user, + string $spaceName, + string $newName + ): void { + $space = $this->getSpaceByName($spaceName); + $spaceId = $space["id"]; + + $bodyData = ["Name" => $newName]; + $body = json_encode($bodyData, JSON_THROW_ON_ERROR); + + $this->featureContext->setResponse( + $this->sendUpdateSpaceRequest( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $body, + $spaceId + ) + ); + } + + /** + * @When /^user "([^"]*)" changes the quota of the "([^"]*)" space to "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * @param int $newQuota + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function updateSpaceQuota( + string $user, + string $spaceName, + int $newQuota + ): void { + $space = $this->getSpaceByName($spaceName); + $spaceId = $space["id"]; + + $bodyData = ["quota" => ["total" => $newQuota]]; + $body = json_encode($bodyData, JSON_THROW_ON_ERROR); + + $this->featureContext->setResponse( + $this->sendUpdateSpaceRequest( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $body, + $spaceId + ) + ); + } + + /** + * Send Graph Update Space Request + * + * @param string $baseUrl + * @param string $user + * @param string $password + * @param mixed $body + * @param string $spaceId + * @param string $xRequestId + * @param array $headers + * + * @return ResponseInterface + * + * @throws GuzzleException + */ + public function sendUpdateSpaceRequest( + string $baseUrl, + string $user, + string $password, + $body, + string $spaceId, + string $xRequestId = '', + array $headers = [] + ): ResponseInterface { + $fullUrl = $baseUrl; + if (!str_ends_with($fullUrl, '/')) { + $fullUrl .= '/'; + } + $fullUrl .= "graph/v1.0/Drive($spaceId)"; + $method = 'PATCH'; + + return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers, $body); + } }