From f08a9ae0d915fd42f496b254c0ca48685174db50 Mon Sep 17 00:00:00 2001 From: Prarup Gurung Date: Wed, 17 Jan 2024 15:59:55 +0545 Subject: [PATCH 1/3] Added test for sending share invitation to normal user --- tests/TestHelpers/GraphHelper.php | 25 +++++++++++++++ .../apiSharingNg/shareInvitations.feature | 26 ++++++++++++++++ .../features/bootstrap/SharingNgContext.php | 31 +++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index a60586fdc0..a8cbd2e419 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -1822,4 +1822,29 @@ class GraphHelper { self::getRequestHeaders() ); } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function getSharesSharedWithMe( + string $baseUrl, + string $xRequestId, + string $user, + string $password + ): ResponseInterface { + $url = self::getBetaFullUrl($baseUrl, "me/drive/sharedWithMe"); + return HttpRequestHelper::get( + $url, + $xRequestId, + $user, + $password, + self::getRequestHeaders() + ); + } } diff --git a/tests/acceptance/features/apiSharingNg/shareInvitations.feature b/tests/acceptance/features/apiSharingNg/shareInvitations.feature index 331668114f..c5a7ae1809 100644 --- a/tests/acceptance/features/apiSharingNg/shareInvitations.feature +++ b/tests/acceptance/features/apiSharingNg/shareInvitations.feature @@ -1111,3 +1111,29 @@ Feature: Send a sharing invitations | Co Owner | folder | FolderToShare | | Uploader | folder | FolderToShare | | Manager | folder | FolderToShare | + + + Scenario Outline: send share invitation to normal user + And user "Alice" has created folder "FolderToShare" + And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile.txt" + When user "Alice" sends the following share invitation using the Graph API: + | resourceType | | + | resource | | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | | + Then the HTTP status code should be "200" + And for user "Brian" the space Shares should contain these entries: + | | + Examples: + | permissions-role | resource-type | path | + | Viewer | file | textfile.txt | + | File Editor | file | textfile.txt | + | Co Owner | file | textfile.txt | + | Manager | file | textfile.txt | + | Viewer | folder | FolderToShare | + | Editor | folder | FolderToShare | + | Co Owner | folder | FolderToShare | + | Uploader | folder | FolderToShare | + | Manager | folder | FolderToShare | diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index 73dd1e531d..8ae528bf9d 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -24,6 +24,7 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Psr\Http\Message\ResponseInterface; use TestHelpers\GraphHelper; use Behat\Gherkin\Node\TableNode; +use PHPUnit\Framework\Assert; require_once 'bootstrap.php'; @@ -424,4 +425,34 @@ class SharingNgContext implements Context { $this->removeSharePermission($sharer, 'link', $resourceType, $resource, $space) ); } + + /** + * @Then /^for user "([^"]*)" the space Shares should (not|)\s?contain these (files|entries):$/ + * + * @param string $user + * @param string $shouldOrNot + * @param TableNode $table + * + * @return void + * @throws Exception + */ + public function forUserTheSpaceSharesShouldContainTheseEntries(string $user, string $shouldOrNot, TableNode $table): void { + $should = $shouldOrNot !== 'not'; + $rows = $table->getRows(); + $response = GraphHelper::getSharesSharedWithMe( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user) + ); + $contents = \json_decode($response->getBody()->getContents(), true); + + $fileFound = !empty(array_intersect(array_column($rows, 0), array_column($contents['value'], 'name'))); + + $assertMessage = $should + ? "Response does not contain the entry." + : "Response does contain the entry but should not."; + + Assert::assertSame($should, $fileFound, $assertMessage); + } } From 0312e72bd2c2050f337669e58184215edb62e7c1 Mon Sep 17 00:00:00 2001 From: Prarup Gurung Date: Fri, 19 Jan 2024 10:15:20 +0545 Subject: [PATCH 2/3] Addressed reviews --- .../apiSharingNg/shareInvitations.feature | 28 ++----------------- .../features/bootstrap/SharingNgContext.php | 2 +- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/tests/acceptance/features/apiSharingNg/shareInvitations.feature b/tests/acceptance/features/apiSharingNg/shareInvitations.feature index c5a7ae1809..130f21c175 100644 --- a/tests/acceptance/features/apiSharingNg/shareInvitations.feature +++ b/tests/acceptance/features/apiSharingNg/shareInvitations.feature @@ -23,6 +23,8 @@ Feature: Send a sharing invitations | shareType | user | | permissionsRole | | Then the HTTP status code should be "200" + And for user "Brian" the space Shares should contain these entries: + | | And the JSON data of the response should match """ { @@ -1111,29 +1113,3 @@ Feature: Send a sharing invitations | Co Owner | folder | FolderToShare | | Uploader | folder | FolderToShare | | Manager | folder | FolderToShare | - - - Scenario Outline: send share invitation to normal user - And user "Alice" has created folder "FolderToShare" - And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile.txt" - When user "Alice" sends the following share invitation using the Graph API: - | resourceType | | - | resource | | - | space | Personal | - | sharee | Brian | - | shareType | user | - | permissionsRole | | - Then the HTTP status code should be "200" - And for user "Brian" the space Shares should contain these entries: - | | - Examples: - | permissions-role | resource-type | path | - | Viewer | file | textfile.txt | - | File Editor | file | textfile.txt | - | Co Owner | file | textfile.txt | - | Manager | file | textfile.txt | - | Viewer | folder | FolderToShare | - | Editor | folder | FolderToShare | - | Co Owner | folder | FolderToShare | - | Uploader | folder | FolderToShare | - | Manager | folder | FolderToShare | diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index 8ae528bf9d..7f18bd793c 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -447,7 +447,7 @@ class SharingNgContext implements Context { ); $contents = \json_decode($response->getBody()->getContents(), true); - $fileFound = !empty(array_intersect(array_column($rows, 0), array_column($contents['value'], 'name'))); + $fileFound = empty(array_diff(array_map(fn ($row) => trim($row[0], '/'), $rows), array_column($contents['value'], 'name'))); $assertMessage = $should ? "Response does not contain the entry." From f7599b3fc86102e6a26978f17d262f3f091d7669 Mon Sep 17 00:00:00 2001 From: Prarup Gurung Date: Tue, 23 Jan 2024 11:13:44 +0545 Subject: [PATCH 3/3] Added step to check as sharee for share invitation to group --- .../acceptance/features/apiSharingNg/shareInvitations.feature | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/acceptance/features/apiSharingNg/shareInvitations.feature b/tests/acceptance/features/apiSharingNg/shareInvitations.feature index 130f21c175..cab96f4632 100644 --- a/tests/acceptance/features/apiSharingNg/shareInvitations.feature +++ b/tests/acceptance/features/apiSharingNg/shareInvitations.feature @@ -117,6 +117,10 @@ Feature: Send a sharing invitations | shareType | group | | permissionsRole | | Then the HTTP status code should be "200" + And for user "Brian" the space Shares should contain these entries: + | | + And for user "Carol" the space Shares should contain these entries: + | | And the JSON data of the response should match """ {