From 47cddcdb29ddcea9c9b69bda16af655fc9f4aabb Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi <41103328+SwikritiT@users.noreply.github.com> Date: Thu, 16 Mar 2023 12:00:29 +0545 Subject: [PATCH] [full-ci][tests-only][backport]Add tests to check the end of an expiration date (#5834) * Add tests to check the end of an expiration date fix style fix style enable group share test skip group share test on ocis * add correct skip tag --- .../apiSpacesShares/shareSpaces.feature | 33 +++++++ .../shareSubItemOfSpace.feature | 27 ++++++ .../features/bootstrap/SpacesContext.php | 94 +++++++++++++++---- 3 files changed, 134 insertions(+), 20 deletions(-) diff --git a/tests/acceptance/features/apiSpacesShares/shareSpaces.feature b/tests/acceptance/features/apiSpacesShares/shareSpaces.feature index b63a10748ea..ea19603f120 100644 --- a/tests/acceptance/features/apiSpacesShares/shareSpaces.feature +++ b/tests/acceptance/features/apiSpacesShares/shareSpaces.feature @@ -428,3 +428,36 @@ Feature: Share spaces | manager | | editor | | viewer | + + @skipOnStable2.0 + Scenario Outline: check the end of expiration of a space in user share + Given user "Alice" has shared a space "share space" with settings: + | shareWith | Brian | + | role | | + | expireDate | 2042-03-25T23:59:59+0100 | + When user "Alice" expires the user share of space "share space" for user "Brian" + Then the HTTP status code should be "200" + And the user "Brian" should not have a space called "share space" + Examples: + | role | + | manager | + | editor | + | viewer | + + @skipOnStable2.0 + Scenario Outline: check the end of expiration of a space in group share + Given group "sales" has been created + And the administrator has added a user "Brian" to the group "sales" using GraphApi + And user "Alice" has shared a space "share space" with settings: + | shareWith | sales | + | shareType | 8 | + | role | | + | expireDate | 2042-03-25T23:59:59+0100 | + When user "Alice" expires the group share of space "share space" for group "sales" + Then the HTTP status code should be "200" + And the user "Brian" should not have a space called "share space" + Examples: + | role | + | manager | + | editor | + | viewer | diff --git a/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpace.feature b/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpace.feature index 5150a17cf13..038b53e5cbf 100644 --- a/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpace.feature +++ b/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpace.feature @@ -146,3 +146,30 @@ Feature: Share a file or folder that is inside a space Then the HTTP status code should be "200" And the information about the last share for user "Brian" should include | expiration | | + + @skipOnStable2.0 + Scenario: check the end of expiration date in user share + Given user "Alice" has created a share inside of space "share sub-item" with settings: + | path | folder | + | shareWith | Brian | + | role | viewer | + | expireDate | 2042-01-01T23:59:59+0100 | + And user "Brian" has accepted share "/folder" offered by user "Alice" + When user "Alice" expires the last share + Then the HTTP status code should be "200" + Then as "Brian" folder "Shares/folder" should not exist + + @issue-5823 @skipOnStable2.0 + Scenario: check the end of expiration date in group share + Given group "sales" has been created + And the administrator has added a user "Brian" to the group "sales" using GraphApi + And user "Alice" has created a share inside of space "share sub-item" with settings: + | path | folder | + | shareWith | sales | + | shareType | 1 | + | role | viewer | + | expireDate | 2042-01-01T23:59:59+0100 | + And user "Brian" has accepted share "/folder" offered by user "Alice" + When user "Alice" expires the last share + Then the HTTP status code should be "200" + Then as "Brian" folder "Shares/folder" should not exist diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 462968a7e44..07dc5a6161e 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -1998,9 +1998,22 @@ public function sendShareSpaceRequest( string $spaceName, TableNode $table ): void { + $rows = $table->getRowsHash(); + $this->featureContext->setResponse($this->shareSpace($user, $spaceName, $rows)); + } + + /** + * @param string $user + * @param string $spaceName + * @param array $rows + * + * @return ResponseInterface + * + * @throws GuzzleException + */ + public function shareSpace(string $user, string $spaceName, array $rows): ResponseInterface { $space = $this->getSpaceByName($user, $spaceName); $availableRoleToAssignToShareSpace = ['manager', 'editor', 'viewer']; - $rows = $table->getRowsHash(); if (isset($rows['role']) && !\in_array(\strtolower($rows['role']), $availableRoleToAssignToShareSpace)) { throw new Error("The Selected " . $rows['role'] . " Cannot be Found"); } @@ -2017,16 +2030,34 @@ public function sendShareSpaceRequest( ]; $fullUrl = $this->baseUrl . $this->ocsApiUrl; - $this->featureContext->setResponse( - $this->sendPostRequestToUrl( - $fullUrl, - $user, - $this->featureContext->getPasswordForUser($user), - $body - ) + + return $this->sendPostRequestToUrl( + $fullUrl, + $user, + $this->featureContext->getPasswordForUser($user), + $body ); } + /** + * @When /^user "([^"]*)" expires the (user|group) share of space "([^"]*)" for (?:user|group) "([^"]*)"$/ + * + * @param string $user + * @param string $shareType + * @param string $spaceName + * @param string $memberUser + * + * @return void + * @throws GuzzleException + */ + public function userExpiresTheShareOfSpaceForUser(string $user, string $shareType, string $spaceName, string $memberUser) { + $dateTime = new DateTime('yesterday'); + $rows['expireDate'] = $dateTime->format('Y-m-d\\TH:i:sP'); + $rows['shareWith'] = $memberUser; + $rows['shareType'] = ($shareType === 'user') ? 7 : 8; + $this->featureContext->setResponse($this->shareSpace($user, $spaceName, $rows)); + } + /** * @When /^user "([^"]*)" creates a share inside of space "([^"]*)" with settings:$/ * @@ -2100,26 +2131,49 @@ public function hasSharedTheFollowingEntityInsideOfSpace( * @return void * @throws GuzzleException */ - public function changeShareResource( + public function changeShareResourceWithSettings( string $user, TableNode $table ): void { - $shareId = $this->featureContext->getLastPublicLinkShareId(); $rows = $table->getRowsHash(); + $this->featureContext->setResponse($this->updateSharedResource($user, $rows)); + } + + /** + * @param string $user + * @param array $rows + * + * @return ResponseInterface + * + * @throws GuzzleException + * @throws JsonException + */ + public function updateSharedResource(string $user, array $rows):ResponseInterface { + $shareId = $this->featureContext->getLastPublicLinkShareId(); $fullUrl = $this->baseUrl . $this->ocsApiUrl . '/' . $shareId; - $this->featureContext->setResponse( - HttpRequestHelper::sendRequest( - $fullUrl, - "", - "PUT", - $this->featureContext->getActualUsername($user), - $this->featureContext->getPasswordForUser($user), - null, - $rows - ) + return HttpRequestHelper::sendRequest( + $fullUrl, + "", + "PUT", + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user), + null, + $rows ); } + /** + * @When /^user "([^"]*)" expires the last share$/ + * + * @param string $user + * + * @return void + */ + public function userExpiresLastResourceShare(string $user): void { + $dateTime = new DateTime('yesterday'); + $rows['expireDate'] = $dateTime->format('Y-m-d\\TH:i:sP'); + $this->featureContext->setResponse($this->updateSharedResource($user, $rows)); + } /** * @When /^user "([^"]*)" creates a public link share inside of space "([^"]*)" with settings:$/ *