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..cab96f4632 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 """ { @@ -115,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 """ { diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index 73dd1e531d..7f18bd793c 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_diff(array_map(fn ($row) => trim($row[0], '/'), $rows), 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); + } }