From 25fa79d54a5c0d97847b630bb6fff9246f980d56 Mon Sep 17 00:00:00 2001 From: Sabin Panta <64484313+S-Panta@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:03:09 +0545 Subject: [PATCH] [tests-only][full-ci]added test for declining a share (#8636) * added test for declining a share * updated step definition for disabling user * addressing review --- tests/TestHelpers/GraphHelper.php | 29 ++++++++++ .../apiSharingNg/mountOrUnmountShare.feature | 56 +++++++++++++++++++ .../features/bootstrap/FeatureContext.php | 1 + .../features/bootstrap/GraphContext.php | 1 + .../features/bootstrap/SharingNgContext.php | 35 ++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 tests/acceptance/features/apiSharingNg/mountOrUnmountShare.feature diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index b4f5863b49..53e0a272e9 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -1893,4 +1893,33 @@ class GraphHelper { self::getRequestHeaders() ); } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * @param string $itemId + * @param string $shareSpaceId + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function unmountShare( + string $baseUrl, + string $xRequestId, + string $user, + string $password, + string $itemId, + string $shareSpaceId + ):ResponseInterface { + $url = self::getBetaFullUrl($baseUrl, "drives/$shareSpaceId/items/$itemId"); + return HttpRequestHelper::delete( + $url, + $xRequestId, + $user, + $password, + self::getRequestHeaders() + ); + } } diff --git a/tests/acceptance/features/apiSharingNg/mountOrUnmountShare.feature b/tests/acceptance/features/apiSharingNg/mountOrUnmountShare.feature new file mode 100644 index 0000000000..106eb027a5 --- /dev/null +++ b/tests/acceptance/features/apiSharingNg/mountOrUnmountShare.feature @@ -0,0 +1,56 @@ +Feature: mount or unmount incoming share + As a user + I want to have control over the share received + So that I can filter out the files and folder shared with Me + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And using spaces DAV path + + + Scenario Outline: unmount shared resource + And user "Alice" has created folder "FolderToShare" + And user "Alice" has uploaded file with content "hello world" to "/textfile0.txt" + And user "Alice" has sent the following share invitation: + | resource | | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | Viewer | + When user "Brian" unmounts share "" using the Graph API + And user "Brian" lists the shares shared with him using the Graph API + Then the HTTP status code of responses on all endpoints should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "@client.synchronize" + ], + "properties": { + "@client.synchronize": { + "const": false + } + } + } + } + } + } + """ + Examples: + | resource | + | textfile0.txt | + | FolderToShare | diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 57dfaa7c01..118facc9bd 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -184,6 +184,7 @@ class FeatureContext extends BehatVariablesContext { */ private bool $dbConversion = false; + public const SHARES_SPACE_ID = 'a0ca6a90-a365-4782-871e-d44447bbc668$a0ca6a90-a365-4782-871e-d44447bbc668'; /** * @param bool $value * diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 3af8906b25..d6acda481c 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -2536,6 +2536,7 @@ class GraphContext implements Context { $credentials['password'] ) ); + $this->featureContext->pushToLastStatusCodesArrays(); } /** diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index c244ebeccc..da488d132e 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -559,4 +559,39 @@ class SharingNgContext implements Context { Assert::assertSame($should, $fileFound, $assertMessage); } + + /** + * + * @param string $user + * @param string $itemId + * @param string $shareSpaceId + * + * @return ResponseInterface + */ + public function unmountShare(string $user, string $itemId, string $shareSpaceId): ResponseInterface { + return GraphHelper::unmountShare( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user), + $itemId, + $shareSpaceId, + ); + } + + /** + * @When user :user unmounts share :share using the Graph API + * + * @param string $user + * + * @return void + * @throws Exception + */ + public function userUnmountsShareUsingTheGraphApi(string $user):void { + $shareItemId = $this->featureContext->shareNgGetLastCreatedUserGroupShareID(); + $shareSpaceId = FeatureContext::SHARES_SPACE_ID; + $itemId = $shareSpaceId . '!' . $shareItemId; + $this->featureContext->setResponse($this->unmountShare($user, $itemId, $shareSpaceId)); + $this->featureContext->pushToLastStatusCodesArrays(); + } }