From f08a9ae0d915fd42f496b254c0ca48685174db50 Mon Sep 17 00:00:00 2001 From: Prarup Gurung Date: Wed, 17 Jan 2024 15:59:55 +0545 Subject: [PATCH] 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); + } }